Ver Fonte

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

Sacha Ligthert há 2 anos atrás
pai
commit
44724cbbb6
1 ficheiros alterados com 12 adições e 15 exclusões
  1. 12 15
      game.go

+ 12 - 15
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
+			}
+		}
+
 	}
 
 }