-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.java
More file actions
68 lines (58 loc) · 1.8 KB
/
Copy pathRoom.java
File metadata and controls
68 lines (58 loc) · 1.8 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public final class Room {
private final String description;
private final Monster monster;
private final static Random random = new Random();
private final static Set<Integer> roomsSeen = new HashSet<Integer>();
private final static int NUM_ROOMS = 7;
private Room(String description, Monster monster) {
this.description = description;
this.monster = monster;
}
public static Room newRegularInstance() {
if (roomsSeen.size() == NUM_ROOMS) {
roomsSeen.clear();
}
int i;
do {
i = random.nextInt(NUM_ROOMS);
} while (roomsSeen.contains(i));
roomsSeen.add(i);
String roomDescription = null;
if (i == 0) {
roomDescription = "bla bla bla";
} else if (i == 1) {
roomDescription = "bla bla bla";
} else if (i == 2) {
roomDescription = "bla bla bla";
} else if (i == 3) {
roomDescription = "bla bla bla";
} else if (i == 4) {
roomDescription =
"bla bla bla";
} else if (i == 5) {
roomDescription =
"bla bla bla";
} else if (i == 6) {
roomDescription = "bla bla blan";
} else {
}
return new Room(roomDescription, Monster.newRandomInstance(), false);
}
public boolean isComplete() {
return !monster.isAlive();
}
@Override
public String toString() {
return description;
}
public void enter(Player player) throws IOException {
System.out.println(description);
if (monster.isAlive()) {
new Combat(player, monster);
}
}
}