-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultichoice.html
More file actions
277 lines (229 loc) · 6.39 KB
/
Copy pathmultichoice.html
File metadata and controls
277 lines (229 loc) · 6.39 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>WordNet Multiple Choice Game</title>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
background: black;
overflow: hidden;
}
#Matrix {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: 1;
}
#gameCard {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: min(650px, calc(100vw - 48px));
padding: 28px;
box-sizing: border-box;
background: rgba(0,0,0,0.85);
border: 2px solid #FC1212;
box-shadow: 0 0 25px #FC1212;
z-index: 5;
font-family: monospace;
color: #FC1212;
text-align: center;
}
#prompt {
font-size: 18px;
line-height: 1.5;
margin-bottom: 20px;
}
#choices {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.choice {
padding: 12px;
border: 1px solid #FC1212;
background: black;
color: #FC1212;
cursor: pointer;
font-size: 15px;
transition: 0.15s;
user-select: none;
}
.choice:hover {
background: #FC1212;
color: black;
}
#status {
margin-top: 15px;
font-size: 14px;
opacity: 0.85;
min-height: 18px;
}
</style>
</head>
<body>
<canvas id="Matrix"></canvas>
<div id="gameCard">
<div id="prompt">Loading...</div>
<div id="choices"></div>
<div id="status"></div>
</div>
<script>
/* ---------------- MATRIX ---------------- */
const canvas = document.getElementById("Matrix");
const ctx = canvas.getContext("2d");
const fontSize = 16;
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let columns, drops = [];
function resetMatrix(){
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
columns = Math.ceil(canvas.width / fontSize);
drops = Array(columns).fill(1);
}
function drawMatrix(){
ctx.fillStyle = "rgba(0,0,0,0.05)";
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.fillStyle = "#FC1212";
ctx.font = fontSize + "px monospace";
for(let i=0;i<drops.length;i++){
const text = alphabet[Math.floor(Math.random()*alphabet.length)];
ctx.fillText(text, i*fontSize, drops[i]*fontSize);
if(drops[i]*fontSize > canvas.height && Math.random() > 0.975){
drops[i]=0;
}
drops[i]++;
}
}
resetMatrix();
window.addEventListener("resize", resetMatrix);
setInterval(drawMatrix, 30);
/* ---------------- GAME ---------------- */
const STORAGE_KEY = "wordGameData";
let nouns = [];
let currentWord = null;
let wrongAttempts = 0;
const prompt = document.getElementById("prompt");
const choicesBox = document.getElementById("choices");
const status = document.getElementById("status");
function normalizeKey(w){ return String(w||"").trim().toUpperCase(); }
function enrich(word){
return {
...word,
correct: Number(word.correct)||0,
wrong: Number(word.wrong)||0,
difficulty: Math.max(0.1, Number(word.difficulty)||1)
};
}
function pickWord(){
const weights = nouns.map(w=>{
const attempts = w.correct + w.wrong;
const weakness = Math.max(0, w.wrong - w.correct);
const newBoost = attempts === 0 ? 2 : 0;
return 1 + weakness + newBoost + 1/Math.max(0.2,w.difficulty);
});
let total = weights.reduce((a,b)=>a+b,0);
let r = Math.random()*total;
for(let i=0;i<nouns.length;i++){
r -= weights[i];
if(r<=0) return nouns[i];
}
return nouns[0];
}
function getRandomDistractors(correctWord){
const pool = nouns
.filter(w => w.word !== correctWord.word);
const shuffled = pool.sort(()=>Math.random()-0.5);
return shuffled.slice(0,3);
}
function shuffle(arr){
return arr.sort(()=>Math.random()-0.5);
}
function renderChoices(word) {
const distractors = getRandomDistractors(word);
const options = shuffle([
word.word,
...distractors.map(w => w.word)
]);
choicesBox.innerHTML = "";
options.forEach(optionWord => {
const btn = document.createElement("div");
btn.className = "choice";
btn.textContent = optionWord;
btn.onclick = () => {
const isCorrect = normalizeKey(optionWord) === normalizeKey(word.word);
handleAnswer(isCorrect);
};
choicesBox.appendChild(btn);
});
}
function makeQuestion(def, word){
return def.replace(new RegExp(word.word,"gi"), "_____");
}
function nextWord(){
currentWord = pickWord();
wrongAttempts = 0;
prompt.textContent = makeQuestion(
currentWord.defs.join(" "),
currentWord
);
status.textContent = "";
renderChoices(currentWord);
}
/* -------- scoring -------- */
function recordAttempt(correct){
if(correct){
currentWord.correct++;
currentWord.difficulty *= 1.05;
status.textContent = "CORRECT";
} else {
currentWord.wrong++;
currentWord.difficulty = Math.max(0.1, currentWord.difficulty*0.9);
status.textContent = "WRONG";
}
localStorage.setItem(STORAGE_KEY, JSON.stringify(nouns));
}
/* -------- answer handler -------- */
function handleAnswer(isCorrect) {
if (!currentWord) return;
// update stats exactly like your original system
if (isCorrect) {
currentWord.correct++;
currentWord.difficulty *= 1.05;
status.textContent = "CORRECT";
} else {
currentWord.wrong++;
currentWord.difficulty = Math.max(0.1, currentWord.difficulty * 0.90);
status.textContent = "WRONG";
}
currentWord.lastAnsweredAt = new Date().toISOString();
// save like original
localStorage.setItem(STORAGE_KEY, JSON.stringify(nouns));
// IMPORTANT: delay prevents double-click / race issues
setTimeout(() => {
nextWord();
}, 650);
}
/* -------- load -------- */
async function load(){
const res = await fetch("wordnet.json");
nouns = (await res.json()).map(enrich);
const saved = localStorage.getItem(STORAGE_KEY);
if(saved){
const parsed = JSON.parse(saved);
const map = new Map(parsed.map(w=>[w.word,w]));
nouns = nouns.map(w=>map.get(w.word)||w);
}
nextWord();
}
window.addEventListener("DOMContentLoaded", load);
</script>
</body>
</html>