models

package
v0.0.0-...-88f0a41 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoWinner if the game continues
	NoWinner = iota

	// Draw if reached end game and the game is draw
	Draw

	// P1Wins if player 1 wins
	P1Wins

	// P2Wins if player 2 wins
	P2Wins
)
View Source
const (
	// EmptyCell represents an empty cell
	EmptyCell = iota

	// P1Head cell that contains the player 1 position
	P1Head

	// P2Head cell that contains the player 2 position
	P2Head

	// P1Tail cell - tail of player 1
	P1Tail

	// P2Tail cell - tail of player 2
	P2Tail

	// Crash cell - when p1 or p2 hits the board edge or another player
	Crash
)
View Source
const (
	// Up
	Up = iota

	// Left
	Left

	// Down
	Down

	// Right
	Right
)

Direction representation

View Source
const BoardHeight = 16

BoardHeight in cells

View Source
const BoardWidth = 16

BoardWidth in cells

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	P1   *Player
	P2   *Player
	Grid *Grid
}

Board rerpesents a game board: - P1, P2 - reference to players - Grid - a two dimensional array, containing the board state

func InitialBoard

func InitialBoard() *Board

InitialBoard creates an initial board

func (*Board) Advance

func (b *Board) Advance() (Winner, *Board)

Advance the game 1 move Returns a Winner and a Board This is a comment

func (*Board) GetCell

func (b *Board) GetCell(p Position) Cell

GetCell the value of a board cell

type Cell

type Cell byte

Cell represents a cell of the board grid The enum above contains the possibble values

type Direction

type Direction byte

Direction representation, above are the available values

type Grid

Grid is a two-dimensional array of bytes, representing the Grid state The lower left corner has coordinates 0, 0

type Player

type Player struct {
	Name          string
	Direction     Direction
	PrevDirection Direction
}

Player represents a player in the game

func (*Player) SetDirection

func (p *Player) SetDirection(d Direction)

SetDirection checks if the change in direction is a valid one and updates the player if so

type Position

type Position struct {
	X int
	Y int
}

Position represents a position on the grid

type Winner

type Winner byte

Winner representation, enum above shows possible values

Jump to

Keyboard shortcuts

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