@@ -52,46 +52,7 @@ function getProjectHTML(projectName) {
5252 }
5353}
5454
55- function initializeProject ( projectName ) {
56- //Prevent duplicate listeners+duplicate ui execution
57- //if same project is already active it will not re run init
58- if ( activeProject === projectName ) return ;
59-
60- activeProject = projectName ;
6155
62- const initializers = {
63- 'rock-paper-scissor' : initRockPaperScissor ,
64- 'dice-rolling' : initDiceRolling ,
65- 'coin-flip' : initCoinFlip ,
66- 'blackjack-21' : initBlackjack ,
67- 'number-guessing' : initNumberGuessing ,
68- 'hangman' : initHangman ,
69- 'flames' : initFlames ,
70- 'fibonacci' : initFibonacci ,
71- 'progression-recognizer' : initProgressionRecognizer ,
72- 'pascal-triangle' : initPascalTriangle ,
73- 'armstrong' : initArmstrong ,
74- 'calculator' : initCalculator ,
75- 'collatz' : initCollatz ,
76- 'prime-analyzer' : initPrimeAnalyzer ,
77- 'projectile-motion' : initProjectileMotion ,
78- 'coordinate-polar-transform' : initCoordinatePolarTransform ,
79- 'derivative-calculator' : initDerivativeCalculator ,
80- 'morse-code' : initMorseCode ,
81- 'tower-of-hanoi' : initTowerOfHanoi ,
82- 'number-converter' : initNumberConverter ,
83- 'typing-speed-tester' : initTypingSpeedTester ,
84- 'snake-game' : initSnakeGame ,
85- 'whack-a-mole' : initWhackaMole ,
86- 'password-forge' : initPasswordForge ,
87- '2048-game' : init2048Game , // Added explicit mapped hook definition binding reference
88- 'typing-speed-tester' : initTypingSpeedTester
89- } ;
90-
91- if ( initializers [ projectName ] ) {
92- initializers [ projectName ] ( ) ;
93- }
94- }
9556
9657// ============================================
9758// ROCK PAPER SCISSORS
@@ -1856,110 +1817,6 @@ function initFlames() {
18561817 ` ;
18571818 }
18581819
1859-
1860- function showSequence ( ) {
1861- isPlayingSequence = true ;
1862- disableButtons ( true ) ;
1863- displayContent . textContent = "Watch the sequence..." ;
1864-
1865- let i = 0 ;
1866- const playNextEmoji = ( ) => {
1867- if ( i < sequence . length ) {
1868- const emoji = sequence [ i ] ;
1869- const button = Array . from ( emojiButtons ) . find ( btn => btn . dataset . emoji === emoji ) ;
1870-
1871- if ( button ) {
1872- button . classList . add ( 'active' ) ;
1873- setTimeout ( ( ) => {
1874- button . classList . remove ( 'active' ) ;
1875- i ++ ;
1876- setTimeout ( playNextEmoji , 500 ) ;
1877- } , 600 ) ;
1878- }
1879- } else {
1880- isPlayingSequence = false ;
1881- disableButtons ( false ) ;
1882- userSequence = [ ] ;
1883- gameActive = true ;
1884- displayContent . textContent = "Your turn! Click the emojis..." ;
1885- instructionsDiv . textContent = `👆 Repeat the sequence (${ sequence . length } steps)` ;
1886- }
1887- } ;
1888-
1889- playNextEmoji ( ) ;
1890- }
1891-
1892- function startNewRound ( ) {
1893- const newEmoji = emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ;
1894- sequence . push ( newEmoji ) ;
1895- userSequence = [ ] ;
1896-
1897- sequenceLengthDisplay . textContent = sequence . length ;
1898- setTimeout ( showSequence , 500 ) ;
1899- }
1900-
1901- function handleEmojiClick ( emoji , button ) {
1902- if ( isPlayingSequence || ! gameActive ) return ;
1903-
1904- userSequence . push ( emoji ) ;
1905- button . classList . add ( 'active' ) ;
1906-
1907- setTimeout ( ( ) => {
1908- button . classList . remove ( 'active' ) ;
1909- } , 300 ) ;
1910-
1911- // Check if the emoji matches
1912- if ( userSequence [ userSequence . length - 1 ] !== sequence [ userSequence . length - 1 ] ) {
1913- gameOver ( ) ;
1914- return ;
1915- }
1916-
1917- // Check if the entire sequence is correct
1918- if ( userSequence . length === sequence . length ) {
1919- score += level * 10 ;
1920- scoreDisplay . textContent = score ;
1921- level ++ ;
1922- levelDisplay . textContent = level ;
1923-
1924- instructionsDiv . textContent = "✅ Correct! Get ready for the next round..." ;
1925- gameActive = false ;
1926- setTimeout ( startNewRound , 1500 ) ;
1927- }
1928- }
1929-
1930- function gameOver ( ) {
1931- gameActive = false ;
1932- disableButtons ( true ) ;
1933- instructionsDiv . textContent = `❌ Game Over! You reached Level ${ level } with Score: ${ score } ` ;
1934- displayContent . textContent = `Final Score: ${ score } ` ;
1935- startBtn . textContent = "▶️ PLAY AGAIN" ;
1936- }
1937-
1938- function resetGame ( ) {
1939- sequence = [ ] ;
1940- userSequence = [ ] ;
1941- score = 0 ;
1942- level = 1 ;
1943- gameActive = false ;
1944- isPlayingSequence = false ;
1945-
1946- scoreDisplay . textContent = '0' ;
1947- levelDisplay . textContent = '1' ;
1948- sequenceLengthDisplay . textContent = '0' ;
1949- instructionsDiv . textContent = "👇 Click START to begin the game!" ;
1950- displayContent . textContent = "Ready to test your memory?" ;
1951- startBtn . textContent = "▶️ START" ;
1952-
1953- disableButtons ( true ) ;
1954- }
1955-
1956- startBtn . addEventListener ( 'click' , ( ) => {
1957- resetGame ( ) ;
1958- gameActive = true ;
1959- instructionsDiv . textContent = "Watch the sequence..." ;
1960- startNewRound ( ) ;
1961- } ) ;
1962-
19631820 calculateBtn . addEventListener ( 'click' , calculateFlames ) ;
19641821 name1Input . addEventListener ( 'keypress' , ( e ) => {
19651822 if ( e . key === 'Enter' ) calculateFlames ( ) ;
@@ -3871,45 +3728,50 @@ function getProductivePetHTML() {
38713728
38723729
38733730function initializeProject ( projectName ) {
3731+ if ( activeProject === projectName ) return ;
3732+ activeProject = projectName ;
3733+
38743734 const initializers = {
3875- 'tic-tac-toe' : initTicTacToe ,
3876- 'rock-paper-scissor' : initRockPaperScissor ,
3877- 'dice-rolling' : initDiceRolling ,
3878- 'coin-flip' : initCoinFlip ,
3879- 'number-guessing' : initNumberGuessing ,
3880- 'hangman' : initHangman ,
3881- 'word-scramble' : initWordScramble ,
3882- 'flames' : initFlames ,
3883- 'dots-boxes' : initDotsBoxes ,
3884- 'emoji-memory' : initEmojiMemoryGame ,
3885- 'fibonacci' : initFibonacci ,
3886- 'progression-recognizer' : initProgressionRecognizer ,
3887- 'pascal-triangle' : initPascalTriangle ,
3888- 'armstrong' : initArmstrong ,
3889- 'calculator' : initCalculator ,
3890- 'collatz' : initCollatz ,
3891- 'prime-analyzer' : initPrimeAnalyzer ,
3892- 'projectile-motion' : initProjectileMotion ,
3893- 'coordinate-polar-transform' : initCoordinatePolarTransform ,
3894- 'derivative-calculator' : initDerivativeCalculator ,
3895- 'morse-code' : initMorseCode ,
3896- 'tower-of-hanoi' : initTowerOfHanoi ,
3897- 'number-converter' : initNumberConverter ,
3898- 'typing-speed-tester' : initTypingSpeedTester ,
3899- 'snake-game' : initSnakeGame ,
3900- 'password-forge' : initPasswordForge , // Register Password Forge initializer
3901- 'spot-the-difference' : initSpotTheDifference ,
3902- 'whack-a-mole' : initWhackaMole ,
3903- 'flappy-game' : initFlappyGame ,
3904- 'productive-pet' : initProductivePet ,
3905- 'simon-says' : initSimonSays ,
3906- '2048-game' : init2048Game ,
3907- 'color-palette' : initColorPalette ,
3908- 'math-quiz' : initMathQuiz ,
3735+ 'tic-tac-toe' : 'initTicTacToe' ,
3736+ 'rock-paper-scissor' : 'initRockPaperScissor' ,
3737+ 'dice-rolling' : 'initDiceRolling' ,
3738+ 'coin-flip' : 'initCoinFlip' ,
3739+ 'blackjack-21' : 'initBlackjack' ,
3740+ 'number-guessing' : 'initNumberGuessing' ,
3741+ 'hangman' : 'initHangman' ,
3742+ 'word-scramble' : 'initWordScramble' ,
3743+ 'flames' : 'initFlames' ,
3744+ 'dots-boxes' : 'initDotsBoxes' ,
3745+ 'emoji-memory' : 'initEmojiMemoryGame' ,
3746+ 'fibonacci' : 'initFibonacci' ,
3747+ 'progression-recognizer' : 'initProgressionRecognizer' ,
3748+ 'pascal-triangle' : 'initPascalTriangle' ,
3749+ 'armstrong' : 'initArmstrong' ,
3750+ 'calculator' : 'initCalculator' ,
3751+ 'collatz' : 'initCollatz' ,
3752+ 'prime-analyzer' : 'initPrimeAnalyzer' ,
3753+ 'projectile-motion' : 'initProjectileMotion' ,
3754+ 'coordinate-polar-transform' : 'initCoordinatePolarTransform' ,
3755+ 'derivative-calculator' : 'initDerivativeCalculator' ,
3756+ 'morse-code' : 'initMorseCode' ,
3757+ 'tower-of-hanoi' : 'initTowerOfHanoi' ,
3758+ 'number-converter' : 'initNumberConverter' ,
3759+ 'typing-speed-tester' : 'initTypingSpeedTester' ,
3760+ 'snake-game' : 'initSnakeGame' ,
3761+ 'password-forge' : 'initPasswordForge' ,
3762+ 'spot-the-difference' : 'initSpotTheDifference' ,
3763+ 'whack-a-mole' : 'initWhackaMole' ,
3764+ 'flappy-game' : 'initFlappyGame' ,
3765+ 'productive-pet' : 'initProductivePet' ,
3766+ 'simon-says' : 'initSimonSays' ,
3767+ '2048-game' : 'init2048Game' ,
3768+ 'color-palette' : 'initColorPalette' ,
3769+ 'math-quiz' : 'initMathQuiz'
39093770 } ;
39103771
3911- if ( initializers [ projectName ] ) {
3912- initializers [ projectName ] ( ) ;
3772+ const initializerName = initializers [ projectName ] ;
3773+ if ( initializerName && typeof window [ initializerName ] === 'function' ) {
3774+ window [ initializerName ] ( ) ;
39133775 }
39143776}
39153777
0 commit comments