-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.jack
57 lines (49 loc) · 1.65 KB
/
Main.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
// This file is part of nand2tetris, as taught in The Hebrew University, and
// was written by Aviv Yaish. It is an extension to the specifications given
// [here](https://www.nand2tetris.org) (Shimon Schocken and Noam Nisan, 2017),
// as allowed by the Creative Common Attribution-NonCommercial-ShareAlike 3.0
// Unported [License](https://creativecommons.org/licenses/by-nc-sa/3.0/).
/**
* In Jack programs, the first function that runs is always the function "main"
* from the class "Main".
* You can include as many classes and functions as you want.
*/
class Main {
function void main() {
var bool start;
var char key;
var Pong game;
var bool exit;
let start = false;
do Screen.clearScreen();
do Output.moveCursor(6, 26);
do Output.printString("Pong Game");
// Print the instructions
do Output.moveCursor(10, 14);
do Output.printString("Player 1 (Left): W for up and S for down.");
do Output.moveCursor(12, 4);
do Output.printString("Player 2 (Right): uparrow for up and downarrow for down.");
do Output.moveCursor(15, 8);
do Output.printString("The score is displayed at the top of the screen.");
do Output.moveCursor(18, 20);
do Output.printString("Press any key to start");
while (start = false) {
let key = Keyboard.keyPressed();
if (~(key = 0)) {
let start = true;
}
}
let game = Pong.new();
let exit = false;
while (exit = false) {
do game.displayScore();
do game.displayStart();
let exit = game.run();
do game.resetBall();
}
do game.displayEnd();
do game.dispose();
return;
}
// Your code goes here!
}