3030
3131 winHistory = []Round {}
3232 goalHistory = []Goal {}
33+ lastGoalHistory = []Goal {}
3334
3435 availableSoundModes = []string {"default" , "meme" , "quake" , "techno" }
3536 currentSoundMode = "random"
@@ -83,6 +84,12 @@ func increaseScore(team string) {
8384
8485func undoScore () {
8586 if (! gameIsRunning ) { return }
87+
88+ if (len (goalHistory ) == 0 && len (winHistory ) >= 1 ) {
89+ goalHistory = lastGoalHistory
90+ winHistory = winHistory [:len (winHistory )- 1 ]
91+ }
92+
8693 if len (goalHistory ) > 0 {
8794 goalHistory = goalHistory [:len (goalHistory )- 1 ]
8895 }
@@ -117,6 +124,7 @@ func updateScore() {
117124
118125 publish ("score/red" , strconv .Itoa (scoreRed ), true )
119126 publish ("score/white" , strconv .Itoa (scoreWhite ), true )
127+ publish ("round/current" , strconv .Itoa (currentRound ()), true )
120128
121129 goals , _ := json .Marshal (goalHistory )
122130 publish ("round/goals" , string (goals ), true )
@@ -133,8 +141,8 @@ func updateScore() {
133141func startGame () {
134142 clearAll ()
135143 gameIsRunning = true
136- publish ("game/round" , strconv .Itoa (currentRound ()), true )
137144 publish ("sound/play" , "start" , false )
145+ updateScore ()
138146
139147}
140148
@@ -152,6 +160,7 @@ func nextRound() {
152160
153161 rounds , _ := json .Marshal (winHistory )
154162 fmt .Printf (string (rounds ))
163+ lastGoalHistory = goalHistory
155164 resetScore ()
156165}
157166
@@ -198,7 +207,8 @@ func gameEnd(winner string) {
198207
199208 fmt .Printf ("%s is the winner \n " , winner )
200209
201- publish ("game/end" , winner , false )
210+ game , _ := json .Marshal (Game {Winner : winner , Time : time .Since (gameStartTime ).Seconds ()})
211+ publish ("game/end" , string (game ), false )
202212
203213 resetScore ()
204214 clearAll ()
0 commit comments