Hunt The Wumpus/Java: Difference between revisions

m
→‎Code: well, we've finally got our enumset
m (set of hazards should be EnumSet)
m (→‎Code: well, we've finally got our enumset)
Line 95:
 
void startNewGame() {
currRoom = rand.nextInt(rooms.length);
numArrows = 3;
currRoom = rand.nextInt(rooms.length);
messages = new ArrayList<>();
 
Line 132:
 
void situation() {
EnumSet<Hazard> lstset = hazards.get(currRoom);
 
if (lstset.contains(Hazard.Wumpus)) {
messages.add("you've been eaten by the Wumpus");
gameOver = true;
 
} else if (lstset.contains(Hazard.Pit)) {
messages.add("you fell into a pit");
gameOver = true;
 
} else if (lstset.contains(Hazard.Bat)) {
messages.add("a bat dropped you in a random room");
 
Line 150 ⟶ 151:
 
// relocate the bat, but not to the player room
lstset.remove(Hazard.Bat);
int newRoom;
do {
Line 184 ⟶ 185:
hazards.get(wumpusRoom).remove(Hazard.Wumpus);
wumpusRoom = links[wumpusRoom][rand.nextInt(3)];
 
if (wumpusRoom == currRoom) {
messages.add("You woke the Wumpus and he ate you");
Line 229 ⟶ 231:
g.setColor(Color.darkGray);
g.setStroke(new BasicStroke(2));
 
for (int i = 0; i < links.length; i++) {
for (int link : links[i]) {
Anonymous user