我对我的节目感到困惑。这场比赛是命运之轮。当我运行程序时,它可以工作,并在猜对时添加字母,如果不正确则不添加字母;虽然我的节目为我的分数显示了两个可能的胜利,但我希望它只显示一个;即使它不正确也会增加分数。任何想法都会有所帮助。谢谢。
这是代码:
import java.util.Scanner;
/**
* This is the main game which will call the coding that will implement the classes word board and wheel in to a fully function game.
* @author 100206667
*
*/
public class WheelOfFortune {
public static int Score;
/**
*
* @param args - This will loop through the code block underneath to allow the game to work. */
public static void main(String[] args) {
Wheel w = new Wheel();
WordBoard b = new WordBoard();
int usrGuess = -1;
String feedback = "";
Scanner sc = new Scanner(System.in);
boolean match;
char guess;
int score;
// Main game loop
do {
if (w.spin().length() > 4) {
// Free spins, bankrups....still need to be added
} else {
Score = Score + Integer.valueOf(w.spin().toString());
}
System.out.println("Your score is " + Score);
//The error is here in my program. (i know that much)
String segment = w.spin();
System.out.println( b.getHiddenPhrase() );
System.out.println("Make a guess:");
String input = sc.nextLine();
guess = input.charAt(0);
match = b.checking(guess);
// missing feedback
System.out.println(feedback);
}while ( !b.finshGame() );
sc.close();
// Display feedback
if (usrGuess != -1){
// is not displaying when game finishes.
System.out.println("Well done. Your final score is");
} else System.out.println("Thanks for playing");
}
}
非常感谢帮助。谢谢。
答案 0 :(得分:1)
我无法真正证明得分的正确性,因为该值来自添加到得分的Wheel对象。
我做了一个模拟你的代码,这里的逻辑很好,减去你从其他对象中提取的任何东西 - do..while将终止并只打印一次。
你有System.out.println("Well done. Your final score is");
但之后没有打印变量,每次循环执行时都会发生score
次打印。
if (usrGuess != -1){
以及之后的参数将永远不会显示,因为您将usrGuess
硬编码为-1并且未在本地任何位置进行修改。
你应该完全删除条件 - 一旦while循环终止它将执行下一行代码。
添加字母的逻辑无法为您调试 - 您应该将此类