@@ -71,16 +71,17 @@ void playGame() {
7171 int  choice;
7272 int  onTime = 500 , offTime = 300 ;
7373 int  timeDecrease = 25 ;
74-  bool  rightAnswer =  true ;
74+  bool  rightAnswer;
7575
7676 Node x;
7777 List gameSequence = newList ();
7878 generateRandomSequence (gameSequence);
7979 while  (lives > 0 ) {
80+  rightAnswer = true ;
8081 playSequence (gameSequence, onTime, offTime);
8182 x = getListHead (gameSequence);
8283 while  (x != NULL  && rightAnswer) {
83-  // waits  for input
84+  // Waits  for input
8485 choice = -1 ;
8586 while  (choice == -1 ) {
8687 choice = checkInputArray (buttons, N_LEDS);
@@ -93,6 +94,7 @@ void playGame() {
9394 rightAnswer = false ;
9495 }
9596 }
97+ 9698 if  (rightAnswer) {
9799 score++;
98100 displayRightAnswer (score);
@@ -143,27 +145,6 @@ void playLED(int index, int onTime) {
143145 digitalWrite (leds[index], LOW);
144146}
145147
146- // Returns the pin number of an input that was set to HIGH in the inputs array.
147- // If all were set to LOW, returns -1.
148- int  checkInputArray (int  inputs[], int  len) {
149-  for  (int  i = 0 ; i < len; i++) {
150-  if  (digitalRead (inputs[i]) == HIGH) {
151-  return  inputs[i];
152-  }
153-  }
154-  return  -1 ;
155- }
156- 157- // Returns the index of the pin pinNumber in the inputs array.
158- int  pinToIndex (int  inputs[], int  len, int  pinNumber) {
159-  for  (int  i = 0 ; i < len; i++) {
160-  if  (inputs[i] == pinNumber) {
161-  return  i;
162-  }
163-  }
164-  return  -1 ;
165- }
166- 167148// Plays the animation for when the answer is wrong. Turns of one LED.
168149void  displayWrongAnswer (int  lives) {
169150 Serial.println (" Wrong answer!"  );
@@ -195,23 +176,5 @@ void displayGameOver(int score) {
195176 gameSetup ();
196177}
197178
198- // Outputs value to all pins in the outputs array.
199- void  outputArray (int  outputs[], int  len, int  value) {
200-  for  (int  i = 0 ; i < len; i++) {
201-  digitalWrite (outputs[i], value);
202-  }
203- }
204- 205- // Writes HIGH for each pin in sequence and then LOW (following the order of the array).
206- // Each steps lasts stepDelay ms.
207- void  outputArraySequence (int  sequence[], int  len, float  loops, int  stepDelay) {
208-  for  (int  i = 0 ; i < len*loops; i++) {
209-  digitalWrite (sequence[i%len], HIGH);
210-  delay (stepDelay);
211-  digitalWrite (sequence[i%len], LOW);
212-  delay (stepDelay); 
213-  }
214- }
215- 216179// Nothing here
217180void  loop () {}
0 commit comments