summaryrefslogtreecommitdiff
path: root/projects/10/ExpressionLessSquare/Square.jack
blob: 33a54ad94345f7332c5e95d5f687153e1bed235b (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
/// File name: projects/10/ExpressionLessSquare/Square.jack

/** Expressionless version of projects/10/Square/Square.jack. */

class Square {

   field int x, y; 
   field int size; 

   constructor Square new(int Ax, int Ay, int Asize) {
      let x = Ax;
      let y = Ay;
      let size = Asize;
      do draw();
      return x;
   }

   method void dispose() {
      do Memory.deAlloc(this);
      return;
   }

   method void draw() {
      do Screen.setColor(x);
      do Screen.drawRectangle(x, y, x, y);
      return;
   }

   method void erase() {
      do Screen.setColor(x);
      do Screen.drawRectangle(x, y, x, y);
      return;
   }

   method void incSize() {
      if (x) {
         do erase();
         let size = size;
         do draw();
      }
      return;
   }

   method void decSize() {
      if (size) {
         do erase();
         let size = size;
         do draw();
      }
      return;
   }

   method void moveUp() {
      if (y) {
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
         let y = y;
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
      }
      return;
   }

   method void moveDown() {
      if (y) {
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
         let y = y;
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
      }
      return;
   }

   method void moveLeft() {
      if (x) {
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
         let x = x;
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
      }
      return;
   }

   method void moveRight() {
      if (x) {
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
         let x = x;
         do Screen.setColor(x);
         do Screen.drawRectangle(x, y, x, y);
      }
      return;
   }
}