-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square.jack
65 lines (58 loc) · 1.5 KB
/
Square.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
64
65
/**
Implements a graphical square.
*/
class Square {
field int x, y; // screen location of the square's top-left corner
field int size; // length of this square, in pixels
/**
Constructs a new square with a given location and size.
*/
constructor Square new(int Ax, int Ay, int Asize) {
let x= Random.randRange(511 - Asize);
let y = Ay;
let size = Asize;
do draw(y);
return this;
}
/**
Disposes this square.
*/
method void dispose() {
do Memory.deAlloc(this);
return;
}
/**
Draws the square on the screen.
*/
method void draw(int Ay) {
let x= Random.randRange(511 - (2*size));
let y = Ay;
do Screen.setColor(false);
do Screen.drawRectangle(x, y, x + (2*size), y + size);
return;
}
/**
Erases the square from the screen.
*/
method void erase() {
do Screen.setColor(true);
do Screen.drawRectangle(x, y, x + (size*2), y + size);
return;
}
/**
Moves the square down by 2 pixels.
*/
method void moveDown() {
if ((y + size) < 254) {
// do Screen.setColor(true);
// do Screen.drawRectangle(x, y, x + (size*2), y + 1);
let y = y + 2;
do Screen.setColor(false);
do Screen.drawRectangle(x, (y + size) - 1, x + (size*2), y + size);
}
return;
}
method int getX(){
return x;
}
}