maps

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: AGPL-3.0 Imports: 2 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
	// contains filtered or unexported fields
}

An Editor backed by a BoardState.

func NewBoardStateEditor

func NewBoardStateEditor(boardState *rules.BoardState, rand rules.Rand) *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) Random

func (editor *BoardStateEditor) Random() rules.Rand

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 {
	// Returns a random number generator. This MUST be used for any non-deterministic behavior in a GameMap.
	Random() rules.Rand

	// 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 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 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

Jump to

Keyboard shortcuts

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