-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphabet.html
330 lines (295 loc) · 12.1 KB
/
alphabet.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alphabet Grec</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f5f5f5;
}
h1 {
color: #333;
text-align: center;
}
button {
padding: 10px 20px;
margin: 10px;
font-size: 18px;
cursor: pointer;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#feedback {
margin-top: 20px;
font-size: 20px;
font-weight: bold;
visibility: hidden;
}
#score {
margin-top: 20px;
font-size: 24px;
font-weight: bold;
color: #333;
}
#menu {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#game, #learn {
display: none;
flex-direction: column;
align-items: center;
justify-content: center;
}
#alphabetDisplay {
display: flex;
flex-wrap: wrap;
justify-content: center;
font-size: 24px;
margin: 20px 0;
gap: 10px;
}
.letter {
display: flex;
flex-direction: column;
align-items: center;
margin: 5px;
cursor: pointer;
}
.active-letter {
color: #007bff;
font-weight: bold;
}
/* Responsive design adjustments */
@media (max-width: 600px) {
#alphabetDisplay {
font-size: 18px;
gap: 5px;
}
button {
font-size: 16px;
padding: 8px 16px;
}
h1 {
font-size: 24px;
}
}
</style>
</head>
<body>
<div id="menu">
<h1>Alphabet Grec</h1>
<p>Choisissez le type de lettres :</p>
<button onclick="startGame(true)">Lettres Majuscules</button>
<button onclick="startGame(false)">Lettres Minuscules</button>
<button onclick="startLearning()">Mode Apprentissage</button>
</div>
<div id="game">
<h1>Alphabet Grec</h1>
<p id="instructions">Sélectionnez le bon caractère :</p>
<audio id="audioPlayer" src="./lettres_grecques/alpha.mp3"></audio>
<div id="choices">
<!-- Les boutons de choix seront générés par le script -->
</div>
<div id="feedback">Placeholder</div>
<div id="score">Score: 0/20</div>
<button id="replayAudio" onclick="playAudio()">Rejouer l'audio</button>
</div>
<div id="learn">
<h1>Mode Apprentissage</h1>
<div id="alphabetDisplay">
<!-- Toutes les lettres seront affichées ici -->
</div>
<audio id="learnAudioPlayer"></audio>
<div>
<button onclick="previousLetter()">Précédent</button>
<button onclick="playLearnAudio()">Écouter</button>
<button onclick="nextLetter()">Suivant</button>
</div>
<button onclick="backToMenu()">Retour au Menu</button>
</div>
<script>
const letters = [
{ name: 'alpha', file: './lettres_grecques/alpha.mp3', upper: 'Α', lower: 'α' },
{ name: 'beta', file: './lettres_grecques/beta.mp3', upper: 'Β', lower: 'β' },
{ name: 'gamma', file: './lettres_grecques/gamma.mp3', upper: 'Γ', lower: 'γ' },
{ name: 'delta', file: './lettres_grecques/delta.mp3', upper: 'Δ', lower: 'δ' },
{ name: 'epsilon', file: './lettres_grecques/épsilon.mp3', upper: 'Ε', lower: 'ε' },
{ name: 'zeta', file: './lettres_grecques/zêta.mp3', upper: 'Ζ', lower: 'ζ' },
{ name: 'eta', file: './lettres_grecques/êta.mp3', upper: 'Η', lower: 'η' },
{ name: 'theta', file: './lettres_grecques/thêta.mp3', upper: 'Θ', lower: 'θ' },
{ name: 'iota', file: './lettres_grecques/iota.mp3', upper: 'Ι', lower: 'ι' },
{ name: 'kappa', file: './lettres_grecques/kappa.mp3', upper: 'Κ', lower: 'κ' },
{ name: 'lambda', file: './lettres_grecques/lambda.mp3', upper: 'Λ', lower: 'λ' },
{ name: 'mu', file: './lettres_grecques/mu.mp3', upper: 'Μ', lower: 'μ' },
{ name: 'nu', file: './lettres_grecques/nu.mp3', upper: 'Ν', lower: 'ν' },
{ name: 'xi', file: './lettres_grecques/ksi.mp3', upper: 'Ξ', lower: 'ξ' },
{ name: 'omicron', file: './lettres_grecques/omicron.mp3', upper: 'Ο', lower: 'ο' },
{ name: 'pi', file: './lettres_grecques/pi.mp3', upper: 'Π', lower: 'π' },
{ name: 'rho', file: './lettres_grecques/rhô.mp3', upper: 'Ρ', lower: 'ρ' },
{ name: 'sigma', file: './lettres_grecques/sigma.mp3', upper: 'Σ', lower: 'σ' },
{ name: 'tau', file: './lettres_grecques/tau.mp3', upper: 'Τ', lower: 'τ' },
{ name: 'upsilon', file: './lettres_grecques/upsilon.mp3', upper: 'Υ', lower: 'υ' },
{ name: 'phi', file: './lettres_grecques/phi.mp3', upper: 'Φ', lower: 'φ' },
{ name: 'chi', file: './lettres_grecques/khi.mp3', upper: 'Χ', lower: 'χ' },
{ name: 'psi', file: './lettres_grecques/psi.mp3', upper: 'Ψ', lower: 'ψ' },
{ name: 'omega', file: './lettres_grecques/oméga.mp3', upper: 'Ω', lower: 'ω' }
];
let currentLetter = null;
let score = 0;
let attempts = 0;
let isUpperCase = true;
let feedbacktimeout = null;
let currentLearnIndex = 0;
function playAudio() {
const audioPlayer = document.getElementById('audioPlayer');
if (currentLetter) {
audioPlayer.src = currentLetter.file;
}
audioPlayer.play();
}
function generateChoices() {
const choicesDiv = document.getElementById('choices');
choicesDiv.innerHTML = '';
const shuffledLetters = letters.sort(() => 0.5 - Math.random());
currentLetter = shuffledLetters[Math.floor(Math.random() * 5)];
shuffledLetters.slice(0, 5).forEach(letter => {
const btn = document.createElement('button');
btn.innerText = isUpperCase ? letter.upper : letter.lower;
btn.onclick = () => {
checkAnswer(letter);
// Remove focus from the button that was clicked
btn.blur();
};
choicesDiv.appendChild(btn);
});
// Play the audio for the current letter
playAudio();
// Explicitly remove focus from all buttons
const allButtons = choicesDiv.getElementsByTagName('button');
for (let i = 0; i < allButtons.length; i++) {
allButtons[i].blur();
}
}
function checkAnswer(selectedLetter) {
const feedbackDiv = document.getElementById('feedback');
const scoreDiv = document.getElementById('score');
// Check if the selected answer is correct
if (selectedLetter.name === currentLetter.name) {
score++;
feedbackDiv.innerText = 'Correct!';
feedbackDiv.style.color = 'green';
} else {
feedbackDiv.innerText = 'Incorrect. Réessayez.';
feedbackDiv.style.color = 'red';
}
// Show feedback and update the score
feedbackDiv.style.visibility = 'visible';
attempts++;
scoreDiv.innerText = `Score: ${score}/20`;
// Proceed to the next question or end the game
if (attempts < 20) {
clearTimeout(feedbacktimeout);
feedbacktimeout = setTimeout(() => {
feedbackDiv.style.visibility = 'hidden';
}, 1500);
generateChoices();
} else {
feedbackDiv.innerText = `Jeu terminé!`;
const replayBtn = document.createElement('button');
replayBtn.innerText = 'Rejouer';
replayBtn.onclick = resetGame;
document.getElementById('instructions').style.visibility = 'hidden';
document.getElementById('replayAudio').style.visibility = 'hidden';
document.getElementById('choices').innerHTML = '';
document.getElementById('choices').appendChild(replayBtn);
}
}
function resetGame() {
score = 0;
attempts = 0;
document.getElementById('score').innerText = 'Score: 0/20';
document.getElementById('feedback').innerText = '';
document.getElementById('instructions').style.visibility = 'visible';
document.getElementById('replayAudio').style.visibility = 'visible';
generateChoices();
}
function startGame(useUpperCase) {
isUpperCase = useUpperCase;
document.getElementById('menu').style.display = 'none';
document.getElementById('game').style.display = 'flex';
generateChoices();
}
function startLearning() {
currentLearnIndex = 0;
document.getElementById('menu').style.display = 'none';
document.getElementById('learn').style.display = 'flex';
displayAlphabet();
updateLearnMode();
}
function displayAlphabet() {
const alphabetDisplay = document.getElementById('alphabetDisplay');
alphabetDisplay.innerHTML = ''; // Clear any previous content
letters.forEach((letter, index) => {
const letterDiv = document.createElement('div');
letterDiv.className = 'letter';
letterDiv.innerHTML = `<span>${letter.upper}</span><span>${letter.lower}</span>`;
letterDiv.onclick = () => setActiveLetter(index);
alphabetDisplay.appendChild(letterDiv);
});
}
function setActiveLetter(index) {
currentLearnIndex = index;
updateLearnMode();
}
function updateLearnMode() {
const learnAudioPlayer = document.getElementById('learnAudioPlayer');
const alphabetDisplay = document.getElementById('alphabetDisplay');
const letterDivs = alphabetDisplay.getElementsByClassName('letter');
// Remove active class from all letters
Array.from(letterDivs).forEach(div => div.classList.remove('active-letter'));
// Add active class to the current letter
letterDivs[currentLearnIndex].classList.add('active-letter');
// Play the audio for the current letter
learnAudioPlayer.src = letters[currentLearnIndex].file;
playLearnAudio();
}
function playLearnAudio() {
const learnAudioPlayer = document.getElementById('learnAudioPlayer');
learnAudioPlayer.play();
}
function previousLetter() {
if (currentLearnIndex > 0) {
currentLearnIndex--;
updateLearnMode();
}
}
function nextLetter() {
if (currentLearnIndex < letters.length - 1) {
currentLearnIndex++;
updateLearnMode();
}
}
function backToMenu() {
document.getElementById('learn').style.display = 'none';
document.getElementById('menu').style.display = 'flex';
}
</script>
</body>
</html>