From a14cb16c6369e1609dd314a614139cbd803348ff Mon Sep 17 00:00:00 2001
From: Tom Greig <tag2y19@soton.ac.uk>
Date: Mon, 17 Mar 2025 09:00:44 +0000
Subject: [PATCH] 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.
---
 src/window.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/window.c b/src/window.c
index 92ce76a..6a6e7dd 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;
-- 
GitLab