-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathflashcards.html
236 lines (207 loc) · 7.15 KB
/
flashcards.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="css/style.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<title>Jig-draw flashcards</title>
<script src="words-test.js"></script>
<script language="javascript">
window.onload = function() {
window.setTimeout(function() {window.update();}, 1000);
window.secSinceLastClue = 0;
window.playerScore0 = 0;
window.playerScore1 = 0;
window.timerDuration = 5;
// console.log('Testing');
window.getParameterByName = function(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.mode = window.getParameterByName('mode');
if (window.mode == 1)
window.timerDuration = 3;
window.update = function() {
var timer = document.getElementById('timer').innerHTML;
timer = Math.max(0, parseInt(timer) - 1);
document.getElementById('timer').innerHTML = timer;
if (timer <= 0) {
window.playLoser();
document.getElementById('timer').innerHTML = 60;
// alert('Time is up!');
window.getNewWord();
// window.bgaudio.stop();
window.bgaudio.pause();
window.bgaudio.currentTime = 0;
window.setTimeout(window.update, 10000);
return;
}
else if (timer % window.timerDuration === 0 && timer < 60) {
window.playsound('ding');
}
if (timer < 10) {
document.getElementById('timer').style.color = 'red';
} else {
document.getElementById('timer').style.color = 'black';
}
if (timer == 60) {
window.playsound('bgmusic');
}
secSinceLastClue++;
if (secSinceLastClue >= 10) {
this.cycleClues();
secSinceLastClue = 0;
}
window.setTimeout(window.update, 1000);
};
var currentWord;
window.getNewWord = function() {
var numWords = (window.mode == 1) ?
window.library.words.length :
window.library.words_with_clues.length;
var newWord = Math.floor(Math.random() * numWords);
currentWord = newWord;
document.getElementById('majorWord').innerHTML =
(window.mode == 1) ?
library.words[newWord][0] :
library.words_with_clues[newWord][0];
document.getElementById('minorWord').innerHTML =
(window.mode == 1) ?
'':
library.words_with_clues[newWord][1];
document.getElementById('timer').innerHTML = '61';
secSinceLastClue = 0;
};
window.getNewWord();
window.cycleClues = function() {
if (window.mode == 1)
return;
var currentMajorWord = document.getElementById('majorWord').innerHTML;
var currentMinorWord = document.getElementById('minorWord').innerHTML;
var i; // find where the given word is in the dictionary of word-clues
for(i=0; i < window.library.words_with_clues.length; i++) {
if (window.library.words_with_clues[i][0] == currentMajorWord)
break;
}
var currentWord = i;
// var currentWord = window.library.words.indexOf(currentMajorWord);
// console.log(currentMajorWord, currentWord);
var currentClue = window.library.words_with_clues[currentWord].indexOf(currentMinorWord);
currentClue++;
if (currentClue >= window.library.words_with_clues[currentWord].length) {
currentClue = 1;
}
document.getElementById('minorWord').innerHTML = window.library.words_with_clues[currentWord][currentClue];
secSinceLastClue = 0;
}
window.incrementPlayerScore = function(player) {
if (player == 0) {
window.playerScore0++;
document.getElementById('player0Score').innerHTML = window.playerScore0;
}
else {
window.playerScore1++;
document.getElementById('player1Score').innerHTML = window.playerScore1;
}
window.getNewWord();
}
document.onkeydown = function(e) {
e = e || window.event;
switch(e.which || e.keyCode) {
// case 32:
case 32:
window.playsound('ding');
break;
case 38:
case 40:
window.bgaudio.pause();
alert('pause');
window.bgaudio.play();
break;
case 37: // left
window.incrementPlayerScore(0);
window.playWinner();
break;
case 39: // right
window.incrementPlayerScore(1);
window.playWinner();
break;
}
}
window.playsound = function(sound) {
var audio;
if (sound == 'ding') {
audio = new Audio('./sounds/ding.wav');
audio.play();
}
if (sound == 'woopow') {
audio = new Audio('./sounds/woopow.wav');
audio.play();
}
if (sound == 'bgmusic') {
if (window.bgaudio) {
window.bgaudio.pause();
window.bgaudio.currentTime = 0;
}
window.bgaudio = new Audio('./sounds/60secRoundMus.wav');
window.bgaudio.play();
}
if (sound == 'likeabaws') {
audio = new Audio('./sounds/likeabaws.wav');
audio.play();
}
}
window.playWinner = function () {
var soundFiles = [ 'likeabaws', 'woopow', 'drawesome', 'jiggy', 'heehee' ];
window.playAudio(soundFiles);
}
window.playLoser = function () {
var soundFiles = [ 'Deadmario', 'Stupid', 'bingo', 'vansuck', 'supersorryo', 'loserville', 'tweetledumb', '99problems', 'gotosleep', 'knockknock' ];
window.playAudio(soundFiles);
}
window.playAudio = function (soundFiles) {
var index = Math.floor(Math.random() * soundFiles.length);
var audio = new Audio('./sounds/'+soundFiles[index]+'.wav');
audio.play();
}
}
</script>
</head>
<body>
<script type="text/javascript">
function getNewWord() {
window.getNewWord();
}
</script>
<header>
<div id="status" class="group">
<span>:</span><span id="timer">61</span>
</div><!--Status div -->
<nav class="group">
<!-- <ul>
<li class="button" onclick="javascript:window.getNewWord();">New Word</li>
<li class="button" onclick="javascript:window.getNewWord();">New Word</li>
<li class="button" onclick="javascript:window.cycleClues();">New Clue</li>
</ul> -->
<div class="player left">
<h3>Player 1</h3>
<span class="button player1" onclick="javascript:window.incrementPlayerScore(0);">Winner!</span>
<span id="player0Score">0</span>
</div>
<div class="player right">
<h3>Player 2</h3>
<span id="player1Score">0</span>
<span class="button player2" onclick="javascript:window.incrementPlayerScore(1);">Winner!</span>
</div>
</nav>
</header>
<div class="container">
<div id="majorWord">Foo</div>
<div id="minorWord">Bar</div>
</div>
<span class="button newclue" onclick="javascript:window.cycleClues();">New Clue</span>
</div>
</body>
</html>