earwax.game_board module

Provides the GameBoard class.

class earwax.game_board.GameBoard(game: Game, size: earwax.point.Point[int][int], tile_builder: Callable[[earwax.point.Point], T], coordinates: earwax.point.Point[int][int] = NOTHING)

Bases: earwax.level.Level, typing.Generic

A useful starting point for making board games.

Tiles can be populated with the populate() method. This method will be called as part of the default on_push() event.

Variables:
  • size

    The size of this board.

    This value will be the maximum possible coordinates on the board, with (0, 0, 0) being the minimum.

  • tile_builder

    The function that is used to build the GameBoard.

    The return value of this function should be of type T.

  • coordinates – The coordinates of the player on this board.
  • tiles – All the tiles generated by populate().
  • populated_points – All the points that have been populated by populate().
current_tile

Return the current tile.

Gets the tile at the current coordinates.

If no such tile is found, None is returned.

get_tile(p: earwax.point.Point[int][int]) → T

Return the tile at the given point.

If there is no tile found, then NoSuchTile is raised.

Parameters:p – The coordinates of the desired tile.
move(direction: earwax.point.PointDirections, wrap: bool = False) → Callable[[], None]

Return a callable that can be used to move the player.

For example:

board = GameBoard(...)

board.action(
    'Move left', symbol=key.LEFT
)(board.move(PointDirections.west))
Parameters:
  • direction – The direction that this action should move the player in.
  • wrap – If True, then coordinates that are out of range will result in wrapping around to the other side of the board..
on_move_fail(direction: earwax.point.PointDirections) → None

Run code when the player fails to move.

An event that is dispatched when a player fails to move in the given direction.

Parameters:direction – The direction the player tried to move in.
on_move_success(direction: earwax.point.PointDirections) → None

Handle a successful move.

An event that is dispatched by move().

Parameters:direction – The direction the player just moved.
on_push() → None

Populate the board.

populate() → None

Fill the board.

exception earwax.game_board.NoSuchTile

Bases: Exception

No such tile exists.

This exception is raised by earwax.GameBoard.get_tile() when no tile is found at the given coordinates.