-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaitext.java
More file actions
51 lines (41 loc) · 1.86 KB
/
aitext.java
File metadata and controls
51 lines (41 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class aitext {
public static void main(String[] args) {
// Initialize game components
Player player = new Player();
Room currentRoom = createStartingRoom();
Scanner scanner = new Scanner(System.in);
OpenAITextGenerator aiGenerator = new OpenAITextGenerator();
// Game loop
while (!player.isDead()) {
// Display current room description
System.out.println(currentRoom.getDescription());
// Display available exits
System.out.println("Exits: " + currentRoom.getExits().keySet());
// Prompt for user input
System.out.print("What will you do? ");
String userInput = scanner.nextLine().toLowerCase();
// Generate AI response based on user input
String aiResponse = aiGenerator.generateResponse("You are in a room. " + userInput);
// Print AI response
System.out.println(aiResponse);
// Check for game over condition
if (aiResponse.contains("The End.")) {
player.die();
}
// Move to another room if applicable
if (currentRoom.getExits().containsKey(userInput)) {
currentRoom = currentRoom.getExits().get(userInput);
}
}
// Game over
System.out.println("Game over. Thanks for playing!");
}
private static Room createStartingRoom() {
Room startingRoom = new Room("You are in a small, dimly lit room. There is a door to the north.");
Room northRoom = new Room("You are in a large, brightly lit hall. There are doors to the south and east.");
startingRoom.setExit("north", northRoom);
northRoom.setExit("south", startingRoom);
return startingRoom;
}
}