Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdjacentUnitGetter ¶
type AdjacentUnitGetter[T any] func(originCoord *Coordinate, relativeCoord *Coordinate) (unit *T, isCrossBorder bool)
This function will be passed into NextUnitGenerator, this is how you can adajcent units in NextUnitGenerator. Also, 2nd argument "isCrossBorder" tells you if the adjacent unit is on ohter side of the map.
type Area ¶
type Area struct { From Coordinate To Coordinate }
Area indicates an area within two coordinates.
type Coordinate ¶
Coordniate tells you the position of an unit in the game.
type ErrAreaIsInvalid ¶
type ErrAreaIsInvalid struct {
Area *Area
}
This error will be thrown when the X or Y of "from coordinate" is less than X or Y of "to coordinate" in the area.
func (*ErrAreaIsInvalid) Error ¶
func (e *ErrAreaIsInvalid) Error() string
type ErrCoordinateIsInvalid ¶
type ErrCoordinateIsInvalid struct {
Coordinate *Coordinate
}
This error will be thrown when you're trying to set or get an unit with invalid coordinate.
func (*ErrCoordinateIsInvalid) Error ¶
func (e *ErrCoordinateIsInvalid) Error() string
Tell you that the coordinate is invalid.
type ErrUnitsIsInvalid ¶
type ErrUnitsIsInvalid struct { }
This error will be thrown when you try to create a new game with invalid size.
func (*ErrUnitsIsInvalid) Error ¶
func (e *ErrUnitsIsInvalid) Error() string
Tell you that the size is invalid.
type Game ¶
type Game[T any] interface { // Generate next units, the way you generate next units will be depending on the NextUnitGenerator function // you passed in SetNextUnitGenerator. GenerateNextUnits() (units *[][]T) // Set NextUnitGenerator, which tells the game how you want to generate next unit of the given unit. SetNextUnitGenerator(nextUnitGenerator NextUnitGenerator[T]) // Set the status of the unit at the given coordinate. SetUnit(coord *Coordinate, unit *T) (err error) // Get the size of the game. GetSize() (size *Size) // Get the status of the unit at the given coordinate. GetUnit(coord *Coordinate) (unit *T, err error) // Get all units in the area. GetUnitsInArea(area *Area) (units *[][]T, err error) // Get all units in the game. GetUnits() (units *[][]T) // Iterate through units in the given area. IterateUnitsInArea(area *Area, callback UnitsIteratorCallback[T]) (err error) // Iterate through all units in the game IterateUnits(callback UnitsIteratorCallback[T]) }
"T" in the Game interface represents the type of unit, it's defined by you.
type NextUnitGenerator ¶
type NextUnitGenerator[T any] func(coord *Coordinate, unit *T, getAdjacentUnit AdjacentUnitGetter[T]) (nextUnit *T)
NextUnitGenerator tells the game how you're gonna generate next status of the given unit.
type UnitsIteratorCallback ¶
type UnitsIteratorCallback[T any] func(coord *Coordinate, unit *T)
UnitsIteratorCallback will be called when iterating through units.