game

package
v0.0.0-...-7f9c31e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldSymbol  = ' '
	SnakeSymbol  = '▇'
	BorderSymbol = '▇'
	AppleSymbol  = '●'
)

Variables

This section is empty.

Functions

func AnimationCycle

func AnimationCycle(game *Game, gameOver chan bool)

func DrawText

func DrawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)

func EventCycle

func EventCycle(game *Game, gameOver chan bool)

Types

type Apple

type Apple struct {
	Cell  Cell
	Style tcell.Style
	Field *Field
}

func NewApple

func NewApple(field *Field, style tcell.Style) Apple

func (Apple) CheckApple

func (apple Apple) CheckApple() bool

func (Apple) DrawApple

func (apple Apple) DrawApple()

func (*Apple) MoveApple

func (apple *Apple) MoveApple()

func (*Apple) UpdateApple

func (apple *Apple) UpdateApple() bool

type Cell

type Cell struct {
	X, Y int
}

func (Cell) DrawCell

func (c Cell) DrawCell(s tcell.Screen, symbol rune, style tcell.Style)

type Configuration

type Configuration struct {
	StartDelay, MinDelay, DelayChange      time.Duration
	MaxApples, NewAppleChance, SnakeLength int
	FieldWidth, FieldHeight                int
}

type Field

type Field struct {
	Screen        *tcell.Screen
	Game          Game
	X, Y          int
	Width, Height int
	Style         tcell.Style
	Cells         []Cell
	Snake         *Snake
	Apples        []Apple
}

func NewField

func NewField(s *tcell.Screen, x, y, width, height int, snake *Snake, style tcell.Style) Field

func (Field) DrawBorder

func (field Field) DrawBorder(symbol rune, style tcell.Style)

func (Field) DrawField

func (field Field) DrawField()

type Game

type Game struct {
	Screen        *tcell.Screen
	Field         *Field
	Score         *Score
	Width, Height int
	Ended         bool
	Styles
	Configuration
}

func NewGame

func NewGame(s *tcell.Screen, f *Field, score *Score, width, height int, styles Styles, configuraion Configuration) Game

func (*Game) InitGame

func (game *Game) InitGame()

func (Game) StartGame

func (game Game) StartGame()

type Score

type Score struct {
	X, Y  int
	Value int
	Game  *Game
}

func NewScore

func NewScore(x, y int, game *Game) Score

func (*Score) UpdateScore

func (score *Score) UpdateScore()

type Snake

type Snake struct {
	Head      Cell
	Tail      []Cell
	Field     *Field
	Style     tcell.Style
	Direction struct {
		X, Y int
	}
	Delay time.Duration
}

func NewSnake

func NewSnake(field *Field, x, y int, length int, delay time.Duration, style tcell.Style) Snake

func (*Snake) BorderTeleportation

func (snake *Snake) BorderTeleportation()

func (Snake) CheckSnake

func (snake Snake) CheckSnake() bool

func (Snake) DrawSnake

func (snake Snake) DrawSnake()

func (*Snake) MoveSnake

func (snake *Snake) MoveSnake(grow bool)

type Styles

type Styles struct {
	DefaultStyle, SnakeStyle, AppleStyle tcell.Style
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL