Reputation: 87
So I started working on a project involving the game MasterMind. I am now completely lost and have no idea what to do next to complete the game. I do not want in run as an applet, just in the console area. BTW this is run on eclipse. I am also having a problem with my if statement. It tells me that the operands are incompatible. The error code is: Incompatible operand types Scanner and Int[].
package masterMind;
import java.util.Scanner;
public class MasterMind {
public static void main(String[] args) {
System.out.println("This is MasterMind, a logic game");
System.out.println("To win you must guess correctly where each number is(The Numbers Range from 1-4)");
System.out.println("You will be told if you get one correct");
System.out.println("You will only get 10 tries, then you lose");
System.out.println("Lets begin");
//Declare Array
int [] answerArray;
answerArray= new int [4];
//Initialize Array
//Change these value to change the answers needed to win
answerArray[0]=2;
answerArray[1]=3;
answerArray[2]=2;
answerArray[3]=2;
//Create Board
System.out.println("__ __ __ __");
Scanner userGuess = new Scanner(System.in);
int num = userGuess.nextInt();
boolean guessedAll = false;
int guessedCount=0;
int tryCounter=0;
while(tryCounter<9 || !guessedAll){
if (userGuess==answerArray) {
} else {
}
//if number equals one of the numbers above then guessedCount++ ...
//if guessedCount==4 then guessedAll=true
tryCounter++;
}
}
}
Upvotes: 0
Views: 9018
Reputation: 1051
in order to understand how your input looks after every turn, try to implement a loop...
public static void main(String[] args) {
Scanner userGuess = new Scanner(System.in);
boolean gameRunning = true;
while (gameRunning) {
// getting a line from the input
System.out.println("\ninput a line");
String inputLine = userGuess.nextLine();
System.out.println("the line is: " + inputLine);
// getting an integer
System.out.println("\ninput an integer");
int inputInt = userGuess.nextInt(); // this will give you an int from the input
userGuess.nextLine();
System.out.println("the integer is: " + inputInt);
}
}
Upvotes: 0
Reputation: 26
inside your if statement, you would need 4 if statements, each checking that the number at that spot is guessed correctly. If they are, then display that number, else let them guess again (suggesting a while loop to check if they guessed enough times, or they got it all right.
Upvotes: 1