-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWumpus.java
More file actions
42 lines (36 loc) · 1.13 KB
/
Wumpus.java
File metadata and controls
42 lines (36 loc) · 1.13 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
/***
* An enemy which can occupy a location in a room and is not to be touched.
*
* @author David
*/
public class Wumpus {
private Room currentRoom; // room the Wumpus is in
private int row, col; // the location of the wumpus in the room
public Wumpus(Room r) {
currentRoom = r;
row = 6;
col = 8;
currentRoom.put(row, col, 3); // THIS IS BAD. WHY?
}
// returns true if enemy was able to move in that direction.
public boolean move(int direction) {
int newrow = row;
int newcol = col;
if (direction == Location.NORTH) newrow--;
if (direction == Location.SOUTH) newrow++;
if (direction == Location.EAST) newcol++;
if (direction == Location.WEST) newcol--;
if (currentRoom.isEmpty(newrow, newcol)) {
currentRoom.put(row, col, 0);
currentRoom.put(newrow, newcol, 3);
row = newrow;
col = newcol;
return true;
}
return false;
}
public void randomMove() {
// you can fill this one
return;
}
}