用java写一份有文本存储选择过程的文本类游戏,要求超过5个问题
时间: 2024-03-05 22:48:20 浏览: 46
基于java的填字游戏
非常感谢你的问题,我会尽力回答。
以下是 Java 写的一个有文本存储选择过程的文本类游戏,共有 6 个问题。
```java
import java.util.Scanner;
public class TextAdventureGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Text Adventure Game!");
System.out.println("You find yourself in a dark room. There are two doors in front of you. Which one do you choose? (1/2)");
int doorChoice = scanner.nextInt();
if (doorChoice == 1) {
System.out.println("You enter a room with a chest. Do you open it? (yes/no)");
String chestChoice = scanner.next();
if (chestChoice.equalsIgnoreCase("yes")) {
System.out.println("You find a key inside the chest. You can use it to open one of two doors. Which one do you choose? (1/2)");
int doorChoice2 = scanner.nextInt();
if (doorChoice2 == 1) {
System.out.println("You escape the room and win the game!");
} else if (doorChoice2 == 2) {
System.out.println("You enter a room with a monster. You try to fight it, but you lose. Game over!");
} else {
System.out.println("Invalid input. Game over!");
}
} else if (chestChoice.equalsIgnoreCase("no")) {
System.out.println("You leave the chest and choose one of two doors. Which one do you choose? (1/2)");
int doorChoice2 = scanner.nextInt();
if (doorChoice2 == 1) {
System.out.println("You enter a room with a monster. You try to fight it, but you lose. Game over!");
} else if (doorChoice2 == 2) {
System.out.println("You escape the room and win the game!");
} else {
System.out.println("Invalid input. Game over!");
}
} else {
System.out.println("Invalid input. Game over!");
}
} else if (doorChoice == 2) {
System.out.println("You enter a room with a mirror. Do you look into it? (yes/no)");
String mirrorChoice = scanner.next();
if (mirrorChoice.equalsIgnoreCase("yes")) {
System.out.println("You see a message written on the mirror: 'The key to escaping this room is hidden in the chest'.");
System.out.println("You choose one of two doors. Which one do you choose? (1/2)");
int doorChoice2 = scanner.nextInt();
if (doorChoice2 == 1) {
System.out.println("You enter a room with a monster. You try to fight it, but you lose. Game over!");
} else if (doorChoice2 == 2) {
System.out.println("You find the chest and open it with the key. Inside, you find a map that shows you the way out of the room. You escape and win the game!");
} else {
System.out.println("Invalid input. Game over!");
}
} else if (mirrorChoice.equalsIgnoreCase("no")) {
System.out.println("You choose one of two doors. Which one do you choose? (1/2)");
int doorChoice2 = scanner.nextInt();
if (doorChoice2 == 1) {
System.out.println("You enter a room with a monster. You try to fight it, but you lose. Game over!");
} else if (doorChoice2 == 2) {
System.out.println("You find the chest and open it. Inside, you find a map that shows you the way out of the room. You escape and win the game!");
} else {
System.out.println("Invalid input. Game over!");
}
} else {
System.out.println("Invalid input. Game over!");
}
} else {
System.out.println("Invalid input. Game over!");
}
}
}
```
希望这个 Java 代码可以帮助你理解有文本存储选择过程的文本类游戏的实现方式。
阅读全文