From 44724cbbb6f1b7002150190c50ec7cb58036edda Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Sun, 12 Nov 2023 15:21:14 +0100 Subject: [PATCH] Clean up something that didn't work in the first place. --- game.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/game.go b/game.go index 0fff18b..36da945 100644 --- a/game.go +++ b/game.go @@ -14,11 +14,6 @@ const ( Down ) -const ( - Over = iota - Running -) - func initilize() (tcell.Screen, tcell.Style, error) { style := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset) @@ -75,10 +70,10 @@ func gameDirector(screen tcell.Screen, style tcell.Style, keypresses chan int, g } if snakex == 0 || snakex == screenx-1 { - gamestate <- Over + close(gamestate) return } else if snakey == 0 || snakey == screeny-1 { - gamestate <- Over + close(gamestate) return } @@ -102,14 +97,6 @@ func keyboardProcessor(screen tcell.Screen, keypresses chan int, gamestate chan for { - select { - case state := <-gamestate: - if state == Over { - return - } - case <-time.After(10 * time.Millisecond): - } - // Poll for an event ev := screen.PollEvent() @@ -140,6 +127,16 @@ func keyboardProcessor(screen tcell.Screen, keypresses chan int, gamestate chan } } + // This function needs to know if the game is over. + select { + case <-time.After(10 * time.Millisecond): + + case _, ok := <-gamestate: + if !ok { + return + } + } + } }