到目前为止,我正在制作刽子手游戏并且进展顺利。我只想声明并打印一系列Missed Letters。 Missed Letters是用户已经输入的字母。
以下是代码:
public static void chosenWord() throws IOException{
String randomWord="";
Scanner ui = new Scanner (System.in);
Random rand = new Random();
randomWord = word.get(rand.nextInt(word.size()));
String Dashes = new String(new char[randomWord.length()]).replace("\0", "_");
while(Tries < 6 && Dashes.contains("_")) {
System.out.print("Guess a Character :");
System.out.print(randomWord);
System.out.println(Dashes);
String guess = ui.next();
char[] Misses = new char[6];
String chngeDashes = "";
for (int i = 0; i < randomWord.length(); i++) {
if (randomWord.charAt(i) == guess.charAt(0)) {
chngeDashes += guess.charAt(0);
System.out.print("Guesses: "+guess.toUpperCase());
}
else if (Dashes.charAt(i) != '_') {
chngeDashes += randomWord.charAt(i);
} else {
chngeDashes += "_";
}
}
if (Dashes.equals(chngeDashes)) {
Tries++;
Misses[Tries] = guess.charAt(0);
System.out.println("Misses: "+Misses[Tries]); //Want to print missed letters
//gameOver();
} else {
Dashes = chngeDashes;
}
if (Dashes.equals(randomWord)) {
System.out.println("Correct! You win! The word was " + randomWord);
}
}
}
答案 0 :(得分:0)
一个。作为问题的一部分,您应该澄清您的问题,而不是期望人们阅读代码。正确解释您当前的行为,以及您目前正在经历的行为。
B中。我认为你要找的是:&#34; Arrays.toString(Misses)&#34; (至少当你不恰当地命名时)