Hello -
I have been working on converting an old Simon game for use with Arduino. I have gotten it working pretty well. I am now working on game play. For my base Simon game code, I "re-purposed" and enhanced some code on the old Arduino forum. now that I have most of it working, I want to get the game to play as realistic as possible. One of the main discrepancies with the game play is when the player is inputting the sequence into the game.
In the current code, the player has unlimited time to choose the color (one of 4 inputs). I would like to put a time limit around the person's choice. So, if the player does not choose a input in 10 seconds, the game should fail (call the fail() sub routine). I can't seem to figure out how to work that into the code. Any advise would be great!
void input() { //Function for allowing user input and checking input against the generated array
for (int x=1; x <= turn;){ //Statement controlled by turn count
if (wrongguess == 'n') {
input1 = digitalRead(switch1);
input2 = digitalRead(switch2);
input3 = digitalRead(switch3);
input4 = digitalRead(switch4);
input5 = digitalRead(startbutton);
Serial.print(x);
if (input1 == HIGH){ //Checking for button push
digitalWrite(led1, HIGH);
enote();
delay(400);
digitalWrite(led1, LOW);
inputArray[x] = 1;
delay(50);
Serial.print(" ");
Serial.print(1);
if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against
wrongguess = 'y';
}
x++;
}
if (input2 == HIGH){
digitalWrite(led2, HIGH);
cnote();
delay(400);
digitalWrite(led2, LOW);
inputArray[x] = 2;
delay(50);
Serial.print(" ");
Serial.print(2);
if (inputArray[x] != randomArray[x]) {
wrongguess = 'y';
}
x++;
}
if (input3 == HIGH){
digitalWrite(led3, HIGH);
anote();
delay(400);
digitalWrite(led3, LOW);
inputArray[x] = 3;
delay(50);
Serial.print(" ");
Serial.print(3);
if (inputArray[x] != randomArray[x]) {
wrongguess = 'y';
}
x++;
}
if (input4 == HIGH){
digitalWrite(led4, HIGH);
lenote();
delay(400);
digitalWrite(led4, LOW);
inputArray[x] = 4;
delay(50);
Serial.print(" ");
Serial.print(4);
if (inputArray[x] != randomArray[x]) {
wrongguess = 'y';
}
x++;
}
if (input5 == HIGH && turn == 15){
secret = 'y';
}
}
if (secret =='y') { secretcache();}
if (wrongguess == 'y') { fail(); }
}
delay(700);
if (turn > highscore) { newhighscore = 'y';}
turn++; //Increments the turn count, also the last action before starting the output function over again
}