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>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Tuple, overload
|
from typing import Any, Iterator, overload
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Point:
|
class Point:
|
||||||
|
@ -47,6 +47,17 @@ class Direction:
|
||||||
West = Vector(-1, 0)
|
West = Vector(-1, 0)
|
||||||
NorthWest = Vector(-1, -1)
|
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)
|
@dataclass(frozen=True)
|
||||||
class Size:
|
class Size:
|
||||||
width: int = 0
|
width: int = 0
|
||||||
|
|
|
@ -196,17 +196,7 @@ class RoomsAndCorridorsGenerator(MapGenerator):
|
||||||
if tiles[x, y] != Floor:
|
if tiles[x, y] != Floor:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
neighbors = [
|
neighbors = (pos + direction for direction in Direction.all())
|
||||||
pos + Direction.North,
|
|
||||||
pos + Direction.NorthEast,
|
|
||||||
pos + Direction.East,
|
|
||||||
pos + Direction.SouthEast,
|
|
||||||
pos + Direction.South,
|
|
||||||
pos + Direction.SouthWest,
|
|
||||||
pos + Direction.West,
|
|
||||||
pos + Direction.NorthWest,
|
|
||||||
]
|
|
||||||
|
|
||||||
for neighbor in neighbors:
|
for neighbor in neighbors:
|
||||||
if tiles[neighbor.x, neighbor.y] != Empty:
|
if tiles[neighbor.x, neighbor.y] != Empty:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue