game

package
v0.0.0-...-b5afa3f Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbsSnake

type AbsSnake interface {
	ID() string
	Move(foods []*Food) (ateFoods []*Food)
	Frame() []*Point
	ChangeDirection(direction Direction)
}

type Direction

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

func (Direction) String

func (i Direction) String() string

type Food

type Food struct {
	Position *Point
}

type Game

type Game struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame(p printer, snakes []AbsSnake, sizer winSizer) *Game

func (*Game) DoSnakeAction

func (g *Game) DoSnakeAction(action SnakeAction)

func (*Game) Start

func (g *Game) Start() error

func (*Game) Stop

func (g *Game) Stop()

type Point

type Point struct {
	X int
	Y int

	PType PointType
	// for show
	Face string
}

屏幕左上角为原点

func (*Point) Equal

func (p *Point) Equal(other *Point) bool

func (*Point) GetFace

func (p *Point) GetFace() string

func (*Point) Move

func (p *Point) Move(d Direction) *Point

type PointType

type PointType int
const (
	PointOfSnake PointType = iota
	PointOfFood
)

func (PointType) String

func (i PointType) String() string

type Snake

type Snake struct {
	// contains filtered or unexported fields
}

func NewSnake

func NewSnake(id string, winSizer winSizer) *Snake

func (*Snake) ChangeDirection

func (snake *Snake) ChangeDirection(direction Direction)

func (*Snake) Frame

func (snake *Snake) Frame() []*Point

func (*Snake) ID

func (snake *Snake) ID() string

func (*Snake) Move

func (snake *Snake) Move(foods []*Food) (ateFoods []*Food)

type SnakeAction

type SnakeAction struct {
	// contains filtered or unexported fields
}

func NewSnakeAction

func NewSnakeAction(sID string, d Direction) SnakeAction

Jump to

Keyboard shortcuts

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