我似乎有自己的扫描仪/ Eclipse自动运行用户输入。我将扫描仪初始化为:
Scanner in = new Scanner(System.in);
菜单为:
@Override
void update() {
//welcome
System.out.println("-----Welcome to the Pet Game-----");
System.out.println();
System.out.println("1. Play");
System.out.println("2. Help");
System.out.println("3. Dev Mode");
int choice = in.nextInt();
switch(choice){
case 1:
playLoop();
break;
case 2:
helpPage();
break;
case 3:
devMode();
break;
}
}
由于某种原因,它会在此菜单上自动输入2。并在此菜单上显示3:
// main menu
System.out.println("This is Day " + (i+1) + " you have " + dayActions + " Actions left.");
System.out.println("1. View Pet Status");
System.out.println("2. Shop");
System.out.println("3. Skip Action");
System.out.println("4. Play");
System.out.println("5. Feed");
System.out.println("6. Bathroom");
System.out.println("7. Sleep");
int choice = in.nextInt();
System.out.println();
我认为这可能是由于我的GameState课程,但我不确定。 Gamestate类:
abstract class GameState {
abstract void update();
protected void pushState(GameState state) {
PetGame.pushState(state);
}
protected void popState() {
PetGame.popState();
}
}
StoreState(这是它跳到的课程。我无法在我的代码中找到它的任何引用,不知道它为什么会在这里。)
public class StoreState{
@Override
void update() {
// TODO Auto-generated method stub
}
}
感谢您的帮助。
答案 0 :(得分:-1)
在满足特定break
之后,您需要利用switch
语句跳出case
语句,否则,您将获得名为{{case 1:
playLoop();
break;
case 2:
helpPage();
break;
case 3:
devMode();
break;
的内容3}}
<div id="topnav">
<div id="sidebar">
<div id="content">