snake

package
v0.0.0-...-f4c9d17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RUNE_RUNNING  = '🐍'
	RUNE_GAMEOVER = '🐶'
)

Variables

View Source
var (
	RUNE_FRUIT = []rune{
		'🍉', '🍌', '🍇', '🍈', '🍊', '🍋', '🍌', '🍍', '🍎', '🍐', '🍑', '🍒', '🍓', '🥝', '🍅', '🥥', '🥑',
	}
)

Functions

This section is empty.

Types

type Board

type Board struct {
	Width  int
	Height int
	Data   []rune
}

type Cell

type Cell struct {
	X    int
	Y    int
	Char rune
}

func NewCellJoined

func NewCellJoined(width, height int, cell *Cell, dir Direction) *Cell

func NewCellRand

func NewCellRand(width, height int, char rune) *Cell

func NewFruit

func NewFruit(width, height int, snake *Snake) *Cell

func (*Cell) Hit

func (c *Cell) Hit(other *Cell) bool

type Direction

type Direction int
const (
	DIR_NONE Direction = iota
	DIR_UP
	DIR_DOWN
	DIR_LEFT
	DIR_RIGHT
)

type Display

type Display interface {
	UpdateBoard(board *Board)
}

type Engine

type Engine struct {
	Display    Display
	Width      int
	Height     int
	FPS        int
	Growth     int
	NextGrowth int
	Speed      int
	NextSpeed  int
	Direction  Direction
	Score      int
	Snake      *Snake
	Fruit      *Cell
	Refresh    *time.Ticker
	Quit       chan bool
	Move       chan Direction
}

func NewEngine

func NewEngine(display Display, width, height, fps int) *Engine

func (*Engine) Start

func (e *Engine) Start()

func (*Engine) Stop

func (e *Engine) Stop()

type Game

type Game struct {
	*tview.Box

	Listener Listener
	App      *tview.Application
	Board    *Board
	Engine   *Engine
}

func NewGame

func NewGame(app *tview.Application, listener Listener) *Game

func (*Game) Draw

func (g *Game) Draw(screen tcell.Screen)

func (*Game) InputHandler

func (g *Game) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) bool

func (*Game) Play

func (g *Game) Play()

func (*Game) Quit

func (g *Game) Quit()

func (*Game) SetRect

func (g *Game) SetRect(x, y, width, height int)

func (*Game) UpdateBoard

func (g *Game) UpdateBoard(board *Board)

type Listener

type Listener interface {
	SnakeGameFinished()
}

type Snake

type Snake struct {
	Body []*Cell
}

func NewSnake

func NewSnake(width, height int) *Snake

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳