-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.lua
49 lines (40 loc) · 846 Bytes
/
events.lua
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
function on.construction()
resetGame()
end
function on.paint(gc)
drawCells(gc)
drawColors(gc)
drawNumbers(gc)
if gameOver then
gc:drawString("GAME OVER!", 125, 15, "middle");
end
end
function on.backspaceKey()
if gameOver then
resetGame()
end
end
function on.charIn(char)
if gameOver then return end
local oldField = field
if char == '8' then
handleMove("up")
end
if char == '2' then
handleMove("down")
end
if char == '4' then
handleMove("left")
end
if char == '6' then
handleMove("right")
end
if fieldChanged(oldField, field) and areFreeFields(field) then
field = insertNumber(field)
end
platform.window:invalidate()
if gameLost(field) then
gameOver = true
return
end
end