I’ve been working on Simon for ages. Like seriously…maybe a year. It’s my only challenge left for front end cert, and with the new curriculum coming, I just want to get it finished before the whole thing changes again.
I redid my whole code base and am trying to use what i’ve learned since my last attempt to finish it to clean up code.
My current question is passing game play back adn forth between the computer and the player…this can’t be as simple as call the computer then call the player, it needs to be responsive right? When the computer is done…then the player can try…
Here’s my codepen…I’m not asking for the solution but just a tip on what others did. My first time around I was able to pass game play back and forth by calling playerTurn within the computer function and vice versa. not sure that’s a good strategy due to memory usage…although maybe it is the correct way to do it?
Currently the game is hardcoded at the 5th round, so it will start to play as soon as you run it. If that’s annoying you can just go in and change the hard coding.
Hi, check out this website, it has the code I used.
If you modify it to your specifications here’s what it should do:
You can have an array to store numbers representing each quadrant. So at level one the computer stores a number for the sound to be played, and then you loop through the array using the code in the website I’ve shared. When it loops through the whole array, it becomes your turn to play. To confirm your code works, you can disable the quadrants, then after all tunes are played, you enable them so the human can play. If the human gets everything right, the quadrants will be disabled again, a new sound will be added and the function will loop through the array again. So it will always start from the first sound.
I think you’ve got most of it down. You just need to figure out how to proceed to the next round(hint: use an array for the human’s tunes as well).
Great, thanks Ed, I’ll check it out! my first version “almost” worked but it seeemd easier to start over.
Just read it, and it’s similar to the strategy I found on Stack Overflow (oddly, not in the accepted or most popular answer)
For my version, I set a timeout after the computer played the sequence. If the player pushed a correct color, the timeout was cleared and a new one was set. At the end of the player’s turn (either successfully selected the correct colors, or failed to select a correct color), the timer was cleared and a function was called for the computer’s turn.
In terms of the sequence of play, I believe that I generated a random sequence at the start of the game and matched the player’s input to an element in the generated array. For instance, the first player input would be checked against the first item in the generated array and a counter for the player’s moves was incremented. When the player’s turn was over, the counter for the player’s moves would be reset, a counter for the round would be incremented (if player was successful), and a function for the computer’s turn would be called to play the sequence up to the current round number (actually the current round number -1, since arrays are 0 based).