-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStacker.jack
More file actions
52 lines (46 loc) · 1.23 KB
/
Stacker.jack
File metadata and controls
52 lines (46 loc) · 1.23 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
43
44
45
46
47
48
49
50
51
52
/**
* Implements the main menu of the game.
* The user presses 'p' to play and 'q' to quit.
*/
class Stacker {
field Array menuStr;
field boolean quit;
field int key;
field StackerGame game;
constructor Stacker new() {
let menuStr = Array.new(4);
let menuStr[0] = "S T A C K E R";
let menuStr[1] = "-------------";
let menuStr[2] = "Stack blocks by pressing SPACE to lock the row in place";
let menuStr[3] = "Press 'p' to play, 'q' to quit.";
return this;
}
method void run() {
while (~(key = Constants.KEY_Q())) {
do Screen.clearScreen();
do Output.moveCursor(10, 26);
do Output.printString(menuStr[0]);
do Output.moveCursor(11, 26);
do Output.printString(menuStr[1]);
do Output.moveCursor(13, 4);
do Output.printString(menuStr[2]);
do Output.moveCursor(15, 17);
do Output.printString(menuStr[3]);
while (key = 0) {
let key = Keyboard.keyPressed();
}
if (key = Constants.KEY_P()) {
do Screen.clearScreen();
let game = StackerGame.new();
do game.run();
do game.dispose();
let key = 0;
}
}
return;
}
method void dispose() {
do Memory.deAlloc(this);
return;
}
}