diff --git a/mine.py b/mine.py deleted file mode 100644 index 69256a4..0000000 --- a/mine.py +++ /dev/null @@ -1,7 +0,0 @@ -class Mine: - def __init__(self, position, mine_type, active=True): - self.position = position - self.mine_type = mine_type - self.active = active - - # more to be added later (e.g. disarming) diff --git a/minefield.py b/minefield.py index a049de1..b7dcc51 100644 --- a/minefield.py +++ b/minefield.py @@ -1,7 +1,8 @@ import json + import project_constants as const import tile as tl -import mine as mn +from mines_models import standard_mine as sm tile_asset_options = { "BLUE": const.ASSET_TILE_BLUE, @@ -53,8 +54,10 @@ class Minefield: # create and add mine if there is one if tile_data["mine"] is not None: - mine_type = tile_data["mine"]["mine_type"].upper() - mine = mn.Mine((x, y), mine_type) + + # TODO: check mine type and create suitable one + # JSON file doesn't represent new mine types yet, so every mine is a standard one at the moment + mine = sm.StandardMine((x, y)) self.matrix[x][y].mine = mine self.matrix[x][y].color = tile_data["color"].upper() @@ -77,7 +80,9 @@ class Minefield: # draw a mine on top if there is one if tile.mine is not None: - window.blit(mine_asset_options.get(tile.mine.mine_type), tile_screen_coords) + # TODO: blit appropriate mine type + # current icons don't represent actual types, thus every mine has the same icon (temporary solution) + window.blit(mine_asset_options['A'], tile_screen_coords) # draw the sapper sapper_screen_coords = calculate_screen_position(self.sapper_position[0], self.sapper_position[1]) diff --git a/mines_models/__init__.py b/mines_models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mines_models/chained_mine.py b/mines_models/chained_mine.py new file mode 100644 index 0000000..da74165 --- /dev/null +++ b/mines_models/chained_mine.py @@ -0,0 +1,14 @@ +# for type hints (predecessor) +from __future__ import annotations + +from .mine import Mine + + +class ChainedMine(Mine): + def __init__(self, position, predecessor: ChainedMine = None, active=True): + self.predecessor = predecessor + self.type = "chained" + super().__init__(position, active) + + def disarm(self): + pass diff --git a/mines_models/mine.py b/mines_models/mine.py new file mode 100644 index 0000000..7e9dcb3 --- /dev/null +++ b/mines_models/mine.py @@ -0,0 +1,19 @@ +# module for abstarct classes +from abc import ABC, abstractmethod + +# type hints +from typing import Tuple + +# Mine cannot be instatinated +# all abstarct methods must be implemented in derived classes + + +class Mine(ABC): + @abstractmethod + def __init__(self, position: Tuple[int, int], active=True): + self.position = position + self.active = active + + @abstractmethod + def disarm(self): + pass diff --git a/mines_models/standard_mine.py b/mines_models/standard_mine.py new file mode 100644 index 0000000..4f1a9d9 --- /dev/null +++ b/mines_models/standard_mine.py @@ -0,0 +1,10 @@ +from .mine import Mine + + +class StandardMine(Mine): + def __init__(self, position, active=True): + self.mine_type = "standard" + super().__init__(position, active) + + def disarm(self): + pass diff --git a/mines_models/tests.py b/mines_models/tests.py new file mode 100644 index 0000000..207ed83 --- /dev/null +++ b/mines_models/tests.py @@ -0,0 +1,21 @@ +import time_mine as tm +import chained_mine as cm +import standard_mine as sm + +mine1 = tm.TimeMine((1, 2), "time", 3) +mine2 = cm.ChainedMine((3, 4)) +mine3 = cm.ChainedMine((0, 6), "chained", mine2) +mine4 = sm.StandardMine((1, 2), "standard") + +mines = [mine1, mine2, mine3, mine4] + +for mine in mines: + print(mine.position) + print(mine.active) + +print(mine2.predecessor) +print(mine3.predecessor) + +mine4.disarm() + +mine5 = cm.ChainedMine() diff --git a/mines_models/time_mine.py b/mines_models/time_mine.py new file mode 100644 index 0000000..52e6a8d --- /dev/null +++ b/mines_models/time_mine.py @@ -0,0 +1,11 @@ +from .mine import Mine + + +class TimeMine(Mine): + def __init__(self, position, timer, active=True): + self.type = "time" + self.timer = timer + super().__init__(position, active) + + def disarm(self): + pass