Go Down

Topic: SIMON SAYS HELP (Read 377 times) previous topic - next topic

Dec 30, 2012, 02:05 am Last Edit: Dec 30, 2012, 04:28 am by Coding Badly Reason: 1
Hi i'm trying to make a simon says game.
I start out at level 1 starting with a sequence of 4, but the sequence keeps on repeating to not let the player have control
How can I fix this and how can I have more levels showing both on the display and on the LEDs?

Code: [Select]
#include <MeggyJrSimple.h>    // Required code, line 1 of 2.


struct Point // our name for the class
{
 int x; //x coordinates of this point
 int y; // y-coordinates of this point
};
//Point b1 = {0,4}; // Blue
//Point b2 = {0,3};
//Point b3 = {1,4};
//Point b4 = {1,3};
//Point b5 = {2,3};
//Point b6 = {2,4};
//Point g1 = {3,7}; //Green
//Point g2 = {3,6};
//Point g3 = {3,5};
//Point g4 = {4,7};
//Point g5 = {4,6};
//Point g6 = {4,5};
//Point r1 = {7,4}; //Red
//Point r2 = {7,3};
//Point r3 = {6,4};
//Point r4 = {6,3};
//Point r5 = {5,4};
//Point r6 = {5,3};
//Point y1 = {3,2}; //yellow
//Point y2 = {4,2};
//Point y3 = {4,1};
//Point y4 = {4,0};
//Point y5 = {3,1};
//Point y6 = {3,0};
//Point blueArray[6] = {b1,b2,b3,b4,b5,b6};
//Point greenArray[6] = {g1,g2,g3,g4,g5,g6};
//Point redArray[6] = {r1,r2,r3,r4,r5,r6};
//Point yellowArray[6] = {y1,y2,y3,y4,y5,y6}; //points that buttons starts as
//two arrays for combination sequence
int mode = 0;
int computerArray[7]; //total levels computer gives player to play
int playerArray[7]; //total levels player needs to complete
int playerMarker=0; //player
int computerMarker=4; //computer
int levels=1; //variable for levels
boolean correctSequence = true; //keeps track if sequence is completed

void setup()                   // run once, when the sketch starts
{
 MeggyJrSimpleSetup(); // Required code, line 2 of 2.
 Tone_Start(ToneC3, 100);  //Background Sound Start
 delay(100);
 Tone_Start(ToneCs3, 100);
 delay(100);
 Tone_Start(ToneD3, 100);
 delay(100);
 Tone_Start(ToneDs3, 100);
 delay(100);
 mode = 0;
 fillArray();
}

void loop()                     // run over and over again
{  
 if (mode == 0)
   AI();
 else if (mode == -1)
   Player();
 else
   lose();
   
  if(correctSequence == true)
    win();
   
 if (levels == 8)
 {
   SetAuxLEDs(255);
 }
 if (levels == 7)
 {
   SetAuxLEDs(127);
 }
 if (levels == 6)
 {
   SetAuxLEDs(63);
 }
 if (levels == 5)
 {
   SetAuxLEDs(31);
 }
 if (levels == 4)
 {
   SetAuxLEDs(15);
 }
 if (levels == 3)
 {
   SetAuxLEDs(7);
 }
 if (levels == 2)
 {
   SetAuxLEDs(3);
 }
 if (levels == 1)
 {
   SetAuxLEDs(1);
 }
 if (levels == 0)
 {
   SetAuxLEDs(0);
 }
}
 
 
void AI()
{
 for (int i = 0; i < computerMarker; i++)
 {
   if (computerArray[i] == 1)
     DrawRed();
   else if (computerArray[i] == 2)
     DrawGreen();
   else if (computerArray[i] == 3)
     DrawYellow();
   else if (computerArray[i] == 4)
     DrawBlue();
   
   DisplaySlate(); //displays the entire slate for current level

   delay(150); //is delayed 200 miliseconds

   ClearSlate(); //clears the entire slate for next level
   
   DisplaySlate();
   
   delay(150);
 }
 
 DisplaySlate();
 mode = 1;
}
 
void Player()
{
      //Check to see which buttons are down that weren't before.
  while(playerMarker < computerMarker)
 {
   CheckButtonsDown();
   if (Button_Up)                     //focuses on up button clicked
   {
     playerArray[playerMarker] = 2;  // add appropriate number to platyer arraay'
     playerMarker++;                  // add one to marker
     DrawGreen();                      //when marker exceeds 10, then check to see if it's correct.
     DisplaySlate ();
     Tone_Start(ToneA3,100);
     delay (150);
     ClearSlate();
     DisplaySlate();
   }
     
 
   if (Button_Down)
    {
     playerArray[playerMarker] = 3; //focuses on down button clicked
     playerMarker++;
     DrawYellow();
     DisplaySlate ();
     Tone_Start(ToneB3,100);
     delay (150);
     ClearSlate();
     DisplaySlate();
    }
 
 

    if (Button_Right)
    {
     playerArray[playerMarker] = 1; //focuses on right button clicked
     playerMarker++;
     DrawRed();
     DisplaySlate ();
     Tone_Start(ToneD3,100);
     delay (150);
     ClearSlate();
     DisplaySlate();
    }  
     
   

    if (Button_Left)
    {
      playerArray[playerMarker] = 4; //focuss on left button clicked
     playerMarker++;
     DrawBlue();
     DisplaySlate ();
     Tone_Start(ToneC3,100);
     delay (150);
     ClearSlate();
     DisplaySlate();
    }  
   
     
}
 
   
 }

void colors()
   {
     for (int i = 0; i<64; i++)
     {
       DrawBlue();
       DrawGreen();
       DrawRed();
       DrawYellow();
     }
   }

  void DrawGreen()
  {            
   DrawPx(3,6,Green);  //green shows
   DrawPx(3,7,Green);
   DrawPx(3,5,Green);
   DrawPx(4,7,Green);
   DrawPx(4,6,Green);
   DrawPx(4,5,Green);
  }

 void DrawRed()
  {
   DrawPx(7,4,Red); //Red shows
   DrawPx(7,3,Red);
   DrawPx(6,4,Red);
   DrawPx(6,3,Red);
   DrawPx(5,4,Red);
   DrawPx(5,3,Red);  
  }


 void DrawYellow()
  {
    DrawPx(3,2,Yellow); //yellow shows
    DrawPx(4,2,Yellow);
    DrawPx(4,1,Yellow);
    DrawPx(4,0,Yellow);
    DrawPx(3,1,Yellow);
    DrawPx(3,0,Yellow);
  }


 void DrawBlue()
  {
    DrawPx(0,4,Blue); // Blue shows
    DrawPx(0,3,Blue);
    DrawPx(1,4,Blue);
    DrawPx(1,3,Blue);
    DrawPx(2,3,Blue);
    DrawPx(2,4,Blue);
  }
 
 


void fillArray()
{
 for (int i = 0; i < 10; i++)
 {
  computerArray[i]=(int)random(4)+1;
  correctSequence = true;
  computerMarker++;
  playerMarker++;
 }
}

void win()
{
 Tone_Start(ToneD3, 100);
 mode = 0;
}

void lose()  //Function used if the player fails to match the sequence
{
 Tone_Start(ToneC3, 100);
 mode = -1; //Resets turn value so the game starts over without need for a reset button
}



Moderator edit: [code] [/code] tags added.

PeterH

In order for your code to display correctly you need to enclose it in [ code ] [ /code ] tags. I suggest you edit your post and add them.
I only provide help via the forum - please do not contact me for private consultancy.

patduino

Hi trollking,

In AI(), you set the mode to 1, but the if statement above looks for a -1 value.  Could that be it?

You should also add some meaningful comments. It's difficult for us to understand what you are doing otherwise.

Some things that are confusing include:

What is mode?
How does a player change the level?
What are the Aux LEDs?

Pat.
There are 10 types of people in the world, those that understand binary, and those that don't.

robtillaart


I implemented Simon some time ago, you might have a look at how I implemented levels. Note it was build with a specific shield as UI so you need to extract the core game ;)
- http://arduino.cc/forum/index.php/topic,54242.msg430406.html#msg430406 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy