diff --git a/mines_models/__init__.py b/mine_models/__init__.py similarity index 100% rename from mines_models/__init__.py rename to mine_models/__init__.py diff --git a/mines_models/chained_mine.py b/mine_models/chained_mine.py similarity index 100% rename from mines_models/chained_mine.py rename to mine_models/chained_mine.py diff --git a/mines_models/mine.py b/mine_models/mine.py similarity index 100% rename from mines_models/mine.py rename to mine_models/mine.py diff --git a/mines_models/standard_mine.py b/mine_models/standard_mine.py similarity index 100% rename from mines_models/standard_mine.py rename to mine_models/standard_mine.py diff --git a/mines_models/time_mine.py b/mine_models/time_mine.py similarity index 100% rename from mines_models/time_mine.py rename to mine_models/time_mine.py diff --git a/minefield.py b/minefield.py index d78c841..fed9072 100644 --- a/minefield.py +++ b/minefield.py @@ -3,7 +3,9 @@ import ctypes # import agent as ag import project_constants as const import tile as tl -from mines_models import standard_mine as sm +from mine_models import standard_mine as sm +from mine_models import time_mine as tm +from mine_models import chained_mine as cm tile_asset_options = { @@ -57,17 +59,13 @@ class Minefield: # load tile's data from json tile_data = data[f"{x},{y}"] - # create and add mine if there is one + # if there is a mine, create & assign new Mine object (type recognition included) if tile_data["mine"] is not None: - # 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)) + mine = self._create_mine(tile_data["mine"], x, y) self.matrix[x][y].mine = mine self.matrix[x][y].color = tile_data["color"].upper() - - def draw(self, window): # iterate through tiles for raw in self.matrix: @@ -84,7 +82,6 @@ class Minefield: # 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.agent.position[0], self.agent.position[1]) @@ -107,7 +104,31 @@ class Minefield: self.agent.position[1] = int(self.agent.y) ctypes.windll.user32.MessageBoxW(0, "Znowu się nie udało", "GAME OVER", 1) # This part of the pop up message is just a temporary solution - - # Here are defined functions that move our agent. They are being called in main when certain key is pressed - + # distinguishes new mine's type and creates appropriate object + def _create_mine(self, mine_data, x, y): + mine_type = mine_data["mine_type"] + + # TIME MINE + if mine_type == "time": + timer = mine_data["timer"] + mine = tm.TimeMine((x, y), int(timer)) + + # CHAINED MINE + elif mine_type == "chained": + if mine_data["predecessor"] is not None: + # locate predecessor + x, y = map(int, mine_data["predecessor"].split(',')) + + # get predecessor object and assign it to the new mine + predecessor = self.matrix[x][y].mine + mine = cm.ChainedMine((x, y), predecessor) + + else: + mine = cm.ChainedMine((x, y)) + + # STANDARD MINE + else: + mine = sm.StandardMine((x, y)) + + return mine diff --git a/project_constants.py b/project_constants.py index 68b2b03..5cb202a 100644 --- a/project_constants.py +++ b/project_constants.py @@ -80,7 +80,7 @@ STRUCT_MINE_ATTRIBUTE_TYPES = { # ============== # # ==== MAPS ==== # # ============== # -MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "firstmap.json") +MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "secondmap.json") # ============== # # === ASSETS === # diff --git a/resources/minefields/firstmap.json b/resources/minefields/firstmap (deprecated).json similarity index 100% rename from resources/minefields/firstmap.json rename to resources/minefields/firstmap (deprecated).json diff --git a/resources/minefields/secondmap.json b/resources/minefields/secondmap.json new file mode 100644 index 0000000..28a19bb --- /dev/null +++ b/resources/minefields/secondmap.json @@ -0,0 +1,499 @@ +{ + "0,0": { + "color": "BLUE", + "mine": null + }, + "0,1": { + "color": "YELLOW", + "mine": null + }, + "0,2": { + "color": "GREEN", + "mine": null + }, + "0,3": { + "color": "PURPLE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "0,4": { + "color": "BLUE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "0,5": { + "color": "BLUE", + "mine": null + }, + "0,6": { + "color": "RED", + "mine": null + }, + "0,7": { + "color": "GREEN", + "mine": null + }, + "0,8": { + "color": "BLUE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "0,3" + } + }, + "0,9": { + "color": "RED", + "mine": { + "asset": "F", + "mine_type": "time", + "timer": 20 + } + }, + "1,0": { + "color": "GREEN", + "mine": null + }, + "1,1": { + "color": "WHITE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "1,2": { + "color": "WHITE", + "mine": null + }, + "1,3": { + "color": "PURPLE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "1,4": { + "color": "ORANGE", + "mine": null + }, + "1,5": { + "color": "GREEN", + "mine": null + }, + "1,6": { + "color": "WHITE", + "mine": null + }, + "1,7": { + "color": "GREEN", + "mine": null + }, + "1,8": { + "color": "ORANGE", + "mine": null + }, + "1,9": { + "color": "ORANGE", + "mine": null + }, + "2,0": { + "color": "RED", + "mine": null + }, + "2,1": { + "color": "PURPLE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "2,2": { + "color": "RED", + "mine": null + }, + "2,3": { + "color": "ORANGE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "2,4": { + "color": "WHITE", + "mine": null + }, + "2,5": { + "color": "ORANGE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "2,6": { + "color": "YELLOW", + "mine": null + }, + "2,7": { + "color": "YELLOW", + "mine": null + }, + "2,8": { + "color": "RED", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "2,9": { + "color": "PURPLE", + "mine": null + }, + "3,0": { + "color": "PURPLE", + "mine": null + }, + "3,1": { + "color": "RED", + "mine": { + "asset": "F", + "mine_type": "time", + "timer": 19 + } + }, + "3,2": { + "color": "WHITE", + "mine": null + }, + "3,3": { + "color": "ORANGE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "1,3" + } + }, + "3,4": { + "color": "ORANGE", + "mine": null + }, + "3,5": { + "color": "PURPLE", + "mine": null + }, + "3,6": { + "color": "ORANGE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "3,7": { + "color": "RED", + "mine": null + }, + "3,8": { + "color": "GREEN", + "mine": null + }, + "3,9": { + "color": "WHITE", + "mine": null + }, + "4,0": { + "color": "PURPLE", + "mine": null + }, + "4,1": { + "color": "ORANGE", + "mine": null + }, + "4,2": { + "color": "PURPLE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "4,3": { + "color": "PURPLE", + "mine": null + }, + "4,4": { + "color": "RED", + "mine": null + }, + "4,5": { + "color": "RED", + "mine": null + }, + "4,6": { + "color": "BLUE", + "mine": null + }, + "4,7": { + "color": "BLUE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": null + } + }, + "4,8": { + "color": "PURPLE", + "mine": null + }, + "4,9": { + "color": "ORANGE", + "mine": null + }, + "5,0": { + "color": "BLUE", + "mine": null + }, + "5,1": { + "color": "ORANGE", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "2,3" + } + }, + "5,2": { + "color": "RED", + "mine": null + }, + "5,3": { + "color": "GREEN", + "mine": null + }, + "5,4": { + "color": "YELLOW", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "2,8" + } + }, + "5,5": { + "color": "YELLOW", + "mine": null + }, + "5,6": { + "color": "ORANGE", + "mine": null + }, + "5,7": { + "color": "ORANGE", + "mine": null + }, + "5,8": { + "color": "WHITE", + "mine": null + }, + "5,9": { + "color": "RED", + "mine": null + }, + "6,0": { + "color": "WHITE", + "mine": null + }, + "6,1": { + "color": "YELLOW", + "mine": null + }, + "6,2": { + "color": "RED", + "mine": null + }, + "6,3": { + "color": "BLUE", + "mine": null + }, + "6,4": { + "color": "PURPLE", + "mine": null + }, + "6,5": { + "color": "GREEN", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "6,6": { + "color": "WHITE", + "mine": null + }, + "6,7": { + "color": "PURPLE", + "mine": null + }, + "6,8": { + "color": "PURPLE", + "mine": null + }, + "6,9": { + "color": "BLUE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "7,0": { + "color": "YELLOW", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "4,7" + } + }, + "7,1": { + "color": "PURPLE", + "mine": null + }, + "7,2": { + "color": "WHITE", + "mine": null + }, + "7,3": { + "color": "RED", + "mine": null + }, + "7,4": { + "color": "GREEN", + "mine": null + }, + "7,5": { + "color": "GREEN", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "7,6": { + "color": "PURPLE", + "mine": { + "asset": "F", + "mine_type": "time", + "timer": 39 + } + }, + "7,7": { + "color": "RED", + "mine": null + }, + "7,8": { + "color": "GREEN", + "mine": null + }, + "7,9": { + "color": "GREEN", + "mine": null + }, + "8,0": { + "color": "GREEN", + "mine": null + }, + "8,1": { + "color": "WHITE", + "mine": { + "asset": "F", + "mine_type": "time", + "timer": 24 + } + }, + "8,2": { + "color": "WHITE", + "mine": null + }, + "8,3": { + "color": "PURPLE", + "mine": { + "asset": "A", + "mine_type": "standard" + } + }, + "8,4": { + "color": "BLUE", + "mine": null + }, + "8,5": { + "color": "GREEN", + "mine": null + }, + "8,6": { + "color": "GREEN", + "mine": null + }, + "8,7": { + "color": "PURPLE", + "mine": null + }, + "8,8": { + "color": "GREEN", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "3,6" + } + }, + "8,9": { + "color": "WHITE", + "mine": null + }, + "9,0": { + "color": "ORANGE", + "mine": null + }, + "9,1": { + "color": "GREEN", + "mine": null + }, + "9,2": { + "color": "YELLOW", + "mine": null + }, + "9,3": { + "color": "BLUE", + "mine": null + }, + "9,4": { + "color": "YELLOW", + "mine": null + }, + "9,5": { + "color": "GREEN", + "mine": { + "asset": "B", + "mine_type": "chained", + "predecessor": "0,4" + } + }, + "9,6": { + "color": "PURPLE", + "mine": null + }, + "9,7": { + "color": "ORANGE", + "mine": null + }, + "9,8": { + "color": "RED", + "mine": null + }, + "9,9": { + "color": "RED", + "mine": null + }, + "agent_starting_position": "0,0" +} \ No newline at end of file