-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.coffee
119 lines (110 loc) · 2.13 KB
/
hangman.coffee
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
word = "slippers".split("");
app = App(
width: 800
height: 400
Text(
text: "Letters to guess"
size: 20
bold: yes
font: sansSerif
)
Keyboard(
up: (key) ->
if /^[a-z]$/i.test(key)
if key not in word
mistake()
else
if guessed[key] is no
guessed[key] = yes;
for section in letters[key]
do (section) ->
section.append(Text(
text: key.toUpperCase()
bold: yes
font: sansSerif
));
)
canvas = Canvas(
left: 390
top: 10
width: 400
height: 380
lineWidth: 4
color: black
moveTo(390, 370)
drawLine(10, 370)
moveTo(30, 370)
drawLine(30, 10)
moveTo(10, 10)
drawLine(250, 10)
moveTo(30, 100)
drawLine(100, 10)
moveTo(220, 10)
drawLine(220, 50)
)
)
letters = {}
guessed = {}
for letter, i in word
do(letter, i) ->
guessed[letter] = no
section = Section(
borderWidth: 2
borderColor: black
height: 20
width: 20
top: 50
align: center
left: 5 + (i * 30)
)
app.append(section);
if letters[letter]
letters[letter].push(section)
else
letters[letter] = [section]
headDrawn = no
torsoDrawn = no
leftArmDrawn = no
rightArmDrawn = no
leftLegDrawn = no
rightLegDrawn = no
mistake = () ->
if headDrawn is no
headDrawn = yes
canvas.add(
drawCircle(220, 80, 30)
)
else if torsoDrawn is no
torsoDrawn = yes
canvas.add(
moveTo(220, 110)
drawLine(220, 220)
)
else if leftArmDrawn is no
leftArmDrawn = yes
canvas.add(
moveTo(220, 120)
drawLine(180, 200)
)
else if rightArmDrawn is no
rightArmDrawn = yes
canvas.add(
moveTo(220, 120)
drawLine(260, 200)
)
else if leftLegDrawn is no
leftLegDrawn = yes
canvas.add(
moveTo(220, 220)
drawLine(180, 280)
)
else if rightLegDrawn is no
rightLegDrawn = yes
canvas.add(
moveTo(220, 220)
drawLine(260, 280)
)
setTimeout(
() -> alert("You lost!")
0
)