Repository navigation
Expand file tree
/
Copy pathboring.html
More file actions
161 lines (153 loc) · 5.88 KB
/
Copy pathboring.html
File metadata and controls
161 lines (153 loc) · 5.88 KB
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
<!DOCTYPE html>
<html><head><title>Unfinished game</title><meta name="viewport" content="width=device-width,initial-scale=1.0" /></head>
<body>
<img style="display: none;" src="https://harmlesswebsite.leoshi6.repl.co/BSIV_ALT.png" alt="" />
<form action="javascript:;" onsubmit="startGame()" style="padding: 3px;">
<p>DISCLAIMER: This game features flashing elements that can get as fast as 0.5 seconds per animation cycle. If you have epilepsy, please do not play this game.</p>
<label>Enter the number of levels you want (0 for infinite):
<input id="levels" type="number" min="0" />
</label>
<input type="submit" value="Start Game" />
</form>
<div style="display: none;" id="gameplay">
<br />
<div class="cool" style="animation-duration: 30s; padding: 30px; border-radius: 10px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">
<span id="load"><img src="loading.gif" alt="" height="20" /> Loading words...</span>
<form style="display: none;" action="javascript:;" id="quizForm" onsubmit="submitAWord()">
<h2>All right...</h2>
<p>The rules are simple:</p>
<ol>
<li>Look at the word</li>
<li>Type the translation</li>
<li>Submit!</li>
<li>Repeat!</li>
</ol>
<hr />
<p>What does <b id="wordField">$WORD</b> mean?</p>
<label>Meaning of <b id="wordField2">$WORD</b>: <input id="answer" autocomplete="off" /></label>
<input type="submit" />
</form>
<p>You currently have <span id="right">$RIGHT</span> correct and <span id="wrong">$WRONG</span> wrong, for a percentage of <span id="percent">$PERCENT</span>.</p>
<div style="display: none;" id="returnLink"><center style="font-size: 40px;">Game <span id="game-status">$STATUS</span>!</center> <a href="https://harmlesswebsite.leoshi6.repl.co">Return to site?</a></div>
</div>
</div>
<script src="https://harmlesswebsite.leoshi6.repl.co/script.js"></script>
<script>
function shuffle(array) {
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle...
while (currentIndex != 0) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
return array;
}
function isNumeric(str) {
if (typeof str != "string") return false;
return !isNaN(str) &&
!isNaN(parseFloat(str))
}
function startGame() {
var questionsLeft = document.getElementById('levels').value;
if (questionsLeft !== "0" && isNumeric(questionsLeft)) questionsLeft = Math.round(parseFloat(questionsLeft));
else questionsLeft = Infinity;
globalThis.questionsLeft = questionsLeft;
document.getElementById('gameplay').style.display = 'block';
document.querySelector('form[onsubmit="startGame()"]').style.display = 'none';
loadWords();
}
function loadWords() {
var oReq = new XMLHttpRequest;
oReq.addEventListener('load', function() {
var words = JSON.parse(this.responseText);
shuffle(words);
globalThis.words = words;
document.getElementById('load').style.display = 'none';
document.getElementById('quizForm').style.display = 'block';
document.getElementById('wrong').textContent = 0;
document.getElementById('right').textContent = 0
document.getElementById('percent').textContent = '[undefined]%';
loadAWord(null);
});
oReq.open('GET', 'https://' + location.hostname + '/latin_words.json', true);
oReq.send();
}
function loadAWord(word2Avoid) {
if (globalThis.questionsLeft === 0) {
document.getElementById('quizForm').style.display = 'none';
document.getElementById('returnLink').style.display = 'block';
var status = 'finished (you passed)';
var right = parseInt(document.querySelector('#right').textContent),
wrong = parseInt(document.querySelector('#wrong').textContent);
if ((right / (right + wrong)) < 0.8) status = 'over';
document.getElementById('game-status').textContent = status;
return;
}
var words = globalThis.words;
while (words[0].word === word2Avoid) shuffle(words);
var word = words[0];
document.getElementById('wordField').textContent = word.word;
document.getElementById('wordField2').textContent = word.word;
globalThis.ans = word.ans;
globalThis.word = word.word;
}
function submitAWord() {
var newAnimDuration = parseFloat(document.querySelector('.cool').style.animationDuration.slice(0, -1));
const value = document.getElementById('answer').value;
if (value !== globalThis.ans) {
// WRONG
document.getElementById('wrong').textContent = parseInt(document.getElementById('wrong').textContent) + 1;
newAnimDuration *= 0.9;
} else {
// RIGHT
newAnimDuration *= 1.1;
document.getElementById('right').textContent = parseInt(document.getElementById('right').textContent) + 1;
}
var right = parseInt(document.getElementById('right').textContent),
wrong = parseInt(document.getElementById('wrong').textContent);
document.getElementById('percent').textContent = (Math.round(10000 * (right/(right + wrong))) / 100) + "%";
document.getElementById('answer').value = '';
document.getElementById('answer').focus();
globalThis.questionsLeft--;
loadAWord(globalThis.word);
if (newAnimDuration < 0.5) newAnimDuration = 0.5;
console.log(newAnimDuration + "s");
document.querySelector('.cool').style.animationDuration = newAnimDuration + "s";
}
</script>
<style>
body {
margin: 0;
padding: 0;
}
#gameplay {
background-image: url(https://harmlesswebsite.leoshi6.repl.co/BSIV_ALT.png);
background-size: 100%;
width: 100vw;
height: 100vh;
}
.cool {
animation-name: cool;
animation-iteration-count: infinite;
}
@keyframes cool {
0% {
background-color: lime;
}
33% {
background-color: skyblue;
}
66% {
background-color: pink;
}
100% {
background-color: lime;
}
}
</style>
</body>
</html>