-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
359 lines (331 loc) · 10 KB
/
script.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// Created by The Young Programmer [TYP 💻]
var word = [
["Hangman", "That game you are playing right now."],
["Nemonet", "About the creator of this game."],
["HTML", "Markup language for creating Web pages."],
["CSS", "Wep page styles"],
["PHP", "A very popular server scripting language."],
["JavaScript", "Make web-page dynamic without reload the web page."],
["Java", "Run 15 billion devices.\nA program can be run in Windows, Linux and Mac"],
["Github", "A company that everyone can code for fun and share."],
["Love", "What is ?\nBaby don't hurt me\nDon't hurt me\nNo more"],
["Document", "A lot of text in the a file."],
["Playground", "There school kids go to."],
["Run", "Usain bolt."],
["Code", "var hw = 'Hello World';"],
["Samsung", "A company create Phone, Tv, Monitor, SDD, Memory chip..."],
["Super Mario", "A very popular game in Nintendo 64 that have red hat."],
["Star", "Super Mario like to get."],
["Clock", "14:12 or 14pm"],
["Binary Clock", "A clock that only use 0 or 1."],
["Sword", "Link from Zelda have on the hand."],
["Girl", "Not boy but ?"],
["Boy", "Not girl but ?"],
["Female", "Other name as girl."],
["Male", "Other name as boy."],
["Smartphone", "Something you've always on you."],
["MUG", "A large cup."],
["TELEPHONE", "A system for transmitting voices."],
["CAR", "Moving object powered by an engine."],
["HORSE", "A domesticated, odd-toed, hoofed mammal."],
["CAMERA", "Can shoot you without causing any harm. What is it?"],
["OLDER", "What everyone gets at the same time?"],
["FOOTSTEP", "The more you take, the more you leave behind. What am I?"],
["ENVELOPE", "What word begins and ends with an E, but only has one letter?"],
["SQUARE", "A shape that have all size equal."],
["HOUSE", "A building for human habitation"],
["MEADOW", "A piece of grassland, especially one used for hay."],
["BULL", "A male animal of the cow."],
["TOWEL", "A thick soft cloth in the bathroom"],
["BAG", "#"],
["BOOK", "#"],
["PLATE", "#"],
["PERFUME", "#"],
["PEN", "#"],
["BENCH", "#"],
["BLOCK", "#"],
["ELEPHANT", "#"],
["COMMODE", "#"],
["LAPTOP", "#"],
["CABLE", "#"],
["TIME", "What flies without wings?"],
["SPOON", "#"],
["HAND", "#"],
["EAR", "#"],
["PIERCE", "#"],
["DRESS", "#"],
["BLANKET", "#"],
["SHOES", "#"],
["CAT", "#"],
["SAND", "#"],
["LAVA", "#"],
["SHARK", "#"],
["DRAWER", "#"],
["FIGURE", "#"],
["DESK", "#"],
["WIPER", "#"],
["WATER", "#"],
["SANDWICH", "Yummy filling between bread. What is it?"],
["TRUCK", "#"],
["DOLL", "#"],
["GUITAR", "#"],
["DRUM", "#"],
["PIANO", "#"],
["PLATTER", "#"],
["PUZZLE", "#"],
["TIGER", "#"],
["BEAR", "#"],
["LINOLEUM", "#"],
["STICKER", "#"],
["FOLDER", "#"],
["FILE", "#"],
["LIST", "#"],
["CLOCK", "#"],
["FOX", "#"],
["BUTTERFLY", "#"],
["KEYBOARD", "#"],
["CAMERA", "#"],
["LENS", "#"],
["SMARTPHONE", "#"],
["FISHNET", "#"],
["STOCKING", "#"],
["CLOTH", "#"],
["TURTLE", "#"],
["FISH", "#"],
["BONE", "#"],
["ICE", "#"],
["GROUND", "#"],
["SALAD", "#"],
["BIKE", "#"],
["PLANE", "#"],
["TRAIN", "#"],
["METRO", "#"],
["SHIP", "#"],
["VEST", "#"],
["PHOTO", "#"],
["STRING", "#"],
["CHAIN", "#"],
["BRACELET", "#"],
["COLLAR", "#"],
["FUR", "#"],
["DISH", "#"],
["SINK", "#"],
["COOKER", "#"],
["AQUARIUM", "#"],
["WOOL", "#"],
["PILLOW", "#"],
["CAP", "#"],
["BAND", "#"],
["BANDANA", "#"],
["DRAGON", "#"],
["SHELL", "#"],
["GLOBE", "#"],
["MICROSCOPE", "#"],
["JACKET", "#"],
["PICTURE", "#"],
["KARMA", "#"],
["RIPE", "#"],
["RUBBER", "#"],
["COUNTER", "#"],
["CASES", "#"],
["SWITCH", "#"],
["ILO", "#"],
["BROOM", "#"],
["ONION", "Take off my skin, I won't cry, but you will. What Am I?"],
["SHEET", "#"],
["LEAF", "#"],
];
// Game keyboard
var tastatur = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Game memory
var select = 0;
var wordLeft = [];
var fail = 0;
// Web-page onload
window.onload = function () {
gId("moveKeybord").addEventListener(
"touchmove",
function (e) {
wH = window.innerHeight;
tY = e.touches[0].clientY;
eL = gId("tastatur");
resY = wH - tY - eL.offsetHeight;
if (resY < 0) {
resY = 0;
} else if (resY > wH / 2) {
resY = wH / 2;
}
eL.style.bottom = resY + "px";
},
false
);
createTastur();
};
// Start game
function startGame() {
gId("home").className = "h";
gId("result").className = "h";
newGame();
}
// New game
function newGame() {
clearTastatur();
clearPlayer();
createWord();
}
// Clear keyboard
function clearTastatur() {
var e = document.getElementsByClassName("b");
for (a = 0; a < e.length; a++) {
e[a].setAttribute("data", "");
}
}
// Clear player
function clearPlayer() {
fail = 0;
wordLeft = [];
gId("g0").setAttribute("data", "false");
gId("g1").setAttribute("data", "false");
gId("g2").setAttribute("data", "false");
gId("g3").setAttribute("data", "false");
gId("g4").setAttribute("data", "false");
gId("g5").setAttribute("data", "false");
gId("g5").setAttribute("r", "false");
gId("g5").setAttribute("l", "false");
gId("g6").setAttribute("data", "false");
gId("g6").setAttribute("l", "false");
gId("g6").setAttribute("r", "false");
gId("hintButton").setAttribute("data", "false");
gId("hint").style.display = "none";
}
// Get new word
function createWord() {
var d = gId("letter");
d.innerHTML = "";
select = Math.floor(Math.random() * word.length);
for (a = 0; a < word[select][0].length; a++) {
var x = word[select][0][a].toUpperCase();
var b = document.createElement("span");
b.className = "l" + (x == " " ? " ls" : "");
b.innerHTML = " ";
b.id = "l" + a;
d.appendChild(b);
if (x != " ") {
if (wordLeft.indexOf(x) == -1) {
wordLeft.push(x);
}
}
}
}
// Create keyboard
function createTastur() {
var tas = gId("keybord");
tas.innerHTML = "";
for (a = 0; a < tastatur.length; a++) {
var b = document.createElement("span");
b.className = "b";
b.innerText = tastatur[a];
b.setAttribute("data", "");
b.onclick = function () {
bTas(this);
};
tas.appendChild(b);
}
}
// Game check, If show next error / game end
function bTas(a) {
if (a.getAttribute("data") == "") {
var x = isExist(a.innerText);
a.setAttribute("data", x);
if (x) {
if (wordLeft.length == 0) {
gameEnd(true);
}
} else {
showNextFail();
}
}
}
// If letter "X" exist
function isExist(e) {
e = e.toUpperCase();
var x = wordLeft.indexOf(e);
if (x != -1) {
wordLeft.splice(x, 1);
typeWord(e);
return true;
}
return false;
}
// Show next fail drawing
function showNextFail() {
fail++;
switch (fail) {
case 1:
gId("g0").setAttribute("data", "true");
break;
case 2:
gId("g1").setAttribute("data", "true");
break;
case 3:
gId("g2").setAttribute("data", "true");
break;
case 4:
gId("g3").setAttribute("data", "true");
gId("hintButton").setAttribute("data", "true");
break;
case 5:
gId("g4").setAttribute("data", "true");
break;
case 6:
gId("g5").setAttribute("data", "true");
break;
case 7:
gId("g5").setAttribute("l", "true");
break;
case 8:
gId("g5").setAttribute("r", "true");
break;
case 9:
gId("g6").setAttribute("data", "true");
gId("g6").setAttribute("l", "true");
break;
case 10:
gId("g6").setAttribute("r", "true");
gameEnd(false);
break;
}
}
function typeWord(e) {
for (a = 0; a < word[select][0].length; a++) {
if (word[select][0][a].toUpperCase() == e) {
gId("l" + a).innerText = e;
}
}
}
// Game result
function gameEnd(e) {
var d = gId("result");
d.setAttribute("data", e);
if (e) {
gId("rT").innerText = "You Win!";
gId("rM").innerHTML = "Congratulations, you found the word!<br/><br/>Good Job!";
} else {
gId("rT").innerText = "You Lose!";
gId("rM").innerHTML = 'The word was <br/><br/>"' + word[select][0].toUpperCase() + '"<br/><br/>Better luck next time.';
}
d.className = "";
}
// Show hint
function hint() {
gId("hintText").innerText = word[select][1];
gId("hint").style.display = "block";
}
// Exit hint
function hintExit() {
gId("hint").style.display = "none";
}
// Get HTML ID element by name
function gId(a) {
return document.getElementById(a);
}