-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines.wren
56 lines (45 loc) · 1.18 KB
/
lines.wren
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
import "graphics" for Canvas
import "./size_helpers" for SizeHelpers
import "./position" for BrickPosition
class Lines {
construct new() {
_lines = []
_clearedCount = 0
}
setAt(pos, color) {
if (pos.y >= _lines.count) {
var missingLinesCount = pos.y - _lines.count + 1
for (i in 0...missingLinesCount) {
_lines.add(List.filled(SizeHelpers.width, null))
}
}
_lines[pos.y][pos.x] = color
if (_lines[pos.y].all {|brick| brick != null }) {
_lines.removeAt(pos.y)
_clearedCount = _clearedCount + 1
}
}
[pos] { 0 <= pos.y && pos.y < _lines.count &&
0 <= pos.x && pos.x < SizeHelpers.width &&
_lines[pos.y][pos.x] != null }
drawBrick_(x, y, color) {
var pos = BrickPosition.new(x, SizeHelpers.height - y).toReal
Canvas.rectfill(pos.x, pos.y, SizeHelpers.brickSize, SizeHelpers.brickSize, color)
}
draw() {
var y = 0
var x = 0
for (line in _lines) {
for (brick in line) {
if (brick) {
drawBrick_(x, y, brick)
}
x = x + 1
}
x = 0
y = y + 1
}
}
gameOver { _lines.count >= SizeHelpers.height }
clearedCount { _clearedCount }
}