所以我开始研究涉及MasterMind游戏的项目。我现在完全迷失了,不知道接下来要做什么来完成比赛。我不希望在控制台区域中作为applet运行。 BTW这是在eclipse上运行的。我的if语句也有问题。它告诉我操作数是不兼容的。错误代码是:不兼容的操作数类型Scanner和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++;
}
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
为了理解每次回合后输入的效果,请尝试实现循环...
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);
}
}