11// Project Registry
22// Each project's HTML and logic lives in its own file under js/projects/
33
4+ //To Prevent duplicate intialisation
5+ let activeProject = null ;
6+
47function getProjectHTML ( projectName ) {
58 const projects = {
9+ 'rock-paper-scissor' : getRockPaperScissorHTML ( ) ,
10+ 'dice-rolling' : getDiceRollingHTML ( ) ,
11+ 'coin-flip' : getCoinFlipHTML ( ) ,
12+ 'number-guessing' : getNumberGuessingHTML ( ) ,
13+ 'hangman' : getHangmanHTML ( ) ,
14+ 'flames' : getFlamesHTML ( ) ,
15+ 'emoji-memory' : getEmojiMemoryGameHTML ( ) ,
16+ 'fibonacci' : getFibonacciHTML ( ) ,
17+ 'progression-recognizer' : getProgressionRecognizerHTML ( ) ,
18+ 'pascal-triangle' : getPascalTriangleHTML ( ) ,
19+ 'armstrong' : getArmstrongHTML ( ) ,
20+ 'calculator' : getCalculatorHTML ( ) ,
21+ 'collatz' : getCollatzHTML ( ) ,
22+ 'prime-analyzer' : getPrimeAnalyzerHTML ( ) ,
23+ 'projectile-motion' : getProjectileMotionHTML ( ) ,
24+ 'coordinate-polar-transform' : getCoordinatePolarTransformHTML ( ) ,
25+ 'derivative-calculator' : getDerivativeCalculatorHTML ( ) ,
26+ 'morse-code' : getMorseCodeHTML ( ) ,
27+ 'tower-of-hanoi' : getTowerOfHanoiHTML ( ) ,
28+ 'number-converter' : getNumberConverterHTML ( ) ,
29+ 'typing-speed-tester' : getTypingSpeedTesterHTML ( ) ,
30+ 'snake-game' : getsnakeGameHTML ( ) ,
31+ 'password-forge' : getPasswordForgeHTML ( ) ,
32+ 'whack-a-mole' : getWhackaMoleHTML ( ) ,
633 'tic-tac-toe' : ( ) => getTicTacToeHTML ( ) ,
734 'rock-paper-scissor' : ( ) => getRockPaperScissorHTML ( ) ,
835 'dice-rolling' : ( ) => getDiceRollingHTML ( ) ,
@@ -50,6 +77,12 @@ function getProjectHTML(projectName) {
5077}
5178
5279function initializeProject ( projectName ) {
80+ //Prevent duplicate listeners+duplicate ui execution
81+ //if same project is already active it will not re run init
82+ if ( activeProject === projectName ) return ;
83+
84+ activeProject = projectName ;
85+
5386 const initializers = {
5487 'rock-paper-scissor' : initRockPaperScissor ,
5588 'dice-rolling' : initDiceRolling ,
@@ -70,6 +103,11 @@ function initializeProject(projectName) {
70103 'derivative-calculator' : initDerivativeCalculator ,
71104 'morse-code' : initMorseCode ,
72105 'tower-of-hanoi' : initTowerOfHanoi ,
106+ 'number-converter' : initNumberConverter ,
107+ 'typing-speed-tester' : initTypingSpeedTester ,
108+ 'snake-game' : initSnakeGame ,
109+ 'whack-a-mole' : initWhackaMole ,
110+ 'password-forge' : initPasswordForge ,
73111 '2048-game' : init2048Game , // Added explicit mapped hook definition binding reference
74112 'typing-speed-tester' : initTypingSpeedTester
75113 } ;
@@ -1841,6 +1879,109 @@ function initFlames() {
18411879 </div>
18421880 ` ;
18431881 }
1882+
1883+
1884+ function showSequence ( ) {
1885+ isPlayingSequence = true ;
1886+ disableButtons ( true ) ;
1887+ displayContent . textContent = "Watch the sequence..." ;
1888+
1889+ let i = 0 ;
1890+ const playNextEmoji = ( ) => {
1891+ if ( i < sequence . length ) {
1892+ const emoji = sequence [ i ] ;
1893+ const button = Array . from ( emojiButtons ) . find ( btn => btn . dataset . emoji === emoji ) ;
1894+
1895+ if ( button ) {
1896+ button . classList . add ( 'active' ) ;
1897+ setTimeout ( ( ) => {
1898+ button . classList . remove ( 'active' ) ;
1899+ i ++ ;
1900+ setTimeout ( playNextEmoji , 500 ) ;
1901+ } , 600 ) ;
1902+ }
1903+ } else {
1904+ isPlayingSequence = false ;
1905+ disableButtons ( false ) ;
1906+ userSequence = [ ] ;
1907+ gameActive = true ;
1908+ displayContent . textContent = "Your turn! Click the emojis..." ;
1909+ instructionsDiv . textContent = `👆 Repeat the sequence (${ sequence . length } steps)` ;
1910+ }
1911+ } ;
1912+
1913+ playNextEmoji ( ) ;
1914+ }
1915+
1916+ function startNewRound ( ) {
1917+ const newEmoji = emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ;
1918+ sequence . push ( newEmoji ) ;
1919+ userSequence = [ ] ;
1920+
1921+ sequenceLengthDisplay . textContent = sequence . length ;
1922+ setTimeout ( showSequence , 500 ) ;
1923+ }
1924+
1925+ function handleEmojiClick ( emoji , button ) {
1926+ if ( isPlayingSequence || ! gameActive ) return ;
1927+
1928+ userSequence . push ( emoji ) ;
1929+ button . classList . add ( 'active' ) ;
1930+
1931+ setTimeout ( ( ) => {
1932+ button . classList . remove ( 'active' ) ;
1933+ } , 300 ) ;
1934+
1935+ // Check if the emoji matches
1936+ if ( userSequence [ userSequence . length - 1 ] !== sequence [ userSequence . length - 1 ] ) {
1937+ gameOver ( ) ;
1938+ return ;
1939+ }
1940+
1941+ // Check if the entire sequence is correct
1942+ if ( userSequence . length === sequence . length ) {
1943+ score += level * 10 ;
1944+ scoreDisplay . textContent = score ;
1945+ level ++ ;
1946+ levelDisplay . textContent = level ;
1947+
1948+ instructionsDiv . textContent = "✅ Correct! Get ready for the next round..." ;
1949+ gameActive = false ;
1950+ setTimeout ( startNewRound , 1500 ) ;
1951+ }
1952+ }
1953+
1954+ function gameOver ( ) {
1955+ gameActive = false ;
1956+ disableButtons ( true ) ;
1957+ instructionsDiv . textContent = `❌ Game Over! You reached Level ${ level } with Score: ${ score } ` ;
1958+ displayContent . textContent = `Final Score: ${ score } ` ;
1959+ startBtn . textContent = "▶️ PLAY AGAIN" ;
1960+ }
1961+
1962+ function resetGame ( ) {
1963+ sequence = [ ] ;
1964+ userSequence = [ ] ;
1965+ score = 0 ;
1966+ level = 1 ;
1967+ gameActive = false ;
1968+ isPlayingSequence = false ;
1969+
1970+ scoreDisplay . textContent = '0' ;
1971+ levelDisplay . textContent = '1' ;
1972+ sequenceLengthDisplay . textContent = '0' ;
1973+ instructionsDiv . textContent = "👇 Click START to begin the game!" ;
1974+ displayContent . textContent = "Ready to test your memory?" ;
1975+ startBtn . textContent = "▶️ START" ;
1976+
1977+ disableButtons ( true ) ;
1978+ }
1979+
1980+ startBtn . addEventListener ( 'click' , ( ) => {
1981+ resetGame ( ) ;
1982+ gameActive = true ;
1983+ instructionsDiv . textContent = "Watch the sequence..." ;
1984+ startNewRound ( ) ;
18441985
18451986 calculateBtn . addEventListener ( 'click' , calculateFlames ) ;
18461987 name1Input . addEventListener ( 'keypress' , ( e ) => {
@@ -1853,7 +1994,7 @@ function initFlames() {
18531994
18541995// ============================================
18551996// COLLATZ CONJECTURE
1856- // ============================================
1997+ // ===========================================
18571998function getCollatzHTML ( ) {
18581999 return `
18592000 <div class="project-content">
0 commit comments