Created
September 26, 2022 07:54
-
-
Save erap129/540e24805f5a4a75487693e36fdd6e42 to your computer and use it in GitHub Desktop.
Snake - game.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "time" | |
| "github.com/gdamore/tcell" | |
| ) | |
| type Game struct { | |
| Screen tcell.Screen | |
| snakeBody SnakeBody | |
| } | |
| func (g *Game) Run() { | |
| defStyle := tcell.StyleDefault.Background(tcell.ColorBlack).Foreground(tcell.ColorWhite) | |
| g.Screen.SetStyle(defStyle) | |
| width, height := g.Screen.Size() | |
| snakeStyle := tcell.StyleDefault.Background(tcell.ColorWhite).Foreground(tcell.ColorWhite) | |
| for { | |
| g.Screen.Clear() | |
| g.snakeBody.Update(width, height) | |
| g.Screen.SetContent(g.snakeBody.X, g.snakeBody.Y, ' ', nil, snakeStyle) | |
| time.Sleep(40 * time.Millisecond) | |
| g.Screen.Show() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment