models

package
v0.0.0-...-3df53b1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Initializing = iota
	InProgress
	Ended
)

Variables

View Source
var (
	ErrInProgress = errors.New("game is already in progress")
	ErrMaxPlayers = errors.New("cannot add more than 4 players")
)

Functions

func GetGames

func GetGames() map[string]*Field

Types

type ChangeDirection

type ChangeDirection struct {
	Index     int
	Direction Direction
	Wait      *sync.WaitGroup
}

type Coordinate

type Coordinate struct {
	X int `json:"X"`
	Y int `json:"Y"`
}

type Direction

type Direction int
const (
	Up Direction = iota
	Down
	Left
	Right
)

type Field

type Field struct {
	ID            string
	Height, Width int
	Needed        int //number of players needed to start the game

	Gophers []*Gopher
	Board   [][]bool

	Change chan ChangeDirection
	Remove chan int

	State int
	// contains filtered or unexported fields
}

func GetGame

func GetGame(id string) (*Field, bool)

func NewField

func NewField(height, width int, needed int) (*Field, error)

func (*Field) Add

func (f *Field) Add(g *Gopher) (int, error)

func (*Field) PreGameRemove

func (f *Field) PreGameRemove(gopher *Gopher)

To be used when the game hasn't started yet

func (*Field) PrintBoard

func (f *Field) PrintBoard()

type Gopher

type Gopher struct {
	// Current direction
	Direction Direction
	X, Y      int
	Path      []Coordinate
	Score     int
	Paths     chan map[string]GopherInfo
	Notify    chan string
	Close     chan bool
}

func NewGopher

func NewGopher() *Gopher

type GopherInfo

type GopherInfo struct {
	Coordinate []Coordinate `json:"coordinate"`
	Color      string       `json:"color"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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