Clean up something that didn't work in the first place.

This commit is contained in:
Sacha Ligthert 2023-11-12 15:21:14 +01:00
parent de33a25864
commit 44724cbbb6

27
game.go
View File

@ -14,11 +14,6 @@ const (
Down Down
) )
const (
Over = iota
Running
)
func initilize() (tcell.Screen, tcell.Style, error) { func initilize() (tcell.Screen, tcell.Style, error) {
style := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset) 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 { if snakex == 0 || snakex == screenx-1 {
gamestate <- Over close(gamestate)
return return
} else if snakey == 0 || snakey == screeny-1 { } else if snakey == 0 || snakey == screeny-1 {
gamestate <- Over close(gamestate)
return return
} }
@ -102,14 +97,6 @@ func keyboardProcessor(screen tcell.Screen, keypresses chan int, gamestate chan
for { for {
select {
case state := <-gamestate:
if state == Over {
return
}
case <-time.After(10 * time.Millisecond):
}
// Poll for an event // Poll for an event
ev := screen.PollEvent() 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
}
}
} }
} }