forked from KC3Kai/kancolle-replay
-
Notifications
You must be signed in to change notification settings - Fork 5
/
quiz-voice.html
125 lines (109 loc) · 3.12 KB
/
quiz-voice.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
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/kcSHIPDATA.js"></script>
<script src="js/shared.js"></script>
<script src="js/howler.min.js"></script>
<script src="js/playersound.js"></script>
<script src="js/playersound2.js"></script>
<style>
div.outer {
margin-top:50px;
}
div.inner {
text-align: center;
padding:3px;
}
#divScore {
font-size:20px;
}
#spanTimer {
font-size:24px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner" id="divScore">Score: <span id="spanScore">0</span></div>
<div class="inner"><span id="spanTimer"></span></div>
<div class="inner"><input type="button" id="btnStart" value="Start" /></div>
<div class="inner"><input type="button" id="btnQuestion" value="►" /></div>
<div class="inner" id="divAnswer"><input id="txtAnswer" /><input type="button" id="btnSkip" value="Skip"/></div>
</div>
<script>
var TIME = 120;
let d = new Date(TIME*1000);
$('#spanTimer').text(d.toTimeString().substr(4,4));
(function() {
function Quiz() {
this.time = 120;
this.currentId = 0;
this.currentType = '';
this.done = [];
this.score = 0;
}
var QUIZ = new Quiz();
var QUESTIONS = [];
var SM = new SoundManager();
for (let mid in VOICES) {
if (mid < 1000 && SHIPDATA[mid].prev == 0) {
QUESTIONS.push(mid);
}
}
function startTimer() {
var itvTimer = setInterval(function() {
QUIZ.time--;
let d = new Date(QUIZ.time*1000);
$('#spanTimer').text(d.toTimeString().substr(4,4));
if (QUIZ.time <= 0) {
clearInterval(itvTimer);
endQuiz();
}
}, 1000);
}
function endQuiz() {
$('#btnQuestion').hide();
$('#divAnswer').hide();
}
function nextQuestion() {
for (let i=0; i<1000; i++) {
QUIZ.currentId = QUESTIONS[Math.floor(Math.random()*QUESTIONS.length)];
if (QUIZ.done.indexOf(QUIZ.currentId) == -1) break;
}
let keys = []; for (let key in VOICES[QUIZ.currentId]) keys.push(key);
QUIZ.currentType = keys[Math.floor(Math.random()*keys.length)];
SM.playVoice(QUIZ.currentId, QUIZ.currentType, 0);
$('#txtAnswer').val('');
}
function clearQuestion() {
QUIZ.done.push(QUIZ.currentId);
QUIZ.score++;
$('#spanScore').text(QUIZ.score);
nextQuestion();
}
function checkAnswer() {
let answer = $('#txtAnswer').val();
if (answer.toLowerCase().replace(' ','') == SHIPDATA[QUIZ.currentId].name.toLowerCase().replace(' ','')) clearQuestion();
}
$('#btnQuestion').hide();
$('#divAnswer').hide();
$('#btnStart').click(function() {
$('#btnQuestion').show();
$('#divAnswer').show();
$('#txtAnswer').focus();
$('#btnStart').hide();
startTimer();
nextQuestion();
});
$('#btnQuestion').click(function() {
SM.playVoice(QUIZ.currentId, QUIZ.currentType, 0);
});
$('#btnSkip').click(function() {
nextQuestion();
});
$('#txtAnswer').on('keyup',checkAnswer);
})();
</script>
</body>
</html>