forked from dtschust/javapacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhost.java
39 lines (33 loc) · 972 Bytes
/
Ghost.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
/* Ghost class controls the ghost. */
class Ghost extends Mover {
/* The pellet the ghost was last on top of */
int lastPelletX, lastPelletY;
/*Constructor places ghost and updates states*/
public Ghost(int x, int y) {
super(x, y);
lastPelletX = pelletX;
lastPelletY = pelletY;
}
/* update pellet status */
public void updatePellet() {
int tempX, tempY;
tempX = x / gridSize - 1;
tempY = y / gridSize - 1;
if (tempX != pelletX || tempY != pelletY) {
lastPelletX = pelletX;
lastPelletY = pelletY;
pelletX = tempX;
pelletY = tempY;
}
}
/* Random move function for ghost */
public void move() {
lastX = x;
lastY = y;
/* If we can make a decision, pick a new direction randomly */
if (isChoiceDest()) {
direction = newDirection();
}
step(direction);
}
}