Simple Simon Clone (everyone knows Simon right?)

Last post 04-22-2008, 11:41 AM by Sm4kt4rd. 7 replies.
Sort Posts: Previous Next
  •  04-21-2008, 1:46 PM

    Simple Simon Clone (everyone knows Simon right?)

    Hello all,

    I'm sorry I have to post this oh so probably way too noobish question here. When you have problems though, you have problems. Basically, I have had to set aside my old Tetris clone thing because I was having issues with trying to solve how to store things and such (long story, probably just means I need more practice).

    So, I decided I would start even more basic than that. Simon!! Everyone knows that right? (Link if you don't: http://en.wikipedia.org/wiki/Simon_%28game%29). Ok, I decided I would make a "class" to handle the playing surface, which is nothing more than 4 rectangles color coded to the four buttons on the Xbox gamepad. So, I managed that and here is what I did:

    http://pastebin.com/f1793649c

    Each of the squares created in that code is just a "dull" color. What I am stuck on is where to create the Intense colors for when the particular color is "playing" and where I should put the code creating a list and maintaining the order in which to play those notes.  Well, I guess I should also say, how should I switch between, computer is playing colors, or computer is waiting for user input to see if it matches previous colors played? If that makes any sense...

    I am putting this in Game Design because I can't decide, should I create another class that say handles "Hey my note (color) is playing)" and another class that handles switching between "Play the series of notes so far then switch to wait on the user".

    This should be something so simple, and I am probably trying to overcomplicate it (trust me, I make small ordeals complicated). Any help or tips would be appreciated! I would just like to actually be able to finish something I am trying to do as far as XNA goes, instead of starting and getting side tracked on something else, which leads to another side track.....

     

    Thanks,

     

    Shawn

    *Edit* - Maybe to make this a more general question, I guess I could just ask, what makes someone decide that "Hey, this would work better in a class by itself!". Reading all about things being too tightly coupled and such here lately has gotten me a bit confused maybe. But, storing the "hey im playing, not reading the controller right now" and switching over to "hey im waiting for your input", still confusing, and I guess that is state management....

  •  04-21-2008, 2:14 PM

    Re: Simple Simon Clone (everyone knows Simon right?)

    In a game like this everything is based on time. Each color area can be drawn in one of 2 colors. The question is that given the current time and the current game state which one do you choose.

    You will probably have an array of the colors to flash - lets call that sequence - and the time you started to play that sequence - start time - and the rate you are flashing the colors - rate.

    So if we know the current time then the current place in the sequence is

    currentSequencePosition = (int)((currentTime - startTime)/rate)

    use that index to look up the color in the array that should be in the bright position.

    When currentSequencePosition > sequence.Length then you know you have finished playing the sequence so you can switch in the player pressing the buttons rather than having the computer animate them

    Its hard to switch your mind from event driven programming where everything happens because the user did something into a game frame of mind where you do things because 'the time is now X'

     

     



    The ZBuffer - News and information for XNA and Managed DirectX
  •  04-21-2008, 2:21 PM

    Re: Simple Simon Clone (everyone knows Simon right?)

    What you could do is add a List<int> for the order that the buttons need to be pressed.

    At the beginning of the game, you could call a function that adds 1 button to the list

    button_sequence.Add(Random.Next(0,3));

    Then at the beginning of your turn, use a foreach on the loop to flash and play the sounds for the buttons

    ########### Edit:  This part won't work ###############
    foreach(int button in button_sequence)
    {
    switch(button)
    {
    case 0:
    //Flash button and play sound
    break;
    case 1:
    //Flash button and play sound
    break;
    case 2:
    //Flash button and play sound
    break;
    case 3:
    //Flash button and play sound
    break;
    default:
    //This should never come up. Maybe have an error message here just in case though.
    break;
    }
    }
    ##############################################
     
    Then, when it is done playing through, enable input from the player.
    What you could try doing is use a counter to know which place in the List that the player is on.  Each time the player presses a button, you could add one to the counter.  When it gets to the end, you disable the input again and go back to the start. (Add one to the list and flash the buttons).
     
    //Put this at the beginning of the program
    int button_counter = 0; //For which spot in the list to check

    //Put this in the update loop
    if (input_enabled && newState....Buttons.A.IsPressed && oldState....Buttons.A.IsReleased) //If the A Button was just pressed.
    {
    if (button_sequence[Counter] == 0)
    {
    button_counter++;
    }
    else
    {
    //Game over method and start over
    }
    }

    if (input_enabled && newState....Buttons.B.IsPressed && oldState....Buttons.B.IsReleased) //If the B Button was just pressed.
    {
    if(button_sequence[Counter] == 1)
    {
    button_counter++;
    }
    else
    {
    //Game over method and start over.
    }
    }
    //Do the same for the other two buttons.
    Don't forget though to reset the button counter at the beginning of each turn.
    Also, I forgot to add after the button_counter++ to check to see if it is at the end of the list.
    Just add an if statement to see if button_counter is equal to button_sequence.Count
  •  04-21-2008, 2:32 PM

    Re: Simple Simon Clone (everyone knows Simon right?)

    Actually that's exactly what you CAN'T do... you don't get to run a tight loop like that if you are running a typical game loop... often there are sound effects playing, background animations, checking for the pause/reset buttons/network packets. If you run a loop like that which should take a long time to run then none of that can happen.

    So you have to assume that you get once chance every 1/60th of a second to decide what to draw on the screen. The only variables you have to play with are the current time, the current state of the input devices and whatever state you have stored from the last frame.



    The ZBuffer - News and information for XNA and Managed DirectX
  •  04-21-2008, 2:36 PM

    Re: Simple Simon Clone (everyone knows Simon right?)

    Oh yeah you're right.  I forgot about the time between each beep...
    (Changed my original post a little bit)

    I think my last part though about checking the input should still work though.

  •  04-22-2008, 10:41 AM

    Re: Simple Simon Clone (everyone knows Simon right?)

    Sm4kt4rd:

    I guess I could just ask, what makes someone decide that "Hey, this would work better in a class by itself!". Reading all about things being too tightly coupled and such here lately has gotten me a bit confused maybe. But, storing the "hey im playing, not reading the controller right now" and switching over to "hey im waiting for your input", still confusing, and I guess that is state management....



    The simplier way to do what you want is by storing a game state variable which indicates whether the CPU is playing or waiting for input. Let's say the variable is called State (original... ;-) and is of type StateType, which is an enum with at least 2 values: Playing and WaitingForInput (or whatever name you want). Then, your game simply must check that variable on each frame and, each time a predefined period has elapsed (for example, 200 ms) execute the, say, the PlayColor() method (CPU turn) or the ReadColor() one (user turn). The variable must flip its value each time a numer of steps have been done. For example, if you are starting and the sequence to play is 4 steps length, then the user turn must change when the user presses a correct button 4 times. If he fails, then his turn ends also. The CPU turn finishes when it has played all the colors of the current sequence (which is incremented while the user goes right).

    Other way to do the same is by using the State Design Pattern.
  •  04-22-2008, 10:54 AM

    Re: Simple Simon Clone (everyone knows Simon right?)

    Sm4kt4rd:

    *Edit* - Maybe to make this a more general question, I guess I could just ask, what makes someone decide that "Hey, this would work better in a class by itself!". Reading all about things being too tightly coupled and such here lately has gotten me a bit confused maybe. But, storing the "hey im playing, not reading the controller right now" and switching over to "hey im waiting for your input", still confusing, and I guess that is state management....

    What to make an object and 'how to I draw things based on state' are not really all that related.

    In general you want to make objects as things you can think about existing... so candidates for your game would be the 'gameboard', the buttons on that board, the sequence of lights to flash. Notice I say candidates - you don't HAVE to have a class for everything. Its a common mistake when moving to OO to go too far. It all depends on the game.

     



    The ZBuffer - News and information for XNA and Managed DirectX
  •  04-22-2008, 11:41 AM

    Re: Simple Simon Clone (everyone knows Simon right?)

    It is very strange that I understand what you guys are saying, but at the same time still feel a little confused. I guess at the moment I am still trying to over complicate things in my head, and should instead sit down and get some more coding done and see what I can accomplish.

    Thanks for the input and insight!

    Shawn

View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback