donjuan.space

Module Contents

Classes

Space

A space is a section of a dungeon composed of `Cell`s. This object

class donjuan.space.Space(cells: Optional[Set[Cell]] = None, name: Union[int, str] = '')[source]

Bases: abc.ABC

A space is a section of a dungeon composed of Cell`s. This object contains these cells in a ``set` under the property cells. It also has a name and knows about any entrances to the room (a list of Edge objects) via the entrances property.

Parameters
  • cells (Optional[Set[Cell]]) – cells that make up this space

  • name (Union[int, str], optional) – defaults to ‘’, the room name

assign_space_to_cells(self) → None[source]

Set the space attribute for each Cell to self.

reset_cell_coordinates(self) → None[source]
property cells(self) → Set[Cell]
property cell_coordinates(self) → Set[Tuple[int, int]]
property name(self) → Union[int, str]
add_cells(self, cells: Sequence[Cell]) → None[source]

Add cells to the set of cells in this space. Cells are added to both the cells set and the cell coordinates to the cell_coordinates set.

Parameters

cells (Sequence[Cell]) – any iterable collection of cells

overlaps(self, other: Space) → bool[source]

Compare the cells of this space to the other space to determine whether they overlap or not. Note, this algorithm is O(N) where N is the number of cells in this space, since set lookup is O(1).

Parameters

other (Space) – other space to check against

Returns

True if they overlap, False if not

set_name(self, name: Union[int, str]) → None[source]
shift_vertical(self, n: int) → None[source]

Change the y coordinates of all cells by n.

Parameters

n (int) – number to increment vertical position of cells

shift_horizontal(self, n: int) → None[source]

Change the x coordinates of all cells by n.

Parameters

n (int) – number to increment horizontal position of cells