multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
29:4708bfb863cb
Parent:
28:a26a43cdaea8
Child:
30:59e9a5409e65
--- a/gamestate.cpp	Mon Nov 23 01:26:24 2020 +0000
+++ b/gamestate.cpp	Sat Nov 28 01:05:42 2020 +0000
@@ -10,6 +10,7 @@
     this->p2_loc = playerTwoLocation; 
     this->ball_loc = ballLocation; 
     this->has_started = 0; 
+    this->countdown = 0; 
     this->is_done = 0; 
     this->score[0] = 0; 
     this->score[1] = 0; 
@@ -35,13 +36,20 @@
         }
         gfx->renderWaitingRoom(); 
     } else if (typeResponse == "gameState") {
-        if (!has_started) {
-            has_started = 1; 
-            printf("reseting display\n\r");
-            gfx->reset(); 
+        MbedJSONValue &serverGameState = (*serverResponse)["gameState"];
+        if (!has_started && serverGameState.hasMember("countdown")) {
+            int countdownValue = (serverGameState)["countdown"].get<int>();
+            if (countdownValue > 0) {
+                countdown = countdownValue; 
+                return; 
+            } else {
+                has_started = 1; 
+                printf("reseting display\n\r");
+                gfx->reset(); 
+            }
         }
         gfx->eraseGameState(this); 
-        MbedJSONValue &serverGameState = (*serverResponse)["gameState"];
+        
         if (serverGameState.hasMember("playerOnePos")) {
             this->p1_loc.x = (serverGameState)["playerOnePos"].get<int>();       
         }
@@ -87,6 +95,14 @@
     return this->localPlayerNum; 
 } 
 
+char GameState::getCountdown() {
+    return this->countdown; 
+}
+
+void GameState::setCountdown(int val) {
+    this->countdown = val; 
+}
+
 int GameState::getPlayerOneScore() {
     return this->score[0];
 }