1- #include "multiple_round.h"
1+ #include "./multiple_round.h"
2+
3+ // Function prototype declaration
4+ static inline void renderChooseGameMode (void );
25
36enum RoundStatus roundStatus [5 ] = {
47 ROUND_IDLE , ROUND_IDLE , ROUND_IDLE , ROUND_IDLE , ROUND_IDLE };
58
69int8_t roundEntered [5 ] = {0 };
710
11+
12+ enum GameplayMode playGameMode = CHOOSE_GAME ;
13+
14+ // Store the overflow state logo
815const uint8_t overflowLogo [6 ][5 ] = {
916 [0 ] = {0b10000111 , 0b10011101 , 0b11011101 , 0b10100101 , 0b11000111 },
1017 [1 ] = {0b10000010 , 0b10011110 , 0b11011010 , 0b10100010 , 0b11000111 },
@@ -13,6 +20,129 @@ const uint8_t overflowLogo[6][5] = {
1320 [4 ] = {0b10000011 , 0b10011101 , 0b11011111 , 0b10100001 , 0b11000001 },
1421 [5 ] = {0b10000111 , 0b10011100 , 0b11011111 , 0b10100001 , 0b11000110 }};
1522
23+ // Store the gameplay screen here
24+ static const char * screenPattern [8 ] = {
25+ "12120330" ,
26+ "21213333" ,
27+ "12123333" ,
28+ "21210330" ,
29+ "00000000" ,
30+ "02200330" ,
31+ "22223333" ,
32+ "00000000"
33+ };
34+
35+ uint16_t chooseGamemodeScreen [7 ] = {0 };
36+
37+ void chooseGameMode (void ) {
38+ // Will stay in this mode until user presses confirm button to choose the game mode
39+ bool chooseMode = false;
40+ // Reset the buttonPressed variable to be 0 first
41+ buttonPressed = 0 ;
42+ // Check if the enter has been pressed or not
43+ ChooseEnterPressed enterPressed = CHOOSE_GAME_NOT_ENTERED ;
44+
45+ // Print the emulator screen for the first time for this function
46+ renderChooseGameMode ();
47+
48+ while (!chooseMode ){
49+ // Activate keyboard I, J, K, L press input
50+ checkMoveButton ();
51+
52+ // Navigate pointers
53+ if (BTN_JUST_PRESSED (BTN_UP )) {
54+ currentposition = (NUM_LEDS + currentposition + 8 ) % NUM_LEDS ;
55+ buttonPressed = 1 ;
56+ }
57+ if (BTN_JUST_PRESSED (BTN_DOWN )) {
58+ currentposition = (NUM_LEDS + currentposition - 8 ) % NUM_LEDS ;
59+ buttonPressed = 1 ;
60+ }
61+ if (BTN_JUST_PRESSED (BTN_LEFT )) {
62+ currentposition = (NUM_LEDS + currentposition + 1 ) % NUM_LEDS ;
63+ buttonPressed = 1 ;
64+ }
65+ if (BTN_JUST_PRESSED (BTN_RIGHT )) {
66+ currentposition = (NUM_LEDS + currentposition - 1 ) % NUM_LEDS ;
67+ buttonPressed = 1 ;
68+ }
69+ if (BTN_JUST_PRESSED (Enter_Key )) {
70+ enterPressed = CHOOSE_GAME_ENTERED ;
71+ }
72+
73+ // Compute which row and col your pointer is in now
74+ uint8_t row = currentposition / GRID_COLS ;
75+ uint8_t col = currentposition % GRID_COLS ;
76+ uint8_t ledIndex = row * VERTICAL_BUTTONS + col ;
77+
78+ // Update to compare button released and pressed state
79+ updateMoveButton ();
80+
81+ if (buttonPressed == 1 ){
82+ renderChooseGameMode ();
83+ // Reset state
84+ buttonPressed = 0 ;
85+ }
86+
87+ if (enterPressed == CHOOSE_GAME_ENTERED ){
88+ // If user has pressed the confirm button, then choose the game mode
89+ if ((ledIndex >= 8 && ledIndex <= 11 ) || ledIndex == 17 || ledIndex == 18 ){
90+ playGameMode = ADDITION_GAME ;
91+ chooseMode = true;
92+ }
93+ else if ((ledIndex >= 12 && ledIndex <= 15 ) || ledIndex == 21 || ledIndex == 22 ){
94+ playGameMode = BINARY_GAME ;
95+ chooseMode = true;
96+ }
97+
98+ // Reset back
99+ enterPressed = CHOOSE_GAME_NOT_ENTERED ;
100+ }
101+
102+ }
103+
104+ //Reset values
105+ buttonPressed = 0 ;
106+ enterPressed = CHOOSE_GAME_NOT_ENTERED ;
107+ }
108+
109+ static inline void renderChooseGameMode (void ) {
110+ // Clear the screen first
111+ fill_color (offColor );
112+ // Render the game mode selection screen
113+ for (uint8_t arrayRow = 0 ; arrayRow <= 7 ; arrayRow ++ ) {
114+ int8_t ledRow = 7 - arrayRow ; // top (7) down to row 3
115+ for (uint8_t arrayCol = 0 ; arrayCol < 8 ; arrayCol ++ ) {
116+ int ledCol = 7 - arrayCol ;
117+ int idx = ledRow * 8 + ledCol ;
118+ // '0'-'3' as ASCII characters need to be converted to actual
119+ // numbers 0-3. Subtracting the character '0' does this:
120+ // e.g. '2' - '0' = 50 - 48 = 2
121+ uint8_t state = screenPattern [arrayRow ][arrayCol ] - '0' ;
122+ switch (state ){
123+ case 0 :
124+ setColorLEDScaled (idx , offColor , brightnessDivisor );
125+ break ;
126+ case 1 :
127+ setColorLEDScaled (idx , onColorBlue , brightnessDivisor );
128+ break ;
129+ case 2 :
130+ setColorLEDScaled (idx , cyanColor , brightnessDivisor );
131+ break ;
132+ case 3 :
133+ setColorLEDScaled (idx , solidColorRed , brightnessDivisor );
134+ break ;
135+ }
136+ }
137+ }
138+
139+ // Draw pointer ON TOP visually (only effect led_array), doesn't touch
140+ set_color (currentposition , pointerColor );
141+
142+ // Print the emulator screen
143+ WS2812BSimpleSend (LED_PINS , (uint8_t * )led_array , NUM_LEDS * 3 );
144+ }
145+
16146void renderGameRounds (void ) {
17147 for (int8_t col = 4 ; col >= 0 ; col -- ) {
18148 // flip to match physical LED ordering
@@ -56,7 +186,7 @@ void handleGameRounds(bool answerCorrect, uint8_t roundIndex) {
56186 currentGame = BINARY_GAME_CONTINUE ;
57187 }
58188 else if (currentPage == ADDITION_GAME ) {
59- currentGame = ADDITION_GAME_CONTINUE ;
189+ currentAddGame = ADDITION_GAME_CONTINUE ;
60190 }
61191 setColorLEDScaled (roundIndex , orangeColor , brightnessDivisor );
62192 printf ("I got correct answer the 1st time in round %d.\n" , roundIndex );
@@ -84,7 +214,7 @@ void handleGameRounds(bool answerCorrect, uint8_t roundIndex) {
84214 currentGame = BINARY_GAME_CONTINUE ;
85215 }
86216 else if (currentPage == ADDITION_GAME ) {
87- currentGame = ADDITION_GAME_CONTINUE ;
217+ currentAddGame = ADDITION_GAME_CONTINUE ;
88218 }
89219 break ;
90220 case false:
0 commit comments