這是我第一次來這裏,我對編程非常陌生,我一直在學習java 2周,現在我只知道一些基本知識,所以我決定測試我的通過做一個簡單的文本冒險遊戲,而不使用對象的知識,因爲我還沒有掌握。我將繼續打印故事並描述情況,並接受玩家選擇繼續。 但我有我的代碼的問題,我不知道如何重複一個問題,如果用戶輸入一個無效的選擇,我嘗試了幾種方法,但程序結束或給我無限循環,我需要一些幫助,請。Java - 創建沒有任何對象的文本冒險,
這裏是我的代碼:
import java.util.Scanner;
class The_Crime {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome Stranger, Please Enter Your Name");
String name = input.nextLine();
System.out.println("Welcome" + name);
Street street = new Street();
System.out.println("You are now in the street with a dead body on the floor drowned in blood \n there is a building right ahead of you\n What would you like to do?");
String choice = input.nextLine();
while(true) {
if(choice.equals("enter building")) {
System.out.println("You have entered the empty building");
} else {
System.out.println("You are now in the street with a dead body lying around drawned in blood \n there is a building right infront of you\n What would you like to do?");
}
}
}
}
你一定要明白'System','Scanner','String','Street'都是對象 – chancea
它是100%不可能不使用對象在java – aaronman
heyy只是使用原始類型!你在自己的gameeeee中作弊! – nachokk