public static int atk = 5;
public static void main(String[] args){
System.out.println("DUNGEONS AND DWAGONS");
Scanner scan = new Scanner(System.in);
help();
String input = scan.next();
// when someone types help first it works, but when they type stats after it shows what would happen if someone typed help.
while(true){
if (input.equals("help")){
help();
scan.next();
}else if(input.equals("stats")){
stats();
scan.next();
}
}
}
static void help() {
System.out.println("type n,s,e,w to move in a direction");
System.out.println("type stats to see your stats");
System.out.println("type look and then a direction n,e,s,w see the sights");
System.out.println("if you wish to see this again type help");
}
static void stats(){
System.out.println("Health " + health);
System.out.println("Armour " + armour);
System.out.println("Attack " + atk);
}
}
//我已經嘗試每一件事情,如果你鍵入任何內容後的第一個THIG鍵入它會一遍又一遍的執行同樣的事情。當用戶輸入第二個字符串,它執行的第一個類型
'輸入'是否改變過? – 2015-02-24 15:49:15
@SotiriosDelimanolis帶領你朝着正確的方向前進。在第一次之後,您不會將掃描儀讀數分配給「輸入」變量。 – Kon 2015-02-24 15:50:21
我該如何解決,然後 – Jacob 2015-02-25 15:04:21