Skip to content

Instantly share code, notes, and snippets.

@erap129
Created September 26, 2022 07:54
Show Gist options
  • Select an option

  • Save erap129/540e24805f5a4a75487693e36fdd6e42 to your computer and use it in GitHub Desktop.

Select an option

Save erap129/540e24805f5a4a75487693e36fdd6e42 to your computer and use it in GitHub Desktop.
Snake - game.go
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