-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhosts.jack
63 lines (58 loc) · 1.24 KB
/
Ghosts.jack
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
class Ghosts {
field Array ghosts;
field int nGhosts;
field PacMan pacman;
field Walls walls;
field Pellets pellets;
constructor Ghosts new(PacMan pm, Walls w, Pellets p) {
let nGhosts = 4;
let walls = w;
let pacman = pm;
let pellets = p;
let ghosts = Array.new(nGhosts);
do createGhosts();
return this;
}
method void createGhosts() {
let ghosts[0] = Ghost.new(162, 117, pacman, walls, pellets);
let ghosts[1] = Ghost.new(162, 117, pacman, walls, pellets);
let ghosts[2] = Ghost.new(162, 117, pacman, walls, pellets);
let ghosts[3] = Ghost.new(162, 117, pacman, walls, pellets);
return;
}
method void init() {
var int i;
var Ghost cur;
let i = 0;
while (i < nGhosts) {
let cur = ghosts[i];
do cur.init();
let i = i + 1;
}
return;
}
method void next() {
var int i;
var Ghost cur;
let i = 0;
while (i < nGhosts) {
let cur = ghosts[i];
do cur.next();
let i = i + 1;
}
return;
}
method void dispose() {
var Ghost b;
var int i;
let i = 0;
while (i < 4) {
let b = ghosts[i];
do b.dispose();
let i = i + 1;
}
do ghosts.dispose();
do Memory.deAlloc(this);
return;
}
}