Jaouadart commited on
Commit
650bb27
·
verified ·
1 Parent(s): a5b837a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +47 -70
index.html CHANGED
@@ -23,7 +23,7 @@
23
  align-items: center;
24
  padding: 0;
25
  touch-action: pan-x pan-y;
26
- overflow-x: hidden; /* Prevent horizontal scroll */
27
  transition: background-color 0.5s ease;
28
  }
29
  .container {
@@ -289,7 +289,7 @@
289
  #game-board {
290
  display: grid;
291
  grid-template-columns: repeat(4, 1fr);
292
- gap: 0.75rem; /* Reduced gap for smaller squares */
293
  perspective: 1000px;
294
  width: 100%;
295
  justify-content: center;
@@ -297,7 +297,7 @@
297
 
298
  .game-card {
299
  width: 100%;
300
- max-width: 90px; /* Smaller max width for cards */
301
  aspect-ratio: 1 / 1;
302
  background-color: #6C757D;
303
  border-radius: 0.75rem;
@@ -338,7 +338,7 @@
338
  background-position: center;
339
  }
340
  .game-card-back {
341
- background-color: #263238; /* Darker back color */
342
  }
343
  #game-info {
344
  margin-top: 1rem;
@@ -446,7 +446,7 @@
446
  width: 100%;
447
  height: 100%;
448
  object-fit: contain;
449
- filter: brightness(0); /* Makes the image black (shadow) */
450
  opacity: 0.4;
451
  }
452
  #shadow-game-bottom {
@@ -556,11 +556,9 @@
556
 
557
 
558
  <script>
559
- // Global state to manage pages and games
560
  let currentPage = 'main';
561
  let currentGame = null;
562
 
563
- // --- THEMES ---
564
  const themes = {
565
  'amurs': {
566
  bg: '#F0F4C3',
@@ -608,14 +606,12 @@
608
 
609
  function applyTheme(themeName) {
610
  const theme = themes[themeName];
611
- const root = document.documentElement;
612
-
613
- // Update CSS variables if needed, or directly update element styles
614
  document.body.style.backgroundColor = theme.bg;
615
- document.querySelector('.header').style.backgroundColor = theme.primary;
616
- document.querySelector('.sidebar').style.backgroundColor = theme.primary;
617
-
618
- // Update buttons and badges
 
619
  const interactiveCards = document.querySelectorAll('.interactive-card');
620
  interactiveCards.forEach(card => card.style.backgroundColor = theme.primary);
621
 
@@ -649,7 +645,6 @@
649
  if (cardText) cardText.style.color = theme.primary;
650
  });
651
 
652
- // Update text colors for dynamic content
653
  const dynamicText = document.querySelectorAll('.text-2xl, .text-xl, .story-text');
654
  dynamicText.forEach(text => {
655
  text.style.color = theme.primary;
@@ -659,13 +654,8 @@
659
  if (messageBox) {
660
  messageBox.style.backgroundColor = theme.primary;
661
  }
662
-
663
- // Re-render the current page to apply changes consistently
664
- renderPage();
665
  }
666
 
667
- // --- END THEMES ---
668
-
669
  // Data for different pages
670
  const tifinaghData = [
671
  { letter: 'ⴰ', word: 'ⴰⵎⴰⵏ', image: 'https://source.unsplash.com/400x400/?water', audio: 'audio/aman.mp3' },
@@ -855,26 +845,25 @@
855
 
856
  // Data for memory game images
857
  const memoryGameImages = [
858
- 'https://source.unsplash.com/400x400/?cat', // قطة
859
- 'https://source.unsplash.com/400x400/?dog', // كلب
860
- 'https://source.unsplash.com/400x400/?lion', // أسد
861
- 'https://source.unsplash.com/400x400/?elephant', // فيل
862
- 'https://source.unsplash.com/400x400/?monkey', // قرد
863
- 'https://source.unsplash.com/400x400/?giraffe', // زرافة
864
- 'https://source.unsplash.com/400x400/?tiger', // نمر
865
- 'https://source.unsplash.com/400x400/?bear', // دب
866
- 'https://source.unsplash.com/400x400/?fish', // سمكة
867
- 'https://source.unsplash.com/400x400/?bird', // طائر
868
- 'https://source.unsplash.com/400x400/?rabbit', // أرنب
869
- 'https://source.unsplash.com/400x400/?sheep' // خروف
870
  ];
871
 
872
  // Memory game levels with image pairs
873
- // كل مستوى يحدد عدد أزواج الصور، وسيتم اختيار الصور عشوائياً من القائمة أعلاه
874
  const memoryGameLevels = [
875
- { pairs: 8, grid: 'repeat(4, 1fr)' }, // Level 1: 16 cards (4x4)
876
- { pairs: 10, grid: 'repeat(5, 1fr)' }, // Level 2: 20 cards (5x4)
877
- { pairs: 12, grid: 'repeat(6, 1fr)' } // Level 3: 24 cards (6x4)
878
  ];
879
 
880
  const guessingGameData = [
@@ -897,9 +886,6 @@
897
  { animal: 'سنجاب', image: 'https://source.unsplash.com/400x400/?squirrel', shadow: 'https://placehold.co/400x400/000000/000000?text=squirrel-shadow' },
898
  ];
899
 
900
- const numberGameData = numbersData.slice(0, 6);
901
- const letterGameData = tifinaghData.slice(0, 6);
902
-
903
  const colorsData = [
904
  { word: 'أحمر', color: '#EF5350', audio: 'audio/red.mp3' },
905
  { word: 'أزرق', color: '#42A5F5', audio: 'audio/blue.mp3' },
@@ -938,11 +924,10 @@
938
  return array;
939
  }
940
 
941
- // New function to play a sound
942
  function playSound(src) {
943
  const player = document.getElementById('sound-player');
944
  player.src = src;
945
- player.play();
946
  }
947
 
948
  function showMessage(htmlContent, duration = 2500) {
@@ -951,18 +936,16 @@
951
 
952
  msgContent.innerHTML = htmlContent;
953
 
954
- // Show message box
955
  msgBox.style.display = 'block';
956
  setTimeout(() => {
957
  msgBox.classList.add('visible');
958
  }, 10);
959
 
960
- // Hide message box after duration
961
  setTimeout(() => {
962
  msgBox.classList.remove('visible');
963
  setTimeout(() => {
964
  msgBox.style.display = 'none';
965
- }, 500); // 500ms transition duration
966
  }, duration);
967
  }
968
 
@@ -973,10 +956,9 @@
973
  <p>طالب بالمدرسة العليا للتربية والتكوين ببرشيد</p>
974
  <p>تخصص اللغة الأمازيغية</p>
975
  `;
976
- showMessage(developerInfoHtml, 5000); // 5 seconds for developer info
977
  }
978
 
979
- // About & Contact Info
980
  function showAboutInfo() {
981
  const aboutInfoHtml = `
982
  <div class="text-xl font-bold mb-4">حول التطبيق</div>
@@ -994,14 +976,12 @@
994
  showMessage(contactInfoHtml, 7000);
995
  }
996
 
997
- // Navigation functions
998
  function goBack() {
999
  currentPage = 'main';
1000
  currentGame = null;
1001
  renderPage();
1002
  }
1003
 
1004
- // Sidebar functions
1005
  function openSidebar() {
1006
  document.getElementById("sidebar").style.width = "250px";
1007
  }
@@ -1012,7 +992,8 @@
1012
 
1013
  function renderPage() {
1014
  const appContainer = document.getElementById('app-container');
1015
- appContainer.innerHTML = ''; // Clear previous content
 
1016
 
1017
  const header = createHeader();
1018
  appContainer.appendChild(header);
@@ -1053,13 +1034,10 @@
1053
  renderShadowGame(appContainer);
1054
  }
1055
 
1056
- // Apply theme after rendering to ensure new elements have correct colors
1057
- // Check for a saved theme or default to 'amurs'
1058
  const savedTheme = localStorage.getItem('theme') || 'amurs';
1059
  applyTheme(savedTheme);
1060
  }
1061
 
1062
- // Header Creation
1063
  function createHeader() {
1064
  const header = document.createElement('div');
1065
  header.className = 'header';
@@ -1083,7 +1061,6 @@
1083
  return header;
1084
  }
1085
 
1086
- // Main Menu
1087
  function renderMainMenu(container) {
1088
  const mainContent = document.createElement('div');
1089
  mainContent.className = 'grid-container';
@@ -1128,7 +1105,6 @@
1128
  container.appendChild(mainContent);
1129
  }
1130
 
1131
- // Tifinagh Letters Page
1132
  function renderTifinaghPage(container) {
1133
  const tifinaghGrid = document.createElement('div');
1134
  tifinaghGrid.className = 'grid-container';
@@ -1147,7 +1123,6 @@
1147
  container.appendChild(tifinaghGrid);
1148
  }
1149
 
1150
- // Generic Interactive Page
1151
  function renderInteractivePage(container, data, title) {
1152
  const pageTitle = document.createElement('h2');
1153
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
@@ -1170,7 +1145,6 @@
1170
  container.appendChild(grid);
1171
  }
1172
 
1173
- // Colors Page
1174
  function renderColorsPage(container) {
1175
  const pageTitle = document.createElement('h2');
1176
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
@@ -1191,7 +1165,6 @@
1191
  container.appendChild(grid);
1192
  }
1193
 
1194
- // Stories Page
1195
  function renderStoriesPage(container) {
1196
  const pageTitle = document.createElement('h2');
1197
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
@@ -1210,7 +1183,6 @@
1210
  });
1211
  }
1212
 
1213
- // Game Menu
1214
  function renderGameMenu(container) {
1215
  const gameMenu = document.createElement('div');
1216
  gameMenu.className = 'grid-container';
@@ -1228,7 +1200,6 @@
1228
  container.appendChild(gameMenu);
1229
  }
1230
 
1231
- // Memory Game Logic
1232
  let hasFlippedCard = false;
1233
  let lockBoard = false;
1234
  let firstCard, secondCard;
@@ -1260,6 +1231,7 @@
1260
  resetMemoryGameState();
1261
  const board = document.getElementById('game-board');
1262
  const info = document.getElementById('game-info');
 
1263
 
1264
  totalPairs = memoryGameLevels[currentLevel].pairs;
1265
  const shuffledImages = shuffleArray([...memoryGameImages].slice(0, totalPairs));
@@ -1310,7 +1282,8 @@
1310
  firstCard.classList.add('matched');
1311
  secondCard.classList.add('matched');
1312
  matchedPairs++;
1313
- document.getElementById('matched-count').innerText = matchedPairs;
 
1314
  if (matchedPairs === totalPairs) {
1315
  setTimeout(() => {
1316
  showMessage('تهانينا! لقد ربحت اللعبة!');
@@ -1364,6 +1337,8 @@
1364
 
1365
  function displayGuessingQuestion() {
1366
  const questionBox = document.getElementById('guessing-question');
 
 
1367
  if (currentQuestionIndex >= guessingGameData.length) {
1368
  questionBox.innerHTML = `
1369
  <div class="text-2xl font-bold">انتهت اللعبة!</div>
@@ -1395,7 +1370,8 @@
1395
  score++;
1396
  } else {
1397
  button.classList.add('wrong');
1398
- document.querySelector(`.option-button[onclick*="'${correctWord}'"]`).classList.add('correct');
 
1399
  }
1400
  updateGuessingScore();
1401
 
@@ -1406,7 +1382,8 @@
1406
  }
1407
 
1408
  function updateGuessingScore() {
1409
- document.getElementById('guessing-score').innerText = `النتيجة: ${score}`;
 
1410
  }
1411
 
1412
  // Shadow Game Logic
@@ -1432,6 +1409,8 @@
1432
  const topContainer = document.getElementById('shadow-game-top');
1433
  const bottomContainer = document.getElementById('shadow-game-bottom');
1434
 
 
 
1435
  gameData = shuffleArray([...shadowGameData]).slice(0, 4);
1436
  const shadows = shuffleArray([...gameData]);
1437
  const animals = shuffleArray([...gameData]);
@@ -1473,12 +1452,11 @@
1473
 
1474
  function handleDrop(e) {
1475
  e.preventDefault();
1476
- if (draggedItem && draggedItem.dataset.animal === e.target.closest('.shadow-box').dataset.animal) {
1477
- const shadowBox = e.target.closest('.shadow-box');
1478
-
1479
- shadowBox.innerHTML = `<img src="${draggedItem.style.backgroundImage.slice(5, -2)}" class="story-image">`;
1480
- shadowBox.style.border = 'none';
1481
- shadowBox.classList.add('matched-correctly');
1482
 
1483
  draggedItem.remove();
1484
  draggedItem = null;
@@ -1500,12 +1478,11 @@
1500
  }
1501
 
1502
  function setGame(game) {
1503
- currentPage = 'gamePage'; // This might be a placeholder, adjust as needed
1504
  currentGame = game;
1505
  renderPage();
1506
  }
1507
 
1508
- // Initial render
1509
  document.addEventListener('DOMContentLoaded', () => {
1510
  renderPage();
1511
  });
 
23
  align-items: center;
24
  padding: 0;
25
  touch-action: pan-x pan-y;
26
+ overflow-x: hidden;
27
  transition: background-color 0.5s ease;
28
  }
29
  .container {
 
289
  #game-board {
290
  display: grid;
291
  grid-template-columns: repeat(4, 1fr);
292
+ gap: 0.75rem;
293
  perspective: 1000px;
294
  width: 100%;
295
  justify-content: center;
 
297
 
298
  .game-card {
299
  width: 100%;
300
+ max-width: 90px;
301
  aspect-ratio: 1 / 1;
302
  background-color: #6C757D;
303
  border-radius: 0.75rem;
 
338
  background-position: center;
339
  }
340
  .game-card-back {
341
+ background-color: #263238;
342
  }
343
  #game-info {
344
  margin-top: 1rem;
 
446
  width: 100%;
447
  height: 100%;
448
  object-fit: contain;
449
+ filter: brightness(0);
450
  opacity: 0.4;
451
  }
452
  #shadow-game-bottom {
 
556
 
557
 
558
  <script>
 
559
  let currentPage = 'main';
560
  let currentGame = null;
561
 
 
562
  const themes = {
563
  'amurs': {
564
  bg: '#F0F4C3',
 
606
 
607
  function applyTheme(themeName) {
608
  const theme = themes[themeName];
 
 
 
609
  document.body.style.backgroundColor = theme.bg;
610
+ const header = document.querySelector('.header');
611
+ if (header) header.style.backgroundColor = theme.primary;
612
+ const sidebar = document.querySelector('.sidebar');
613
+ if (sidebar) sidebar.style.backgroundColor = theme.primary;
614
+
615
  const interactiveCards = document.querySelectorAll('.interactive-card');
616
  interactiveCards.forEach(card => card.style.backgroundColor = theme.primary);
617
 
 
645
  if (cardText) cardText.style.color = theme.primary;
646
  });
647
 
 
648
  const dynamicText = document.querySelectorAll('.text-2xl, .text-xl, .story-text');
649
  dynamicText.forEach(text => {
650
  text.style.color = theme.primary;
 
654
  if (messageBox) {
655
  messageBox.style.backgroundColor = theme.primary;
656
  }
 
 
 
657
  }
658
 
 
 
659
  // Data for different pages
660
  const tifinaghData = [
661
  { letter: 'ⴰ', word: 'ⴰⵎⴰⵏ', image: 'https://source.unsplash.com/400x400/?water', audio: 'audio/aman.mp3' },
 
845
 
846
  // Data for memory game images
847
  const memoryGameImages = [
848
+ 'https://source.unsplash.com/400x400/?cat',
849
+ 'https://source.unsplash.com/400x400/?dog',
850
+ 'https://source.unsplash.com/400x400/?lion',
851
+ 'https://source.unsplash.com/400x400/?elephant',
852
+ 'https://source.unsplash.com/400x400/?monkey',
853
+ 'https://source.unsplash.com/400x400/?giraffe',
854
+ 'https://source.unsplash.com/400x400/?tiger',
855
+ 'https://source.unsplash.com/400x400/?bear',
856
+ 'https://source.unsplash.com/400x400/?fish',
857
+ 'https://source.unsplash.com/400x400/?bird',
858
+ 'https://source.unsplash.com/400x400/?rabbit',
859
+ 'https://source.unsplash.com/400x400/?sheep'
860
  ];
861
 
862
  // Memory game levels with image pairs
 
863
  const memoryGameLevels = [
864
+ { pairs: 8, grid: 'repeat(4, 1fr)' },
865
+ { pairs: 10, grid: 'repeat(5, 1fr)' },
866
+ { pairs: 12, grid: 'repeat(6, 1fr)' }
867
  ];
868
 
869
  const guessingGameData = [
 
886
  { animal: 'سنجاب', image: 'https://source.unsplash.com/400x400/?squirrel', shadow: 'https://placehold.co/400x400/000000/000000?text=squirrel-shadow' },
887
  ];
888
 
 
 
 
889
  const colorsData = [
890
  { word: 'أحمر', color: '#EF5350', audio: 'audio/red.mp3' },
891
  { word: 'أزرق', color: '#42A5F5', audio: 'audio/blue.mp3' },
 
924
  return array;
925
  }
926
 
 
927
  function playSound(src) {
928
  const player = document.getElementById('sound-player');
929
  player.src = src;
930
+ player.play().catch(e => console.error("Error playing audio:", e));
931
  }
932
 
933
  function showMessage(htmlContent, duration = 2500) {
 
936
 
937
  msgContent.innerHTML = htmlContent;
938
 
 
939
  msgBox.style.display = 'block';
940
  setTimeout(() => {
941
  msgBox.classList.add('visible');
942
  }, 10);
943
 
 
944
  setTimeout(() => {
945
  msgBox.classList.remove('visible');
946
  setTimeout(() => {
947
  msgBox.style.display = 'none';
948
+ }, 500);
949
  }, duration);
950
  }
951
 
 
956
  <p>طالب بالمدرسة العليا للتربية والتكوين ببرشيد</p>
957
  <p>تخصص اللغة الأمازيغية</p>
958
  `;
959
+ showMessage(developerInfoHtml, 5000);
960
  }
961
 
 
962
  function showAboutInfo() {
963
  const aboutInfoHtml = `
964
  <div class="text-xl font-bold mb-4">حول التطبيق</div>
 
976
  showMessage(contactInfoHtml, 7000);
977
  }
978
 
 
979
  function goBack() {
980
  currentPage = 'main';
981
  currentGame = null;
982
  renderPage();
983
  }
984
 
 
985
  function openSidebar() {
986
  document.getElementById("sidebar").style.width = "250px";
987
  }
 
992
 
993
  function renderPage() {
994
  const appContainer = document.getElementById('app-container');
995
+ if (!appContainer) return; // Prevent errors if container is not found
996
+ appContainer.innerHTML = '';
997
 
998
  const header = createHeader();
999
  appContainer.appendChild(header);
 
1034
  renderShadowGame(appContainer);
1035
  }
1036
 
 
 
1037
  const savedTheme = localStorage.getItem('theme') || 'amurs';
1038
  applyTheme(savedTheme);
1039
  }
1040
 
 
1041
  function createHeader() {
1042
  const header = document.createElement('div');
1043
  header.className = 'header';
 
1061
  return header;
1062
  }
1063
 
 
1064
  function renderMainMenu(container) {
1065
  const mainContent = document.createElement('div');
1066
  mainContent.className = 'grid-container';
 
1105
  container.appendChild(mainContent);
1106
  }
1107
 
 
1108
  function renderTifinaghPage(container) {
1109
  const tifinaghGrid = document.createElement('div');
1110
  tifinaghGrid.className = 'grid-container';
 
1123
  container.appendChild(tifinaghGrid);
1124
  }
1125
 
 
1126
  function renderInteractivePage(container, data, title) {
1127
  const pageTitle = document.createElement('h2');
1128
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
 
1145
  container.appendChild(grid);
1146
  }
1147
 
 
1148
  function renderColorsPage(container) {
1149
  const pageTitle = document.createElement('h2');
1150
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
 
1165
  container.appendChild(grid);
1166
  }
1167
 
 
1168
  function renderStoriesPage(container) {
1169
  const pageTitle = document.createElement('h2');
1170
  pageTitle.className = 'text-2xl font-bold text-center my-4 text-[#263238]';
 
1183
  });
1184
  }
1185
 
 
1186
  function renderGameMenu(container) {
1187
  const gameMenu = document.createElement('div');
1188
  gameMenu.className = 'grid-container';
 
1200
  container.appendChild(gameMenu);
1201
  }
1202
 
 
1203
  let hasFlippedCard = false;
1204
  let lockBoard = false;
1205
  let firstCard, secondCard;
 
1231
  resetMemoryGameState();
1232
  const board = document.getElementById('game-board');
1233
  const info = document.getElementById('game-info');
1234
+ if (!board || !info) return;
1235
 
1236
  totalPairs = memoryGameLevels[currentLevel].pairs;
1237
  const shuffledImages = shuffleArray([...memoryGameImages].slice(0, totalPairs));
 
1282
  firstCard.classList.add('matched');
1283
  secondCard.classList.add('matched');
1284
  matchedPairs++;
1285
+ const matchedCount = document.getElementById('matched-count');
1286
+ if (matchedCount) matchedCount.innerText = matchedPairs;
1287
  if (matchedPairs === totalPairs) {
1288
  setTimeout(() => {
1289
  showMessage('تهانينا! لقد ربحت اللعبة!');
 
1337
 
1338
  function displayGuessingQuestion() {
1339
  const questionBox = document.getElementById('guessing-question');
1340
+ if (!questionBox) return;
1341
+
1342
  if (currentQuestionIndex >= guessingGameData.length) {
1343
  questionBox.innerHTML = `
1344
  <div class="text-2xl font-bold">انتهت اللعبة!</div>
 
1370
  score++;
1371
  } else {
1372
  button.classList.add('wrong');
1373
+ const correctButton = Array.from(options).find(btn => btn.innerText === correctWord);
1374
+ if (correctButton) correctButton.classList.add('correct');
1375
  }
1376
  updateGuessingScore();
1377
 
 
1382
  }
1383
 
1384
  function updateGuessingScore() {
1385
+ const scoreElement = document.getElementById('guessing-score');
1386
+ if (scoreElement) scoreElement.innerText = `النتيجة: ${score}`;
1387
  }
1388
 
1389
  // Shadow Game Logic
 
1409
  const topContainer = document.getElementById('shadow-game-top');
1410
  const bottomContainer = document.getElementById('shadow-game-bottom');
1411
 
1412
+ if (!topContainer || !bottomContainer) return;
1413
+
1414
  gameData = shuffleArray([...shadowGameData]).slice(0, 4);
1415
  const shadows = shuffleArray([...gameData]);
1416
  const animals = shuffleArray([...gameData]);
 
1452
 
1453
  function handleDrop(e) {
1454
  e.preventDefault();
1455
+ const targetElement = e.target.closest('.shadow-box');
1456
+ if (draggedItem && targetElement && draggedItem.dataset.animal === targetElement.dataset.animal) {
1457
+ targetElement.innerHTML = `<img src="${draggedItem.style.backgroundImage.slice(5, -2)}" class="story-image">`;
1458
+ targetElement.style.border = 'none';
1459
+ targetElement.classList.add('matched-correctly');
 
1460
 
1461
  draggedItem.remove();
1462
  draggedItem = null;
 
1478
  }
1479
 
1480
  function setGame(game) {
1481
+ currentPage = 'gamePage';
1482
  currentGame = game;
1483
  renderPage();
1484
  }
1485
 
 
1486
  document.addEventListener('DOMContentLoaded', () => {
1487
  renderPage();
1488
  });