| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- // An amateurs approach to the game of Snake
- package main
- import (
- "fmt"
- "log"
- )
- // main function
- func main() {
- // Create channles to manage keypresses and the gamestate
- keypresses := make(chan int)
- gamestate := make(chan int)
- // Score tracker
- score := Score{
- score: 0,
- scoreCounter: 1,
- reason: 0,
- }
- // Initialize tcell and clean up when needed.
- screen, style, err := initilize()
- if err != nil {
- log.Fatalln("Initlization error: ", err)
- }
- //defer quit(screen)
- // Spawn the Game Director in its own go routine
- // We give it channels to control...
- go gameDirector(screen, style, keypresses, gamestate, &score)
- // A simple function that captures keyboard presses...
- // ...and sends it to the GameDirector.
- keyboardProcessor(screen, keypresses, gamestate, &score)
- // Quit the screen
- quit(screen)
- // Print the score
- fmt.Println("Score: ", score.score)
- switch score.reason {
- case 1:
- fmt.Println("Reason: You quit")
- case 2:
- fmt.Println("Reason: You hit a wall")
- case 3:
- fmt.Println("Reason: You ate your tail")
- }
- }
|