Simon Game - Help Please

Simon Game -

  • I created an objected with stores the function of the computer function for changing colors and audio
  • I created Player moves and function for color and audio
  • I create two SEPARATE arrays which store the moves of the Computer and Player

Can someone provide guidance on the timing intervals for pausing to waiting for the Player moves and then to compare the moves of the computer and Player…

Thanks

Hmmm… I think the question is a bit open ended, and without completely dissecting your code, this might be the best I can offer (keeping in mind there are likely several solutions to this problem):

  1. Create a function that randomly pushes a new color to an array every time a turn advances (computer’s moves), then display pattern.
  • Create a click function that pushes the color of a users button push to a separate array, and within and at the end of that function, call another function that compares the two arrays to make sure they match. You can start with a base comparison of length - if the 2 arrays have different lengths, then the user did not press the right number of buttons and there is no reason to compare further. Then you can probably use a loop to compare the individual elements assuming the lengths match.
  1. If the patterns do match, trigger the function described in step 1 again to add a new color the the computer’s array, and display, then repeat.

To wait the right amount of time between a computer’s button pushes, you can use something like setTimeout(), which you can also use in some fashion to “timeout” a users turn if they wait to long to push a button.

I hope this helps in some way, but the best approach I think is to always exhaustively use Read and Search to the best of your ability before asking (if you haven’t already). So instead of searching for the solution specifically for a Simon game, try to break down the individual problem you are having and see if you can find a solution for that, which might be apply to someone else’s problem in a completely different way… there are answers out there to just about everything!

Good luck and happy coding!

I had my Simon game evaluate the two arrays (player and computer) every time the player clicked a game pad. All it needs to evaluate is playerArray.length -1 vs the corresponding index number in the computer array. If the playerArray and the computerArray are ever equal length, the game moves on to the next turn.

Thanks for the tip … I will try that…

thank you for taking the time to write and sharing your thoughts…

@slocodemonkey - but if all you are checking is that the lengths of the arrays match, how would you know when the player enters an incorrect combination of buttons?

I’m not checking the length of the arrays, I’m checking the last entry in the player’s array, and then comparing that to the corresponding index number of the computer’s array.

var computerArray = ['yellow','blue','red'];
var playerArray = ['yellow'];

Then, player presses the blue button. I push that to the playerArray and compare like so:

var length = playerArray.length -1 
if(computerArray[length] === playerArray[length]){
***keep going***} else{
**lose**}

@slocodemonkey - ahhh, ok. I misunderstood. So you’re running that check after every button push, not just at the end of a turn. Makes more sense now.

thanks camper fro your help…

Appears to be working after some work…

appreciate it…