Skip to content

Commit 9111e60

Browse files
committed
finish bat catcher
1 parent 0f348d3 commit 9111e60

File tree

4 files changed

+486
-212
lines changed

4 files changed

+486
-212
lines changed

jackProgramExample/BatCatcherV1/Bat.jack

+1-22
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ class Bat {
33
field boolean isCaught; // if the bat has been caught or not
44
field int x, y; // position on the screen
55
field int size; // length of this square, in pixels
6-
field Random random;
76

87
/** Constructs a new bat with a given location size and caught as false. */
9-
constructor Bat new(int Ax, int Ay, int Asize, Random randIn) {
8+
constructor Bat new(int Ax, int Ay, int Asize) {
109
let x = Ax;
1110
let y = Ay;
1211
let size = Asize;
1312
let isCaught = false;
14-
let random = randIn;
1513
do draw();
1614
return this;
1715
}
@@ -93,23 +91,4 @@ class Bat {
9391
}
9492
return;
9593
}
96-
97-
method void moveRandomly() {
98-
// Generate a random number between 0 and 3
99-
var int direction;
100-
let direction = random.randRange(3);
101-
if (direction = 0) {
102-
do moveUp();
103-
}
104-
if (direction = 1) {
105-
do moveDown();
106-
}
107-
if (direction = 2) {
108-
do moveLeft();
109-
}
110-
if (direction = 3) {
111-
do moveRight();
112-
}
113-
return;
114-
}
11594
}

jackProgramExample/BatCatcherV1/Bat.vm

+1-52
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function Bat.new 0
2-
push constant 6
2+
push constant 5
33
call Memory.alloc 1
44
pop pointer 0
55
push argument 0
@@ -10,8 +10,6 @@ push argument 2
1010
pop this 4
1111
push constant 0
1212
pop this 1
13-
push argument 3
14-
pop this 5
1513
push pointer 0
1614
call Bat.draw 1
1715
pop temp 0
@@ -269,52 +267,3 @@ pop temp 0
269267
label IF_FALSE0
270268
push constant 0
271269
return
272-
function Bat.moveRandomly 1
273-
push argument 0
274-
pop pointer 0
275-
push this 5
276-
push constant 3
277-
call Random.randRange 2
278-
pop local 0
279-
push local 0
280-
push constant 0
281-
eq
282-
if-goto IF_TRUE0
283-
goto IF_FALSE0
284-
label IF_TRUE0
285-
push pointer 0
286-
call Bat.moveUp 1
287-
pop temp 0
288-
label IF_FALSE0
289-
push local 0
290-
push constant 1
291-
eq
292-
if-goto IF_TRUE1
293-
goto IF_FALSE1
294-
label IF_TRUE1
295-
push pointer 0
296-
call Bat.moveDown 1
297-
pop temp 0
298-
label IF_FALSE1
299-
push local 0
300-
push constant 2
301-
eq
302-
if-goto IF_TRUE2
303-
goto IF_FALSE2
304-
label IF_TRUE2
305-
push pointer 0
306-
call Bat.moveLeft 1
307-
pop temp 0
308-
label IF_FALSE2
309-
push local 0
310-
push constant 3
311-
eq
312-
if-goto IF_TRUE3
313-
goto IF_FALSE3
314-
label IF_TRUE3
315-
push pointer 0
316-
call Bat.moveRight 1
317-
pop temp 0
318-
label IF_FALSE3
319-
push constant 0
320-
return

0 commit comments

Comments
 (0)