maps

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMap

func RegisterMap(id string, m GameMap)

RegisterMap adds a map to the global registry.

func SetupBoard

func SetupBoard(mapID string, settings rules.Settings, width, height int, snakeIDs []string) (*rules.BoardState, error)

SetupBoard is a shortcut for looking up a map by ID and initializing a new board state with it.

func UpdateBoard

func UpdateBoard(mapID string, previousBoardState *rules.BoardState, settings rules.Settings) (*rules.BoardState, error)

UpdateBoard is a shortcut for looking up a map by ID and updating an existing board state with it.

Types

type BoardStateEditor

type BoardStateEditor struct {
	*rules.BoardState
}

An Editor backed by a BoardState.

func NewBoardStateEditor

func NewBoardStateEditor(boardState *rules.BoardState) *BoardStateEditor

func (*BoardStateEditor) AddFood

func (editor *BoardStateEditor) AddFood(p rules.Point)

func (*BoardStateEditor) AddHazard

func (editor *BoardStateEditor) AddHazard(p rules.Point)

func (*BoardStateEditor) ClearFood

func (editor *BoardStateEditor) ClearFood()

func (*BoardStateEditor) ClearHazards

func (editor *BoardStateEditor) ClearHazards()

func (*BoardStateEditor) PlaceSnake

func (editor *BoardStateEditor) PlaceSnake(id string, body []rules.Point, health int32)

func (*BoardStateEditor) RemoveFood

func (editor *BoardStateEditor) RemoveFood(p rules.Point)

func (*BoardStateEditor) RemoveHazard

func (editor *BoardStateEditor) RemoveHazard(p rules.Point)

type Editor

type Editor interface {
	// Clears all food from the board.
	ClearFood()

	// Clears all hazards from the board.
	ClearHazards()

	// Adds a food to the board. Does not check for duplicates.
	AddFood(rules.Point)

	// Adds a hazard to the board. Does not check for duplicates.
	AddHazard(rules.Point)

	// Removes all food from a specific tile on the board.
	RemoveFood(rules.Point)

	// Removes all hazards from a specific tile on the board.
	RemoveHazard(rules.Point)

	// Updates the body and health of a snake.
	PlaceSnake(id string, body []rules.Point, health int32)
}

Editor is used by GameMap implementations to modify the board state.

type EmptyMap added in v1.1.2

type EmptyMap struct{}

func (EmptyMap) ID added in v1.1.2

func (m EmptyMap) ID() string

func (EmptyMap) Meta added in v1.1.2

func (m EmptyMap) Meta() Metadata

func (EmptyMap) SetupBoard added in v1.1.2

func (m EmptyMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (EmptyMap) UpdateBoard added in v1.1.2

func (m EmptyMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type GameMap

type GameMap interface {
	// Return a unique identifier for this map.
	ID() string

	// Return non-functional metadata about this map.
	Meta() Metadata

	// Called to generate a new board. The map is responsible for placing all snakes, food, and hazards.
	SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

	// Called every turn to optionally update the board.
	UpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error
}

func GetMap

func GetMap(id string) (GameMap, error)

GetMap returns the map associated with the given ID from the global registry.

type MapRegistry

type MapRegistry map[string]GameMap

MapRegistry is a mapping of map names to game maps.

func (MapRegistry) GetMap

func (registry MapRegistry) GetMap(id string) (GameMap, error)

GetMap returns the map associated with the given ID.

func (MapRegistry) RegisterMap

func (registry MapRegistry) RegisterMap(id string, m GameMap)

RegisterMap adds a stage to the registry. If a map has already been registered this will panic.

type Metadata

type Metadata struct {
	Name        string
	Author      string
	Description string
}

type RoyaleHazardsMap added in v1.1.2

type RoyaleHazardsMap struct{}

func (RoyaleHazardsMap) ID added in v1.1.2

func (m RoyaleHazardsMap) ID() string

func (RoyaleHazardsMap) Meta added in v1.1.2

func (m RoyaleHazardsMap) Meta() Metadata

func (RoyaleHazardsMap) SetupBoard added in v1.1.2

func (m RoyaleHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RoyaleHazardsMap) UpdateBoard added in v1.1.2

func (m RoyaleHazardsMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type StandardMap

type StandardMap struct{}

func (StandardMap) ID

func (m StandardMap) ID() string

func (StandardMap) Meta

func (m StandardMap) Meta() Metadata

func (StandardMap) SetupBoard

func (m StandardMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StandardMap) UpdateBoard

func (m StandardMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type StubMap added in v1.1.1

type StubMap struct {
	Id             string
	SnakePositions map[string]rules.Point
	Food           []rules.Point
	Hazards        []rules.Point
	Error          error
}

An implementation of GameMap that just does predetermined placements, for testing.

func (StubMap) ID added in v1.1.1

func (m StubMap) ID() string

func (StubMap) Meta added in v1.1.1

func (StubMap) Meta() Metadata

func (StubMap) SetupBoard added in v1.1.1

func (m StubMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StubMap) UpdateBoard added in v1.1.1

func (m StubMap) UpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

Jump to

Keyboard shortcuts

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