Skip to content
Snippets Groups Projects
Commit a14cb16c authored by tag2y19's avatar tag2y19
Browse files

Minus points for wrong buttons!

Pressing the wrong button or pressing a button before the light comes on
gets you -1 point.  Capped to -1 per round, because I'm nice.
parent f39b44c3
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,10 @@ struct _GameWindow { ...@@ -28,6 +28,10 @@ struct _GameWindow {
int team_1; int team_1;
int team_2; int team_2;
} score; } score;
struct {
bool team_1;
bool team_2;
} wrong;
enum { RED, GREEN } colour; enum { RED, GREEN } colour;
...@@ -134,6 +138,37 @@ void game_window_button_press( GameWindow* window, int pin ) { ...@@ -134,6 +138,37 @@ void game_window_button_press( GameWindow* window, int pin ) {
} }
case WAIT: { case WAIT: {
switch ( pin ) {
case BUTTON_G1:
case BUTTON_R1: {
if ( window->score.team_1 > 0 &&
!window->wrong.team_1 ) {
window->score.team_1--;
window->wrong.team_1 = true;
}
break;
}
case BUTTON_G2:
case BUTTON_R2: {
if ( window->score.team_2 > 0 &&
!window->wrong.team_2 ) {
window->score.team_2--;
window->wrong.team_2 = true;
}
break;
}
}
break; break;
} }
...@@ -157,11 +192,18 @@ void game_window_button_press( GameWindow* window, int pin ) { ...@@ -157,11 +192,18 @@ void game_window_button_press( GameWindow* window, int pin ) {
digitalWrite( LED_R3, LOW ); digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW ); digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW ); digitalWrite( LED_R4, LOW );
window->wrong.team_1 = false;
window->wrong.team_2 = false;
window->state = WAIT; window->state = WAIT;
} else { } else {
fprintf( stderr, "wrong\n" ); fprintf( stderr, "wrong\n" );
if ( window->score.team_1 > 0 &&
!window->wrong.team_1 ) {
window->score.team_1--;
window->wrong.team_1 = true;
}
} }
break; break;
...@@ -185,11 +227,18 @@ void game_window_button_press( GameWindow* window, int pin ) { ...@@ -185,11 +227,18 @@ void game_window_button_press( GameWindow* window, int pin ) {
digitalWrite( LED_R3, LOW ); digitalWrite( LED_R3, LOW );
digitalWrite( LED_G4, LOW ); digitalWrite( LED_G4, LOW );
digitalWrite( LED_R4, LOW ); digitalWrite( LED_R4, LOW );
window->wrong.team_1 = false;
window->wrong.team_2 = false;
window->state = WAIT; window->state = WAIT;
} else { } else {
fprintf( stderr, "wrong\n" ); fprintf( stderr, "wrong\n" );
if ( window->score.team_2 > 0 &&
!window->wrong.team_2 ) {
window->score.team_2--;
window->wrong.team_2 = true;
}
} }
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment