-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
259 lines (207 loc) · 8.07 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
window.onload = function () {
var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z'];
var categories; // Array of topics
var chosenCategory; // Selected catagory
var getHint; // Word getHint
var word; // Selected word
var guess; // Geuss
var geusses = []; // Stored geusses
var lives; // Lives
var counter; // Count correct geusses
var space; // Number of spaces in word '-'
var gameOver=false;
// Get elements
var showLives = document.getElementById("mylives");
var showCatagory = document.getElementById("scatagory");
var getHint = document.getElementById("hint");
var showClue = document.getElementById("clue");
// create alphabet ul
var buttons = function () {
myButtons = document.getElementById('buttons');
letters = document.createElement('ul');
for (var i = 0; i < alphabet.length; i++) {
letters.id = 'alphabet';
list = document.createElement('li');
list.id = 'letter';
list.innerHTML = alphabet[i];
check();
myButtons.appendChild(letters);
letters.appendChild(list);
}
}
// Select Catagory
var selectCat = function () {
if (chosenCategory === categories[0]) {
catagoryName.innerHTML = "The Chosen Category Is One Word Substitution";
} else if (chosenCategory === categories[1]) {
catagoryName.innerHTML = "The Chosen Category Is Indian Brands";
} else if (chosenCategory === categories[2]) {
catagoryName.innerHTML = "The Chosen Category Is Indian Cities";
}
}
// Create geusses ul
result = function () {
wordHolder = document.getElementById('hold');
correct = document.createElement('ul');
for (var i = 0; i < word.length; i++) {
correct.setAttribute('id', 'my-word');
guess = document.createElement('li');
guess.setAttribute('class', 'guess');
if (word[i] === "-") {
guess.innerHTML = "-";
space = 1;
} else {
guess.innerHTML = "_";
}
geusses.push(guess);
wordHolder.appendChild(correct);
correct.appendChild(guess);
}
}
// Show lives
comments = function () {
showLives.innerHTML = "You have " + lives + " lives";
if (lives < 1) {
showLives.innerHTML = "Game Over\n the word was "+ word;
gameOver=true;
}
for (var i = 0; i < geusses.length; i++) {
if (counter + space === geusses.length) {
showLives.innerHTML = "You Win!";
}
}
}
// Animate man
var animate = function () {
var drawMe = lives;
drawArray[drawMe]();
}
// Hangman
canvas = function () {
myStickman = document.getElementById("stickman");
context = myStickman.getContext('2d');
context.beginPath();
context.strokeStyle = "#fff";
context.lineWidth = 2;
};
head = function () {
myStickman = document.getElementById("stickman");
context = myStickman.getContext('2d');
context.beginPath();
context.arc(60, 25, 10, 0, Math.PI * 2, true);
context.stroke();
}
draw = function ($pathFromx, $pathFromy, $pathTox, $pathToy) {
context.moveTo($pathFromx, $pathFromy);
context.lineTo($pathTox, $pathToy);
context.stroke();
}
frame1 = function () {
draw(0, 150, 150, 150);
};
frame2 = function () {
draw(10, 0, 10, 600);
};
frame3 = function () {
draw(0, 5, 70, 5);
};
frame4 = function () {
draw(60, 5, 60, 15);
};
torso = function () {
draw(60, 36, 60, 70);
};
rightArm = function () {
draw(60, 46, 100, 50);
};
leftArm = function () {
draw(60, 46, 20, 50);
};
rightLeg = function () {
draw(60, 70, 100, 100);
};
leftLeg = function () {
draw(60, 70, 20, 100);
};
drawArray = [rightLeg, leftLeg, rightArm, leftArm, torso, head, frame4, frame3, frame2, frame1];
// OnClick Function
check = function () {
list.onclick = function () {
var geuss = (this.innerHTML);
this.setAttribute("class", "active");
this.onclick = null;
if(!gameOver)
{
//this.setAttribute("class", "active");
for (var i = 0; i < word.length; i++) {
if (word[i] === geuss) {
geusses[i].innerHTML = geuss;
counter += 1;
}
}
var j = (word.indexOf(geuss));
if (j === -1) {
lives -= 1;
comments();
animate();
} else {
comments();
}
}
}
}
// Play
play = function () {
categories = [
["geology", "anthropology", "psychology", "atheist", "introvert", "pedestrian", "philanthropist","cartographer"],
["aquafina", "amul", "castrol", "coca-cola", "complan",
"flipkart","haldiram","kurkure","nestle","sensodyne",
"videocon"],
["shillong", "bhubaneshwar", "jamshedpur", "kashmir",
"pondicherry","chennai","madurai","kollam",
"hyderabad","bangalore" ,"nasik","mumbai","jodhpur"]
];
chosenCategory = categories[Math.floor(Math.random() * categories.length)];
word = chosenCategory[Math.floor(Math.random() * chosenCategory.length)];
word = word.replace(/\s/g, "-");
console.log(word);
buttons();
geusses = [];
lives = 10;
counter = 0;
space = 0;
result();
comments();
selectCat();
canvas();
gameOver=false;
}
play();
// Hint
hint.onclick = function () {
hints = [
["The study of rocks and soil", "The study of evolution of mankind", "The study of Human Mind", "The one who does not believe in God",
"Someone who is reserved and shy", "Someone who walks by foot", "The one who loves mankind","A person who draws maps"],
["Pure Water That Tastes Good", "Utterly, Butterly, Delicious", "It’s More Than Just Oil", "Always The Real Thing!", "For Extra Growing Power",
"Shopping Ka Naya Address","Taste Of Tradition","Spend Time With Family","Good Food, Good Life","Stop The Pain And Eat What You Love",
"Experience Change"],
["Scotland of East", "Temple city of India", "Steel city of India, Pittsburgh of India", "Switzerland of India",
"Paris of the East" ,"Gateway of South, Detroit of Asia" ,"The City of Festivals, Athens of the East","Cashew Capital",
"City of Pearls, Hitech city","Space city, Science city, Silicon Valley of India",
"Wine Capital of India" ,"City of 7 Islands, Gateway of India","Blue city, Sun city"]
];
var catagoryIndex = categories.indexOf(chosenCategory);
var hintIndex = chosenCategory.indexOf(word);
showClue.innerHTML = "Clue: - " + hints[catagoryIndex][hintIndex];
};
// Reset
document.getElementById('reset').onclick = function () {
correct.parentNode.removeChild(correct);
letters.parentNode.removeChild(letters);
showClue.innerHTML = "";
context.clearRect(0, 0, 400, 400);
play();
}
}