|
|
@@ -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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|