diff --git a/src/window.c b/src/window.c index 92ce76acb35482de817eafe3196e6e65b18f497b..6a6e7ddf084ef80ab5531be42f79c434c5432531 100644 --- a/src/window.c +++ b/src/window.c @@ -28,6 +28,10 @@ struct _GameWindow { int team_1; int team_2; } score; + struct { + bool team_1; + bool team_2; + } wrong; enum { RED, GREEN } colour; @@ -134,6 +138,37 @@ void game_window_button_press( GameWindow* window, int pin ) { } 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; } @@ -157,11 +192,18 @@ void game_window_button_press( GameWindow* window, int pin ) { digitalWrite( LED_R3, LOW ); digitalWrite( LED_G4, LOW ); digitalWrite( LED_R4, LOW ); + window->wrong.team_1 = false; + window->wrong.team_2 = false; window->state = WAIT; } else { fprintf( stderr, "wrong\n" ); + if ( window->score.team_1 > 0 && + !window->wrong.team_1 ) { + window->score.team_1--; + window->wrong.team_1 = true; + } } break; @@ -185,11 +227,18 @@ void game_window_button_press( GameWindow* window, int pin ) { digitalWrite( LED_R3, LOW ); digitalWrite( LED_G4, LOW ); digitalWrite( LED_R4, LOW ); + window->wrong.team_1 = false; + window->wrong.team_2 = false; window->state = WAIT; } else { fprintf( stderr, "wrong\n" ); + if ( window->score.team_2 > 0 && + !window->wrong.team_2 ) { + window->score.team_2--; + window->wrong.team_2 = true; + } } break;