forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.java
102 lines (81 loc) · 2.62 KB
/
main.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.util.Scanner;
public class TextAdventure {
private static final Scanner scanner = new Scanner(System.in);
private static Room currentRoom;
public static void main(String[] args) {
currentRoom = new Room("Starting room");
gameLoop();
}
private static void gameLoop() {
while (true) {
System.out.println("You are in " + currentRoom.getName());
System.out.println("What do you want to do?");
String command = scanner.nextLine();
switch (command) {
case "go north":
currentRoom = currentRoom.getNorthRoom();
break;
case "go south":
currentRoom = currentRoom.getSouthRoom();
break;
case "go east":
currentRoom = currentRoom.getEastRoom();
break;
case "go west":
currentRoom = currentRoom.getWestRoom();
break;
case "examine":
System.out.println(currentRoom.getDescription());
break;
default:
System.out.println("I don't understand that command.");
}
}
}
private static class Room {
private final String name;
private final String description;
private final Room northRoom;
private final Room southRoom;
private final Room eastRoom;
private final Room westRoom;
public Room(String name) {
this.name = name;
this.description = "";
this.northRoom = null;
this.southRoom = null;
this.eastRoom = null;
this.westRoom = null;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public Room getNorthRoom() {
return northRoom;
}
public Room getSouthRoom() {
return southRoom;
}
public Room getEastRoom() {
return eastRoom;
}
public Room getWestRoom() {
return westRoom;
}
public void setNorthRoom(Room northRoom) {
this.northRoom = northRoom;
}
public void setSouthRoom(Room southRoom) {
this.southRoom = southRoom;
}
public void setEastRoom(Room eastRoom) {
this.eastRoom = eastRoom;
}
public void setWestRoom(Room westRoom) {
this.westRoom = westRoom;
}
}
}