Add Direction.all() that returns an iterator that produces all the Direction values
This commit is contained in:
parent
1247617b87
commit
1cd45d366b
2 changed files with 13 additions and 12 deletions
|
@ -2,7 +2,7 @@
|
|||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Tuple, overload
|
||||
from typing import Any, Iterator, overload
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Point:
|
||||
|
@ -47,6 +47,17 @@ class Direction:
|
|||
West = Vector(-1, 0)
|
||||
NorthWest = Vector(-1, -1)
|
||||
|
||||
@classmethod
|
||||
def all(cls) -> Iterator['Direction']:
|
||||
yield Direction.North
|
||||
yield Direction.NorthEast
|
||||
yield Direction.East
|
||||
yield Direction.SouthEast
|
||||
yield Direction.South
|
||||
yield Direction.SouthWest
|
||||
yield Direction.West
|
||||
yield Direction.NorthWest
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Size:
|
||||
width: int = 0
|
||||
|
|
|
@ -196,17 +196,7 @@ class RoomsAndCorridorsGenerator(MapGenerator):
|
|||
if tiles[x, y] != Floor:
|
||||
continue
|
||||
|
||||
neighbors = [
|
||||
pos + Direction.North,
|
||||
pos + Direction.NorthEast,
|
||||
pos + Direction.East,
|
||||
pos + Direction.SouthEast,
|
||||
pos + Direction.South,
|
||||
pos + Direction.SouthWest,
|
||||
pos + Direction.West,
|
||||
pos + Direction.NorthWest,
|
||||
]
|
||||
|
||||
neighbors = (pos + direction for direction in Direction.all())
|
||||
for neighbor in neighbors:
|
||||
if tiles[neighbor.x, neighbor.y] != Empty:
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue