Projekt_Sztuczna_Inteligencja/objects/tile.py

37 lines
1.0 KiB
Python
Raw Normal View History

from project_constants import Terrain
# Assume_cost function assumes colour as an argument (colour that is already given to a tile) and depending
# on what it is returns value of Terrein Enum
# It is used in Tile.cost (giving the value to the tile)
def assume_cost(terrain_type, mine):
2021-06-18 17:55:38 +02:00
# to allow walking through inactive mines -> and mine.active
if mine is not None:
return Terrain.MINE
if terrain_type == "CONCRETE":
return Terrain.CONCRETE
elif terrain_type == "GRASS":
return Terrain.GRASS
elif terrain_type == "MUD":
return Terrain.MUD
2021-03-12 11:49:19 +01:00
class Tile:
def __init__(self, position, terrain_type=None, mine=None):
2021-03-12 11:49:19 +01:00
self.position = position
self.terrain_type = terrain_type
self._cost = assume_cost(terrain_type, mine)
2021-03-12 21:24:04 +01:00
# mine is an instance of Mine class
self.mine = mine
@property
def cost(self):
self._cost = assume_cost(self.terrain_type, self.mine)
return self._cost
@cost.setter
def cost(self, new_value):
self._cost = new_value