@@ -1183,6 +1183,110 @@ function initFlames() {
11831183 ` ;
11841184 }
11851185
1186+
1187+ function showSequence ( ) {
1188+ isPlayingSequence = true ;
1189+ disableButtons ( true ) ;
1190+ displayContent . textContent = "Watch the sequence..." ;
1191+
1192+ let i = 0 ;
1193+ const playNextEmoji = ( ) => {
1194+ if ( i < sequence . length ) {
1195+ const emoji = sequence [ i ] ;
1196+ const button = Array . from ( emojiButtons ) . find ( btn => btn . dataset . emoji === emoji ) ;
1197+
1198+ if ( button ) {
1199+ button . classList . add ( 'active' ) ;
1200+ setTimeout ( ( ) => {
1201+ button . classList . remove ( 'active' ) ;
1202+ i ++ ;
1203+ setTimeout ( playNextEmoji , 500 ) ;
1204+ } , 600 ) ;
1205+ }
1206+ } else {
1207+ isPlayingSequence = false ;
1208+ disableButtons ( false ) ;
1209+ userSequence = [ ] ;
1210+ gameActive = true ;
1211+ displayContent . textContent = "Your turn! Click the emojis..." ;
1212+ instructionsDiv . textContent = `👆 Repeat the sequence (${ sequence . length } steps)` ;
1213+ }
1214+ } ;
1215+
1216+ playNextEmoji ( ) ;
1217+ }
1218+
1219+ function startNewRound ( ) {
1220+ const newEmoji = emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ;
1221+ sequence . push ( newEmoji ) ;
1222+ userSequence = [ ] ;
1223+
1224+ sequenceLengthDisplay . textContent = sequence . length ;
1225+ setTimeout ( showSequence , 500 ) ;
1226+ }
1227+
1228+ function handleEmojiClick ( emoji , button ) {
1229+ if ( isPlayingSequence || ! gameActive ) return ;
1230+
1231+ userSequence . push ( emoji ) ;
1232+ button . classList . add ( 'active' ) ;
1233+
1234+ setTimeout ( ( ) => {
1235+ button . classList . remove ( 'active' ) ;
1236+ } , 300 ) ;
1237+
1238+ // Check if the emoji matches
1239+ if ( userSequence [ userSequence . length - 1 ] !== sequence [ userSequence . length - 1 ] ) {
1240+ gameOver ( ) ;
1241+ return ;
1242+ }
1243+
1244+ // Check if the entire sequence is correct
1245+ if ( userSequence . length === sequence . length ) {
1246+ score += level * 10 ;
1247+ scoreDisplay . textContent = score ;
1248+ level ++ ;
1249+ levelDisplay . textContent = level ;
1250+
1251+ instructionsDiv . textContent = "✅ Correct! Get ready for the next round..." ;
1252+ gameActive = false ;
1253+ setTimeout ( startNewRound , 1500 ) ;
1254+ }
1255+ }
1256+
1257+ function gameOver ( ) {
1258+ gameActive = false ;
1259+ disableButtons ( true ) ;
1260+ instructionsDiv . textContent = `❌ Game Over! You reached Level ${ level } with Score: ${ score } ` ;
1261+ displayContent . textContent = `Final Score: ${ score } ` ;
1262+ startBtn . textContent = "▶️ PLAY AGAIN" ;
1263+ }
1264+
1265+ function resetGame ( ) {
1266+ sequence = [ ] ;
1267+ userSequence = [ ] ;
1268+ score = 0 ;
1269+ level = 1 ;
1270+ gameActive = false ;
1271+ isPlayingSequence = false ;
1272+
1273+ scoreDisplay . textContent = '0' ;
1274+ levelDisplay . textContent = '1' ;
1275+ sequenceLengthDisplay . textContent = '0' ;
1276+ instructionsDiv . textContent = "👇 Click START to begin the game!" ;
1277+ displayContent . textContent = "Ready to test your memory?" ;
1278+ startBtn . textContent = "▶️ START" ;
1279+
1280+ disableButtons ( true ) ;
1281+ }
1282+
1283+ startBtn . addEventListener ( 'click' , ( ) => {
1284+ resetGame ( ) ;
1285+ gameActive = true ;
1286+ instructionsDiv . textContent = "Watch the sequence..." ;
1287+ startNewRound ( ) ;
1288+ } ) ;
1289+
11861290 calculateBtn . addEventListener ( 'click' , calculateFlames ) ;
11871291 name1Input . addEventListener ( 'keypress' , ( e ) => {
11881292 if ( e . key === 'Enter' ) calculateFlames ( ) ;
0 commit comments