-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
370 lines (278 loc) · 13.7 KB
/
random.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
360
361
362
363
364
365
366
367
368
369
370
var episodeNumbers = [0, 13, 22, 24, 22, 22, 25, 25, 25, 25, 23];
var s1Titles = ["", "Simpsons Roasting on an Open Fire", "Bart the Genius", "Homer's Odyssey", "There's No Disgrace Like Home", "Bart the General", "Moaning Lisa", "The Call of the Simpsons", "The Telltale Head", "Life on the Fast Lane", "Homer's Night Out", "The Crepes of Wrath", "Krusty Gets Busted", "Some Enchanted Evening"];
var s2Titles = ["", "Bart Gets an \"F\"","Simpson and Delilah","Treehouse of Horror","Two Cars in Every Garage and Three Eyes on Every Fish","Dancin' Homer","Dead Putting Society","Bart vs. Thanksgiving","Bart the Daredevil","Itchy & Scratchy & Marge","Bart Gets Hit by a Car","One Fish, Two Fish, Blowfish, Blue Fish","The Way We Was","Homer vs. Lisa and the 8th Commandment","Principal Charming","Oh Brother, Where Art Thou?","Bart's Dog Gets an \"F\"","Old Money","Brush with Greatness","Lisa's Substitute","The War of the Simpsons","Three Men and a Comic Book","Blood Feud"];
var s3Titles = ["", "Stark Raving Dad","Mr. Lisa Goes to Washington","When Flanders Failed","Bart the Murderer","Homer Defined","Like Father, Like Clown","Treehouse of Horror II","Lisa's Pony","Saturdays of Thunder","Flaming Moe's","Burns Verkaufen der Kraftwerk","I Married Marge","Radio Bart","Lisa the Greek","Homer Alone","Bart the Lover","Homer at the Bat","Separate Vocations","Dog of Death","Colonel Homer","Black Widower","The Otto Show","Bart's Friend Falls in Love","Brother, Can You Spare Two Dimes?"];
var s4Titles = ["", "Kamp Krusty","A Streetcar Named Marge","Homer the Heretic","Lisa the Beauty Queen","Treehouse of Horror III","Itchy & Scratchy: The Movie","Marge Gets a Job","New Kid on the Block","Mr. Plow","Lisa's First Word","Homer's Triple Bypass","Marge vs. the Monorail","Selma's Choice","Brother from the Same Planet","I Love Lisa","Duffless","Last Exit to Springfield","So It's Come to This: A Simpsons Clip Show","The Front","Whacking Day","Marge in Chains","Krusty Gets Kancelled"];
var s5Titles = ["", "Homer's Barbershop Quartet","Cape Feare","Homer Goes to College","Rosebud","Treehouse of Horror IV","Marge on the Lam","Bart's Inner Child","Boy-Scoutz 'n the Hood","The Last Temptation of Homer","$pringfield (or, How I Learned to Stop Worrying and Love Legalized Gambling)","Homer the Vigilante","Bart Gets Famous","Homer and Apu","Lisa vs. Malibu Stacy","Deep Space Homer","Homer Loves Flanders","Bart Gets an Elephant","Burns' Heir","Sweet Seymour Skinner's Baadasssss Song","The Boy Who Knew Too Much","Lady Bouvier's Lover","Secrets of a Successful Marriage"];
var s6Titles = ["", "Bart of Darkness","Lisa's Rival","Another Simpsons Clip Show","Itchy & Scratchy Land","Sideshow Bob Roberts","Treehouse of Horror V","Bart's Girlfriend","Lisa on Ice","Homer Badman","Grampa vs. Sexual Inadequacy","Fear of Flying","Homer the Great","And Maggie Makes Three","Bart's Comet","Homie the Clown","Bart vs. Australia","Homer vs. Patty and Selma","A Star Is Burns","Lisa's Wedding","Two Dozen and One Greyhounds","The PTA Disbands","'Round Springfield","The Springfield Connection","Lemon of Troy","Who Shot Mr. Burns? (Part One)"];
var s7Titles = ["", "Who Shot Mr. Burns? (Part Two)","Radioactive Man","Home Sweet Homediddly-Dum-Doodily","Bart Sells His Soul","Lisa the Vegetarian","Treehouse of Horror VI","King-Size Homer","Mother Simpson","Sideshow Bob's Last Gleaming","The Simpsons 138th Episode Spectacular","Marge Be Not Proud","Team Homer","Two Bad Neighbors","Scenes from the Class Struggle in Springfield","Bart the Fink","Lisa the Iconoclast","Homer the Smithers","The Day the Violence Died","A Fish Called Selma","Bart on the Road","22 Short Films About Springfield","Raging Abe Simpson and His Grumbling Grandson in \"The Curse of the Flying Hellfish\"","Much Apu About Nothing","Homerpalooza","Summer of 4 Ft. 2"];
var s8Titles = ["", "Treehouse of Horror VII","You Only Move Twice","The Homer They Fall","Burns, Baby Burns","Bart After Dark","A Milhouse Divided","Lisa's Date with Density","Hurricane Neddy","El Viaje Misterioso de Nuestro Jomer (The Mysterious Voyage of Homer)","The Springfield Files","The Twisted World of Marge Simpson","Mountain of Madness","Simpsoncalifragilisticexpiala(Annoyed Grunt)cious","The Itchy & Scratchy & Poochie Show","Homer's Phobia","Brother from Another Series","My Sister, My Sitter","Homer vs. the Eighteenth Amendment","Grade School Confidential","The Canine Mutiny","The Old Man and the Lisa","In Marge We Trust","Homer's Enemy","The Simpsons Spin-Off Showcase","The Secret War of Lisa Simpson"];
var s9Titles = ["", "The City of New York vs. Homer Simpson","The Principal and the Pauper","Lisa's Sax","Treehouse of Horror VIII","The Cartridge Family","Bart Star","The Two Mrs. Nahasapeemapetilons","Lisa the Skeptic","Realty Bites","Miracle on Evergreen Terrace","All Singing, All Dancing","Bart Carny","The Joy of Sect","Das Bus","The Last Temptation of Krust","Dumbbell Indemnity","Lisa the Simpson","This Little Wiggy","Simpson Tide","The Trouble with Trillions","Girly Edition","Trash of the Titans","King of the Hill","Lost Our Lisa","Natural Born Kissers"];
var s10Titles = ["", "Lard of the Dance","The Wizard of Evergreen Terrace","Bart the Mother","Treehouse of Horror IX","When You Dish Upon a Star","D'oh-in' in the Wind","Lisa Gets an \"A\"","Homer Simpson in: \"Kidney Trouble\"","Mayored to the Mob","Viva Ned Flanders","Wild Barts Can't Be Broken","Sunday, Cruddy Sunday","Homer to the Max","I'm with Cupid","Marge Simpson in: \"Screaming Yellow Honkers\"","Make Room for Lisa","Maximum Homerdrive","Simpsons Bible Stories","Mom and Pop Art","The Old Man and the \"C\" Student","Monty Can't Buy Me Love","They Saved Lisa's Brain","Thirty Minutes over Tokyo"];
var s8e9AltTitle = "The Mysterious Voyage of Homer";
var s8e9AltTitle2 = "El Viaje Misterioso de Nuestro Jomer";
var s5e10AltTitle = "$pringfield";
var season = 0;
var episode = 0;
var shotNum = 0;
var imagePath = "";
var episodeName = "";
var wrongAnswers = "";
var showEpisodeName = document.createTextNode("");
var giveAnswer = document.createTextNode("");
var score = 0;
var antiScore = 0;
var isAnswered = false;
var hintOn = false;
var isGameOver = false;
var skips = 10;
document.getElementById("skipButton").disabled = false;
document.getElementById("seasonHint").disabled = false;
//var sE = "Season " + season.toString() + " Episode " + episode.toString();
//alert(sE);
var shot = document.createElement("IMG");
getRandomImage();
document.getElementById("imageLocation").appendChild(shot);
shot.onerror = function(){getRandomImage();}
//displayEpisode();
//document.body.appendChild(showEpisodeName);
function getRandomIntInclusive(min, max){
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function gameOver(){
document.getElementById("skipButton").disabled = true;
document.getElementById("seasonHint").disabled = true;
wrongAnswers = "GAME OVER";
document.getElementById("wrongAnswer").innerHTML = wrongAnswers;
isGameOver = true;
toggleText("userInputButton");
document.getElementsByTagName("img")[0].setAttribute("style","-webkit-filter:grayscale(" + 100 + "%)");
//document.getElementsByTagName("img")[0].style.filter = "grayscale(1)";
}
function reset(){
document.getElementsByTagName("img")[0].setAttribute("style","-webkit-filter:grayscale(" + 0 + "%)");
antiScore = 0;
wrongAnswers = "";
document.getElementById("wrongAnswer").innerHTML = wrongAnswers;
isGameOver = false;
score = 0;
var displayScore = document.getElementById("playerScore");
displayScore.innerHTML = score.toString();
document.getElementById("skipButton").disabled = false;
document.getElementById("seasonHint").disabled = false;
skips = 10;
var el = document.getElementById("skipButton");
el.firstChild.data = "Skip (" + skips + ")";
toggleText("userInputButton");
displaySiteResponse("");
document.getElementById("changeYoPadding").style.paddingTop = "150px";
getRandomImage();
}
function checkUserInput(){
var check = document.getElementById("userEpisode").value;
//document.write(check);
var resetNow = true;
var responseToUser = "";
if(hintOn){
toggleHint();
}
if(isAnswered && !isGameOver){
document.getElementById("userEpisode").value = "";
displaySiteResponse("");
toggleText("userInputButton");
if(skips > 0){
document.getElementById("skipButton").disabled = false;}
document.getElementById("seasonHint").disabled = false;
getRandomImage();
}
else{
if(!isGameOver){
if((simplifyString(episodeName) == simplifyString(check)) || (simplifyString(s8e9AltTitle) == simplifyString(check) && season == 8 && episode == 9) || (simplifyString(s8e9AltTitle2) == simplifyString(check) && season == 8 && episode == 9) || (simplifyString(s5e10AltTitle) == simplifyString(check) && season == 5 && episode == 10)){
responseToUser = "Correct!";
document.getElementById("guessResult").style.color = "#0b842e";
if(!isAnswered){
incrementScore();
}
}
else {
responseToUser = "Wrong! The correct answer is: " + episodeName;
document.getElementById("guessResult").style.color = "#db5755";
antiScore++;
wrongAnswers = wrongAnswers + "X ";
document.getElementById("wrongAnswer").innerHTML = wrongAnswers;
document.getElementById("changeYoPadding").style.paddingTop = 0;
document.getElementById("wrongAnswer").style.paddingBottom = "53px";
if(antiScore == 3){
gameOver();
resetNow = false;
}
}
isAnswered = true;
//responseToUser = check;
displaySiteResponse(responseToUser);
toggleText("userInputButton");
//hider();
document.getElementById("skipButton").disabled = true;
document.getElementById("seasonHint").disabled = true;
//giveAnswer = document.createTextNode(responseToUser);
//docum ent.body.appendChild(giveAnswer);
}
}
if(isGameOver && resetNow){
reset();
}
}
function getRandomImage(){
//alert("HELLO");
isAnswered = false;
season = getRandomIntInclusive(1,10);
//season = getRandomIntInclusive(7,7);
episode = getRandomIntInclusive(1, episodeNumbers[season]);
//episode = getRandomIntInclusive(10,11);
shotNum = getRandomIntInclusive(1, 39);
var coinFlip = getRandomIntInclusive(0,1);
imagePath = "./img/Season " + season;
if(season < 10){
imagePath += "/S0" + season.toString() + "E";}
else imagePath += "/S" + season.toString() + "E";
if(episode < 10){
imagePath += "0" + episode.toString() + "/shot_" + shotNum.toString() + ".jpg";
}
else imagePath += episode.toString() + "/shot_" + shotNum.toString() + ".jpg";
shot.setAttribute("src", imagePath);
//document.getElementById("screenshotImage").src= imagePath;
switch(season){
case 1:
episodeName = s1Titles[episode];
break;
case 2:
episodeName = s2Titles[episode];
break;
case 3:
episodeName = s3Titles[episode];
break;
case 4:
episodeName = s4Titles[episode];
break;
case 5:
episodeName = s5Titles[episode];
break;
case 6:
episodeName = s6Titles[episode];
break;
case 7:
episodeName = s7Titles[episode];
break;
case 8:
episodeName = s8Titles[episode];
break;
case 9:
episodeName = s9Titles[episode];
break;
case 10:
episodeName = s10Titles[episode];
break;
}
showEpisodeName = document.createTextNode(episodeName);
if((season == 4 && episode == 18) || (season == 6 && episode == 3) || (season == 7 && episode == 10) || (season == 9 && episode == 11)){
getRandomImage();
}
}
function simplifyString(stringInput){
var str = stringInput;
str = str.replace(/\s+/g, '');
str = str.replace(/[:]+/g, '');
str = str.replace(/[.]+/g, '');
str = str.replace(/[-]+/g, '');
str = str.replace(/[{()}]/g, '');
str = str.replace(/[,]+/g, "");
str = str.replace(/['"]+/g, '');
str = str.replace(/[&]+/g, 'and');
str = str.replace(/[1]+/g, 'one');
str = str.replace(/[2] +/g, 'two');
str = str.replace("?", '');
str = str.toUpperCase();
str = str.replace("THE", "");
return str;
}
function incrementScore(){
score++;
var displayScore = document.getElementById("playerScore");
displayScore.innerHTML = score.toString();
}
function displaySiteResponse(message){
var showResponse = document.getElementById("guessResult");
showResponse.innerHTML = message;
}
function toggleText(button_id)
{
var el = document.getElementById(button_id);
if (el.firstChild.data == "Enter" && !isGameOver)
{
el.firstChild.data = "Next";
}
else if(!isGameOver)
{
el.firstChild.data = "Enter";
}
else{
el.firstChild.data = "Restart";
}
}
function hider(){
var link = document.getElementById('skipButton');
link.style.visibility = 'hidden';
}
function shower(){
var link = document.getElementById('skipButton');
link.style.visibility = 'visible';
}
function enterCheck(e){
evt = e || window.event;
if(evt.keyCode == 13){
checkUserInput();
}
}
function checkKey(e) {
// compliant with ie6
alert(evt.keyCode+' Pressed');
}
function skipper(){
if(hintOn){
toggleHint();
}
if(skips > 0){
skips--;
var el = document.getElementById("skipButton");
el.firstChild.data = "Skip (" + skips + ")";
if(skips == 0){
document.getElementById("skipButton").disabled = true;
}
getRandomImage();
}
}
function toggleHint(coinFlip){
if(hintOn == false){
if(season == 1){
coinFlip = 0;
}
if(season == 10){
coinFlip = 1;
}
if(coinFlip == 0){
document.getElementById("seasonHintText").innerHTML = " Season: " + season.toString() + " or " + (season+1).toString();
}
else document.getElementById("seasonHintText").innerHTML = " Season: " + (season-1).toString() + " or " + season.toString();
}
else document.getElementById("seasonHintText").innerHTML = "";
hintOn = !hintOn;
}
function wait(ms)
{
var d = new Date();
var d2 = null;
do { d2 = new Date(); }
while(d2-d < ms);
}