game

package
v0.0.0-...-def37d1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinates

type Coordinates struct {
	X int
	Y int
}

Coordinates contains the coordinates of the snake's head

type Direction

type Direction uint8

Direction is the type that reppresents the current direction of the snake

const (
	UP    Direction = 0
	RIGHT Direction = 1
	DOWN  Direction = 2
	LEFT  Direction = 3
)

UP means that the snake is going up RIGHT means that the snake is going right DOWN means that the snake is going down LEFT means that the snake is going left

type Food

type Food struct {
	Position Coordinates
}

Food contains all the food information

func (*Food) Generate

func (f *Food) Generate(snake Snake)

Generate generates a new food item for the snake to eat

type Options

type Options struct {
	PacmanEffect bool
	Speed        Speed
}

Options reppresents the options of the game

type Snake

type Snake struct {
	Direction Direction
	Length    int
	Positions []Coordinates
}

Snake contains all the snake information

func Init

func Init(terminalWidth int, terminalHeight int) Snake

Init initializes a new game

func (*Snake) Grow

func (s *Snake) Grow()

Grow is the functions that makes the snake growing

func (*Snake) Init

func (s *Snake) Init()

Init initializes the snake's head

func (*Snake) Move

func (s *Snake) Move(deleteTail bool, options Options) bool

Move is the function that moves a snake

type Speed

type Speed int8

Speed reppresent the speed of the snake during the game

const (
	VERYFAST Speed = 1
	FAST     Speed = 2
	NORMAL   Speed = 3
	SLOW     Speed = 4
	VERYSLOW Speed = 5
)

VERYSLOW tells the snake to go very slowly (500) SLOW tells the snake to go slowly (300ms) NORMAL tells the snake to go at normal speed (200ms) FAST tells the snake to go fast (100ms) VERYFAST tells the snake to go very fast (50ms)

Jump to

Keyboard shortcuts

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