Added a method to interfaces.Map to get the neighbours of a given tile
This commit is contained in:
parent
7fb743eb72
commit
3a8549cfcc
|
@ -5,6 +5,7 @@ from enum import Enum, auto
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
from random import choice, randint
|
from random import choice, randint
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
from itertools import product
|
||||||
|
|
||||||
from .display.texturepack import TexturePack
|
from .display.texturepack import TexturePack
|
||||||
from .translations import gettext as _
|
from .translations import gettext as _
|
||||||
|
@ -180,6 +181,13 @@ class Map:
|
||||||
for entisave in d["entities"]:
|
for entisave in d["entities"]:
|
||||||
self.add_entity(dictclasses[entisave["type"]](**entisave))
|
self.add_entity(dictclasses[entisave["type"]](**entisave))
|
||||||
|
|
||||||
|
def large_neighbourhood(self, y, x):
|
||||||
|
neighbours = []
|
||||||
|
for dy, dx in product([-1, 0, 1], [-1, 0, 1]):
|
||||||
|
if 0 < y+dy < self.height and 0 < x+dx < self.width:
|
||||||
|
neighbours.append([y+dy, x+dx])
|
||||||
|
return neighbours
|
||||||
|
|
||||||
|
|
||||||
class Tile(Enum):
|
class Tile(Enum):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue