-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.jack
52 lines (43 loc) · 979 Bytes
/
Grid.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
class Grid {
field int pixelsPerCell;
field int width, height;
field Array cells;
constructor Grid new(int w, int h) {
let pixelsPerCell = 16;
let width = w;
let height = h;
let cells = Array.new(width * height);
return this;
}
method void draw() {
var int x, y;
let y = 0;
while (y < height) {
let x = 0;
while (x < width) {
if (valueAt(x, y)) {
do Screen.drawRectangle(
x * pixelsPerCell,
y * pixelsPerCell,
((x + 1) * pixelsPerCell) - 1,
((y + 1) * pixelsPerCell) - 1
);
}
let x = x + 1;
}
let y = y + 1;
}
return;
}
method bool valueAt(int x, int y) {
var int index;
let index = (y * width) + x;
return cells[index];
}
method void setValueAt(int x, int y, bool value) {
var int index;
let index = (y * width) + x;
let cells[index] = value;
return;
}
}