Simon Game - How do I show which colors the computer has selected again when a new round starts

Hi all,

I’ve been working on the Simon Game for a while and I finally have some bare bones code that allows me to generate the list and have a human player try to match it. I’m running into a problem though - after the human successfully completes a round, the game should show every color in the array before adding the next color. I cannot figure out how to implement this. I’ve tried using a couple of different loops but none of it seems to work. If you could look at my code and help me out I would greatly appreciate it.

http://codepen.io/jv88899/pen/JbYrYG

Why? Why not just add a new color onto the array before starting playback?

That’s a fair question… I guess I had it in my head to show the colors before adding on, but I can see that it would be easier to do what you said.

The thing I’m running into is that I don’t know how to make it so that the colors show after each other, instead of at the same time. I’ve updated my code based on what your suggestion made me think of. It still doesn’t work quite right - it shows colors at the same time instead of waiting and after the first couple of selections it starts showing the newest color first.

If you (or anyone else) have any suggestions, I would appreciate it.

http://codepen.io/jv88899/pen/JbYrYG

This is what I did, but I haven’t seen anyone do it the same way.

  1. Have an array of colors, this is the easy part.
  2. Have a function that outputs the pattern. I used the the setInterval function so every 1000ms or so it would count++ and execute the next piece of the array. At the end of the array, the setinterval function is killed.
1 Like

Thank you so much! I have no idea why, but your comment just made something click in my head and I knew exactly what to do. It is working now! Thank you thank you thank you!

1 Like

Thats awesome. I didn’t actually tell you much, so good job :slight_smile: