main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // An amateurs approach to the game of Snake
  2. package main
  3. import (
  4. "fmt"
  5. "log"
  6. )
  7. // main function
  8. func main() {
  9. // Create channles to manage keypresses and the gamestate
  10. keypresses := make(chan int)
  11. gamestate := make(chan int)
  12. // Score tracker
  13. score := Score{
  14. score: 0,
  15. scoreCounter: 1,
  16. reason: 0,
  17. }
  18. // Initialize tcell and clean up when needed.
  19. screen, style, err := initilize()
  20. if err != nil {
  21. log.Fatalln("Initlization error: ", err)
  22. }
  23. //defer quit(screen)
  24. // Spawn the Game Director in its own go routine
  25. // We give it channels to control...
  26. go gameDirector(screen, style, keypresses, gamestate, &score)
  27. // A simple function that captures keyboard presses...
  28. // ...and sends it to the GameDirector.
  29. keyboardProcessor(screen, keypresses, gamestate, &score)
  30. // Quit the screen
  31. quit(screen)
  32. // Print the score
  33. fmt.Println("Score: ", score.score)
  34. switch score.reason {
  35. case 1:
  36. fmt.Println("Reason: You quit")
  37. case 2:
  38. fmt.Println("Reason: You hit a wall")
  39. case 3:
  40. fmt.Println("Reason: You ate your tail")
  41. }
  42. }