所以我需要一些代碼來制作它,以便如果輸入四個單詞中的一個,它會跳回到某一行。這是一款基于文本的 rpg 游戲。
if(input3.equalsIgnoreCase("Inside")) {
System.out.println("------------------------------------------");
System.out.println("\n- You go inside the tent right as the sky becomes a dark shade, zipping yourself shut inside. -");
System.out.println("- You scan over the things in the tent. -");
System.out.println("- There is a lantern in the corner, a sleeping bad next to it, and a walkie talkie on the pillow. -\n");
System.out.println("-----------------------------------------------");
System.out.println("\t\nWhat would you like to do?\n");
System.out.println("\tSleep. Get into the sleeping bag and go to sleep.");
System.out.println("\tCall. Use the walkie talkie to try to reach out to someone.");
System.out.println("\tIntrospect. Think about what is going on and how you are here.");
System.out.println("\tOutside. Go outside the tent.\n");
String input4 = in.nextLine();
if(input4.equalsIgnoreCase("Sleep")) {
System.out.println("-----------------------------------------------");
System.out.println("\n- You move the walkie talkie and get into the sleeping bag. You slowly drift off into a deep slumber. -\n");
}
else if(input4.equalsIgnoreCase("Call")) {
System.out.println("-----------------------------------------------");
System.out.println("\n- You grab the walkie talkie and press a couple of buttons, trying to figure out how it works. -");
System.out.println("- After a little bit of fiddling with it, you give up, thinking it's ran out of battery. -");
System.out.println("- You feel your eyes droop and decide to get into the sleeping bad and go to sleep. -\n");
}
else if(input4.equalsIgnoreCase("Introspect")) {
System.out.println("-----------------------------------------------");
System.out.println("\n- You huddle into the corner, thinking. -\n");
System.out.println("- 'How are you here?' Your mind wanders. -");
System.out.println("- 'Why are you here?' You don't know. -");
System.out.println("- 'You don't even know what you look like. -");
System.out.println("- Before long, your eyes slowly close shut, as you head into a deep slumber. -\n");
}
else if(input4.equalsIgnoreCase("Outside")) {
System.out.println("-----------------------------------------------");
System.out.println("\n- You unzip the tent and step outside. -");
System.out.println("- A cold shudder washes over you, making you quickly go back inside, zipping yourself back inside. -\n");
}
我基本上想要它,這樣當用戶鍵入“外部”時,這個功能......
else if(input4.equalsIgnoreCase("Outside")) {
System.out.println("-----------------------------------------------");
System.out.println("\n- You unzip the tent and step outside. -");
System.out.println("- A cold shudder washes over you, making you quickly go back inside, zipping yourself back inside. -\n");
}
...運行并在列印行之后我希望它跳回..
if(input3.equalsIgnoreCase("Inside")) {
System.out.println("------------------------------------------");
System.out.println("\n- You go inside the tent right as the sky becomes a dark shade, zipping yourself shut inside. -");
System.out.println("- You scan over the things in the tent. -");
System.out.println("- There is a lantern in the corner, a sleeping bad next to it, and a walkie talkie on the pillow. -\n");
System.out.println("-----------------------------------------------");
...然后再次運行所有內容。
uj5u.com熱心網友回復:
你可以做的就是把所有東西都放在一個while回圈中。簡化版:
if(input3.equalsIgnoreCase("Inside")) {
while(true) {
System.out.println("Some text");
System.out.println("Some options:");
String input4 = in.nextLine();
if(input4.equalsIgnoreCase("Sleep")) {
System.out.println("Some text");
break;
} else if(input4.equalsIgnoreCase("Outside") {
System.out.println("Some text");
}
}
}
通常我會說這while(true)是不好的做法,但我認為在這種情況下沒關系。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/424441.html
上一篇:用外部資料填充Django模板中的ChoiceField
下一篇:在python腳本中集成一個回圈
