From 3c263e57e74e901ffe1201b66e0046d59e53a59f Mon Sep 17 00:00:00 2001 From: s452645 Date: Wed, 19 May 2021 23:44:56 +0200 Subject: [PATCH 1/5] implemented setting random mines as targets --- main.py | 11 ++++++++++- mine_models/standard_mine.py | 2 +- minefield.py | 23 +++++++++++++++++++---- searching_algorithms/a_star.py | 28 +++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 6a11f12..0e335d9 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ # libraries +import time import pygame from pyglet.gl import * # for blocky textures import random @@ -119,12 +120,20 @@ def main(): for component in ui_components_list.selectable_ui_components: component.set_flags(is_active=False) + # === TARGET-MINE CHOICE (NAIVE) === + mines = minefield.get_active_mines() + if any(mines): + row, column = random.choice(mines).position + const.SCREEN.blit(HIGHLIGHT, const.get_tile_coordinates((row, column))) + else: + is_game_over = True + action_sequence = a_star.graphsearch( initial_state=a_star.State( row=minefield.agent.position[0], column=minefield.agent.position[1], direction=minefield.agent.direction), - minefield=minefield, tox=row, toy=column) + minefield=minefield, target_type="mine", tox=row, toy=column) # initializing variables in_game_timer = 0 diff --git a/mine_models/standard_mine.py b/mine_models/standard_mine.py index 4f1a9d9..371fe8c 100644 --- a/mine_models/standard_mine.py +++ b/mine_models/standard_mine.py @@ -3,7 +3,7 @@ from .mine import Mine class StandardMine(Mine): def __init__(self, position, active=True): - self.mine_type = "standard" + self.type = "standard" super().__init__(position, active) def disarm(self): diff --git a/minefield.py b/minefield.py index 269d3d6..6238734 100644 --- a/minefield.py +++ b/minefield.py @@ -45,16 +45,31 @@ class Minefield: if mine is not None and isinstance(mine, TimeMine): mine.timer = max(0, mine.starting_time - int(self.turn / 4)) + def get_active_mines(self): + mines = list() + + for row in range(const.V_GRID_VER_TILES): + for column in range(const.V_GRID_VER_TILES): + mine = self.matrix[row][column].mine + + if mine is not None and mine.active: + # do not add mines with predecessors + if mine.type == 'chained' and mine.predecessor is not None: + continue + + mines.append(mine) + + return mines + # ================ # # === MOVEMENT === # # ================ # # check if sapper's destination is accessible - # If Agent comes upon a tile with a mine his starting position shall be reestablished - def is_valid_move(self, target_row: int, target_column: int): + @staticmethod + def is_valid_move(target_row: int, target_column: int): if 0 <= target_row < const.V_GRID_VER_TILES \ - and 0 <= target_column < const.V_GRID_HOR_TILES \ - and self.matrix[target_row][target_column].mine is None: + and 0 <= target_column < const.V_GRID_HOR_TILES: return True return False diff --git a/searching_algorithms/a_star.py b/searching_algorithms/a_star.py index c87ed90..5c42f66 100644 --- a/searching_algorithms/a_star.py +++ b/searching_algorithms/a_star.py @@ -45,12 +45,32 @@ def get_estimated_cost(node: Node): return abs(node.state.row - GOAL[0]) + abs(node.state.column - GOAL[1]) -def goal_test(state: State): +def tile_goal_test(state: State): if (state.row, state.column) == GOAL: return True return False +def mine_goal_test(state: State): + if state.row == GOAL[0] and state.column == GOAL[1] - 1: + if state.direction == Direction.RIGHT: + return True + + elif state.row == GOAL[0] and state.column == GOAL[1] + 1: + if state.direction == Direction.LEFT: + return True + + elif state.row == GOAL[0] - 1 and state.column == GOAL[1]: + if state.direction == Direction.DOWN: + return True + + elif state.row == GOAL[0] + 1 and state.column == GOAL[1]: + if state.direction == Direction.UP: + return True + + return False + + def get_successors(state: State, minefield: Minefield): successors = list() @@ -73,6 +93,7 @@ def graphsearch(initial_state: State, minefield: Minefield, fringe: List[Node] = None, explored: List[Node] = None, + target_type: str = "tile", tox: int = None, toy: int = None): @@ -86,6 +107,11 @@ def graphsearch(initial_state: State, if tox is not None and toy is not None: GOAL = (tox, toy) + if target_type == "mine": + goal_test = mine_goal_test + else: + goal_test = tile_goal_test + # fringe and explored initialization if fringe is None: fringe = list() From 07934fb15cb5f277980caa3d2f8fa91d415d95a1 Mon Sep 17 00:00:00 2001 From: s452635 Date: Sun, 23 May 2021 05:50:49 +0200 Subject: [PATCH 2/5] created package for assets, minor changes to mine assets --- agent.py | 5 +- assets/__init__.py | 0 assets/asset_constants.py | 262 ++++++++++++++++++ display_assets.py => assets/display_assets.py | 91 +++--- game.py | 2 +- project_constants.py | 249 +---------------- resources/assets/chains.png | Bin 325 -> 248 bytes resources/assets/mine.png | Bin 196 -> 196 bytes resources/assets/time_mine.png | Bin 301 -> 296 bytes 9 files changed, 318 insertions(+), 291 deletions(-) create mode 100644 assets/__init__.py create mode 100644 assets/asset_constants.py rename display_assets.py => assets/display_assets.py (73%) diff --git a/agent.py b/agent.py index ed635e4..bee5fb3 100644 --- a/agent.py +++ b/agent.py @@ -1,4 +1,5 @@ import project_constants as const +from assets import asset_constants as asset import json from pygame import transform @@ -33,10 +34,10 @@ class Agent: coord_x, coord_y = self.on_screen_coordinates[0], self.on_screen_coordinates[1] tl_dimension = const.V_TILE_SIZE / 2 - rotating_rect = transform.rotate(const.ASSET_SAPPER, self.rotation_angle).get_rect() + rotating_rect = transform.rotate(asset.ASSET_SAPPER, self.rotation_angle).get_rect() rotating_rect.center = (coord_x + tl_dimension, coord_y + tl_dimension) - window.blit(transform.rotate(const.ASSET_SAPPER, self.rotation_angle), rotating_rect) + window.blit(transform.rotate(asset.ASSET_SAPPER, self.rotation_angle), rotating_rect) def update(self, delta_time, minefield): self.new_action = self.going_forward + self.rotating_left * 2 + self.rotating_right * 4 diff --git a/assets/__init__.py b/assets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/assets/asset_constants.py b/assets/asset_constants.py new file mode 100644 index 0000000..28d93b0 --- /dev/null +++ b/assets/asset_constants.py @@ -0,0 +1,262 @@ + +import pygame +import os + +import project_constants as c +DIR_ASSETS = c.DIR_ASSETS +V_TILE_SIZE = c.V_TILE_SIZE + + +# ============== # +# === ASSETS === # +# ============== # + +ASSET_BACKGROUND = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), + (650, 650) +) + +ASSET_SAPPER = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_WALL = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CONCRETE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "concrete.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MUD = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "mud.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_GRASS = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "grass.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "mine.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CHAINS = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chains.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CHAIN_COUNTER = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_counter.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TIME_MINE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_mine.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + + +# ==================== # +# === TIME NUMBERS === # +# ==================== # + +ASSET_NUMBER_TIME_0 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_0.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_1 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_1.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_2 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_2.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_3 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_3.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_4 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_4.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_5 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_5.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_6 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_6.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_7 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_7.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_8 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_8.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_9 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_9.png")), + (6, 16) +) + + +# ====================== # +# === CHAINS NUMBERS === # +# ====================== # + +ASSET_NUMBER_CHAINS_0 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_0.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_1 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_1.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_2 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_2.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_3 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_3.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_4 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_4.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_5 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_5.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_6 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_6.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_7 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_7.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_8 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_8.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_9 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_9.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_10 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_10.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_11 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_11.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_12 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_12.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_13 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_13.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_14 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_14.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_15 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_15.png")), + (6, 12) +) + + +# ================== # +# === OLD ASSETS === # +# ================== # + +ASSET_MINE_A = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_a.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_B = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_b.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_F = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_f.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_K = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_k.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_ORANGE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_orange.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_RED = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_red.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_BLUE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_blue.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_PURPLE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_purple.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_GREEN = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_green.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_YELLOW = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_yellow.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_WHITE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) diff --git a/display_assets.py b/assets/display_assets.py similarity index 73% rename from display_assets.py rename to assets/display_assets.py index 72060e1..1d05c64 100644 --- a/display_assets.py +++ b/assets/display_assets.py @@ -1,6 +1,7 @@ import pygame import project_constants as const +from assets import asset_constants as asset from mine_models.standard_mine import StandardMine from mine_models.chained_mine import ChainedMine @@ -12,15 +13,15 @@ from mine_models.time_mine import TimeMine # ================================= # tile_asset_options = { - "MUD": const.ASSET_MUD, - "GRASS": const.ASSET_GRASS, - "CONCRETE": const.ASSET_CONCRETE + "MUD": asset.ASSET_MUD, + "GRASS": asset.ASSET_GRASS, + "CONCRETE": asset.ASSET_CONCRETE } mine_asset_options = { - "MINE": const.ASSET_MINE, - "CHAINS": const.ASSET_CHAINS, - "TIME_MINE": const.ASSET_TIME_MINE, + "MINE": asset.ASSET_MINE, + "CHAINS": asset.ASSET_CHAINS, + "TIME_MINE": asset.ASSET_TIME_MINE, } @@ -33,7 +34,7 @@ def blit_graphics(minefield): # background grid (fills frame with white, blits grid) const.SCREEN.fill((255, 255, 255)) const.SCREEN.blit( - const.ASSET_BACKGROUND, + asset.ASSET_BACKGROUND, ( const.V_SCREEN_PADDING, const.V_SCREEN_PADDING @@ -112,22 +113,22 @@ def display_sapper(coords, direction): if direction == const.Direction.UP: const.SCREEN.blit( - const.ASSET_SAPPER, + asset.ASSET_SAPPER, sapper_screen_coords ) elif direction == const.Direction.RIGHT: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 270), + pygame.transform.rotate(asset.ASSET_SAPPER, 270), sapper_screen_coords ) elif direction == const.Direction.DOWN: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 180), + pygame.transform.rotate(asset.ASSET_SAPPER, 180), sapper_screen_coords ) elif direction == const.Direction.LEFT: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 90), + pygame.transform.rotate(asset.ASSET_SAPPER, 90), sapper_screen_coords ) @@ -139,21 +140,21 @@ def display_sapper(coords, direction): def display_concrete(coords): const.SCREEN.blit( - const.ASSET_CONCRETE, + asset.ASSET_CONCRETE, calculate_screen_position(coords) ) def display_mud(coords): const.SCREEN.blit( - const.ASSET_MUD, + asset.ASSET_MUD, calculate_screen_position(coords) ) def display_grass(coords): const.SCREEN.blit( - const.ASSET_GRASS, + asset.ASSET_GRASS, calculate_screen_position(coords) ) @@ -165,7 +166,7 @@ def display_grass(coords): def display_mine(coords): const.SCREEN.blit( - const.ASSET_MINE, + asset.ASSET_MINE, calculate_screen_position(coords) ) @@ -173,35 +174,35 @@ def display_mine(coords): def display_chained_mine(coords, parent_coords=None): def display_number(which_coord, number): - number_asset = const.ASSET_NUMBER_CHAINS_0 + number_asset = asset.ASSET_NUMBER_CHAINS_0 if number == 1: - number_asset = const.ASSET_NUMBER_CHAINS_1 + number_asset = asset.ASSET_NUMBER_CHAINS_1 elif number == 3: - number_asset = const.ASSET_NUMBER_CHAINS_3 + number_asset = asset.ASSET_NUMBER_CHAINS_3 elif number == 4: - number_asset = const.ASSET_NUMBER_CHAINS_4 + number_asset = asset.ASSET_NUMBER_CHAINS_4 elif number == 5: - number_asset = const.ASSET_NUMBER_CHAINS_5 + number_asset = asset.ASSET_NUMBER_CHAINS_5 elif number == 6: - number_asset = const.ASSET_NUMBER_CHAINS_6 + number_asset = asset.ASSET_NUMBER_CHAINS_6 elif number == 7: - number_asset = const.ASSET_NUMBER_CHAINS_7 + number_asset = asset.ASSET_NUMBER_CHAINS_7 elif number == 8: - number_asset = const.ASSET_NUMBER_CHAINS_8 + number_asset = asset.ASSET_NUMBER_CHAINS_8 elif number == 9: - number_asset = const.ASSET_NUMBER_CHAINS_9 + number_asset = asset.ASSET_NUMBER_CHAINS_9 elif number == 10: - number_asset = const.ASSET_NUMBER_CHAINS_10 + number_asset = asset.ASSET_NUMBER_CHAINS_10 elif number == 11: - number_asset = const.ASSET_NUMBER_CHAINS_11 + number_asset = asset.ASSET_NUMBER_CHAINS_11 elif number == 12: - number_asset = const.ASSET_NUMBER_CHAINS_12 + number_asset = asset.ASSET_NUMBER_CHAINS_12 elif number == 13: - number_asset = const.ASSET_NUMBER_CHAINS_13 + number_asset = asset.ASSET_NUMBER_CHAINS_13 elif number == 14: - number_asset = const.ASSET_NUMBER_CHAINS_14 + number_asset = asset.ASSET_NUMBER_CHAINS_14 elif number == 15: - number_asset = const.ASSET_NUMBER_CHAINS_15 + number_asset = asset.ASSET_NUMBER_CHAINS_15 mine_coords = calculate_screen_position(coords) number_coords = mine_coords @@ -218,11 +219,17 @@ def display_chained_mine(coords, parent_coords=None): display_mine(coords) const.SCREEN.blit( - const.ASSET_CHAINS, + asset.ASSET_CHAINS, calculate_screen_position(coords) ) if parent_coords is not None: + + const.SCREEN.blit( + asset.ASSET_CHAIN_COUNTER, + calculate_screen_position(coords) + ) + display_number(const.Coords.X, parent_coords[0]) display_number(const.Coords.Y, parent_coords[1]) @@ -231,25 +238,25 @@ def display_time_mine(coords, time): def display_number(which_digit, number): - number_asset = const.ASSET_NUMBER_TIME_0 + number_asset = asset.ASSET_NUMBER_TIME_0 if number == 1: - number_asset = const.ASSET_NUMBER_TIME_1 + number_asset = asset.ASSET_NUMBER_TIME_1 elif number == 2: - number_asset = const.ASSET_NUMBER_TIME_2 + number_asset = asset.ASSET_NUMBER_TIME_2 elif number == 3: - number_asset = const.ASSET_NUMBER_TIME_3 + number_asset = asset.ASSET_NUMBER_TIME_3 elif number == 4: - number_asset = const.ASSET_NUMBER_TIME_4 + number_asset = asset.ASSET_NUMBER_TIME_4 elif number == 5: - number_asset = const.ASSET_NUMBER_TIME_5 + number_asset = asset.ASSET_NUMBER_TIME_5 elif number == 6: - number_asset = const.ASSET_NUMBER_TIME_6 + number_asset = asset.ASSET_NUMBER_TIME_6 elif number == 7: - number_asset = const.ASSET_NUMBER_TIME_7 + number_asset = asset.ASSET_NUMBER_TIME_7 elif number == 8: - number_asset = const.ASSET_NUMBER_TIME_8 + number_asset = asset.ASSET_NUMBER_TIME_8 elif number == 9: - number_asset = const.ASSET_NUMBER_TIME_9 + number_asset = asset.ASSET_NUMBER_TIME_9 mine_coords = calculate_screen_position(coords) number_coords = mine_coords @@ -264,7 +271,7 @@ def display_time_mine(coords, time): ) const.SCREEN.blit( - const.ASSET_TIME_MINE, + asset.ASSET_TIME_MINE, calculate_screen_position(coords) ) diff --git a/game.py b/game.py index 1000a20..9545f53 100644 --- a/game.py +++ b/game.py @@ -2,7 +2,7 @@ from random import randint import project_constants as const -from display_assets import blit_graphics +from assets.display_assets import blit_graphics from searching_algorithms import a_star from minefield import Minefield diff --git a/project_constants.py b/project_constants.py index 8c72078..b8b15d9 100644 --- a/project_constants.py +++ b/project_constants.py @@ -10,7 +10,7 @@ from ui.input_box import InputBox # STRUCT a list or other structure of values # FUNC a function # OBJ a classes instance -# ASSET a png file (or other graphic format) +# ASSET a png file (or other graphic format) (moved to asset_constants) # MAP a JSON map file @@ -19,9 +19,10 @@ from ui.input_box import InputBox # ================= # V_NAME_OF_WINDOW = "MineFusion TM" -DIR_ASSETS = os.path.join("resources", "assets") V_FPS = 60 +DIR_ASSETS = os.path.join("resources", "assets") + TURN_INTERVAL = 0.3 # interval between two turns in seconds V_TILE_SIZE = 60 @@ -211,248 +212,4 @@ OK_BUTTON = Button( MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json") -# ============== # -# === ASSETS === # -# ============== # -ASSET_BACKGROUND = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), - (650, 650) -) - -ASSET_SAPPER = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_WALL = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_CONCRETE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "concrete.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MUD = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "mud.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_GRASS = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "grass.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "mine.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_CHAINS = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chains.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TIME_MINE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_mine.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -# ==================== # -# === TIME NUMBERS === # -# ==================== # - -ASSET_NUMBER_TIME_0 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_0.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_1 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_1.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_2 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_2.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_3 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_3.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_4 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_4.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_5 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_5.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_6 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_6.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_7 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_7.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_8 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_8.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_9 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_9.png")), - (6, 16) -) - -# ====================== # -# === CHAINS NUMBERS === # -# ====================== # - -ASSET_NUMBER_CHAINS_0 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_0.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_1 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_1.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_2 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_2.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_3 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_3.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_4 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_4.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_5 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_5.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_6 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_6.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_7 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_7.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_8 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_8.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_9 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_9.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_10 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_10.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_11 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_11.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_12 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_12.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_13 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_13.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_14 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_14.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_15 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_15.png")), - (6, 12) -) - -# ================== # -# === OLD ASSETS === # -# ================== # - -ASSET_MINE_A = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_a.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_B = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_b.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_F = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_f.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_K = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_k.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_ORANGE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_orange.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_RED = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_red.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_BLUE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_blue.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_PURPLE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_purple.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_GREEN = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_green.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_YELLOW = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_yellow.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_WHITE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) diff --git a/resources/assets/chains.png b/resources/assets/chains.png index 9a7d67cb6dc1dbc18883e9d16c567cf19586bf31..a4cafbe05bae4c3bf1f2974d4059e1fa6118ebe3 100644 GIT binary patch delta 221 zcmV<303!dz0{8)tBYyzDNkl_zS42^N5H8fQWdEtE!*5@9-HvgaN?J{CvoX0*t-Nk6Ob=hd{+Qv(Yh=T_w%< zgRqFWnK?<>9CRR7Y94F?D?oEcVzuKqyia?)LU{OpnP?PFjaHSVXhPY_viXge4)3bT zo;pr1coVkuc0a!j<8;}(@zZz! X=w7w!N}r_q00000NkvXXu0mjf_Q-7z delta 299 zcmV+`0o4BZ0mTB4BYy!5Nkl64D8^ai7~8M4~a~b9XYs zsJO|xKoW@_`wMHW8C*n+h)6`t$6IR_u`_tYKg2{ts%p`J@dSun#e1&ZLma@&yUA76 znAxu2@u53nyo@Pg<}{^II`iz z9V*TyopE2jp&Dagwj4$r>b?8<$v;HkU1F~|3fmC-RGcZUwOXxph`8IlS@Bn-8pPd> z&R(u0K2#hR_{vl-t?}1%_2qTEY6F?tx$bP6z2-d*zU}ToF|7FR5t!j2u3O_3hknF+ xvb3vx2K=@6K_oNybOZ68#bm6HGf diff --git a/resources/assets/mine.png b/resources/assets/mine.png index 1a42234e8835b59be71e0fc806b7ad8faefdf82d..ad8a727e35130223a12230e94605832584059faa 100644 GIT binary patch delta 159 zcmV;Q0AT;b0mK22Eq}ocfItWY!0XjAtieir*o^(?*O(JnTp*ew;XQ1k9IcHKYF(y7 z>QHds=5A95uz>UdQ1EGhRMdsDP#9;TS3EVXIduf8rbg1<7sspAUKGV$u(mP>{Czm= z<0|=`kkp=5H&@BZj7n{Ool2fXCSG!dQ0}hOV-FpG3Q7a?nivlLs!j?96F;Jocmn_c N002ovPDHLkV1l&?N6P>J delta 159 zcmV;Q0AT;b0mK22Eq_4@fItWZ(78tt-J$!m@BRmRr7LYyw3O)^xin?$X3gb-lil?SEr;b3?)JWR<;&_$Xi=wy-)>h_#zYm9f zTqVB~lG@Yi<|0;mFzB!BNoL_t(YiS3rp34<^c#$Cdb^biEKc+np0MZA@I><-<*5judB zjL=O4$q4n(Au_<%Q-Xh@1#4PS10OH>9^{u7LK4GRZ7b6RWtyOfd_49psyM*wa+0dz zK18wq!ou& z-l%0<8j&B!BctL_t(YiDO_GXmG;A?*9o7yZ=YcwEr*DRR4e5#^C?`09QD^ zZDW8{9G@Ia{HU4sf0+3+u~>21XB13Riw&hG{nwFbhFgRzr#S61Z7epFo&=Xuoc8&@ zjzlxuLb>)^aGI(X!z@Mi8O#Cb;)>Hg)81lOup`GY%`Arb6n`cM3v%Sd1+yH*Qe`#e z|Kwmp=}9Pj#c7{$szsKg*kW=qhQ;RYMl{6)EoPXK49D2`!_#7XG_qspZt;Nmc=!eN z$V%0;!h^5K{C`RVg+^yn-C|g^`2Uo~|D$Hw|No!TfLC$ Date: Sun, 23 May 2021 05:50:49 +0200 Subject: [PATCH 3/5] created package for assets, minor changes to mine assets --- agent.py | 5 +- assets/__init__.py | 0 assets/asset_constants.py | 262 ++++++++++++++++++ display_assets.py => assets/display_assets.py | 91 +++--- game.py | 2 +- project_constants.py | 249 +---------------- resources/assets/chain_counter.png | Bin 0 -> 164 bytes resources/assets/chains.png | Bin 325 -> 248 bytes resources/assets/mine.png | Bin 196 -> 196 bytes resources/assets/old_robo/chains.png | Bin 0 -> 325 bytes resources/assets/old_robo/mine.png | Bin 0 -> 196 bytes resources/assets/old_robo/time_mine.png | Bin 0 -> 301 bytes resources/assets/time_mine.png | Bin 301 -> 296 bytes 13 files changed, 318 insertions(+), 291 deletions(-) create mode 100644 assets/__init__.py create mode 100644 assets/asset_constants.py rename display_assets.py => assets/display_assets.py (73%) create mode 100644 resources/assets/chain_counter.png create mode 100644 resources/assets/old_robo/chains.png create mode 100644 resources/assets/old_robo/mine.png create mode 100644 resources/assets/old_robo/time_mine.png diff --git a/agent.py b/agent.py index ed635e4..bee5fb3 100644 --- a/agent.py +++ b/agent.py @@ -1,4 +1,5 @@ import project_constants as const +from assets import asset_constants as asset import json from pygame import transform @@ -33,10 +34,10 @@ class Agent: coord_x, coord_y = self.on_screen_coordinates[0], self.on_screen_coordinates[1] tl_dimension = const.V_TILE_SIZE / 2 - rotating_rect = transform.rotate(const.ASSET_SAPPER, self.rotation_angle).get_rect() + rotating_rect = transform.rotate(asset.ASSET_SAPPER, self.rotation_angle).get_rect() rotating_rect.center = (coord_x + tl_dimension, coord_y + tl_dimension) - window.blit(transform.rotate(const.ASSET_SAPPER, self.rotation_angle), rotating_rect) + window.blit(transform.rotate(asset.ASSET_SAPPER, self.rotation_angle), rotating_rect) def update(self, delta_time, minefield): self.new_action = self.going_forward + self.rotating_left * 2 + self.rotating_right * 4 diff --git a/assets/__init__.py b/assets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/assets/asset_constants.py b/assets/asset_constants.py new file mode 100644 index 0000000..28d93b0 --- /dev/null +++ b/assets/asset_constants.py @@ -0,0 +1,262 @@ + +import pygame +import os + +import project_constants as c +DIR_ASSETS = c.DIR_ASSETS +V_TILE_SIZE = c.V_TILE_SIZE + + +# ============== # +# === ASSETS === # +# ============== # + +ASSET_BACKGROUND = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), + (650, 650) +) + +ASSET_SAPPER = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_WALL = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CONCRETE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "concrete.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MUD = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "mud.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_GRASS = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "grass.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "mine.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CHAINS = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chains.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_CHAIN_COUNTER = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_counter.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TIME_MINE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_mine.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + + +# ==================== # +# === TIME NUMBERS === # +# ==================== # + +ASSET_NUMBER_TIME_0 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_0.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_1 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_1.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_2 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_2.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_3 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_3.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_4 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_4.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_5 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_5.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_6 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_6.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_7 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_7.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_8 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_8.png")), + (6, 16) +) + +ASSET_NUMBER_TIME_9 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_9.png")), + (6, 16) +) + + +# ====================== # +# === CHAINS NUMBERS === # +# ====================== # + +ASSET_NUMBER_CHAINS_0 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_0.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_1 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_1.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_2 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_2.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_3 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_3.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_4 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_4.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_5 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_5.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_6 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_6.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_7 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_7.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_8 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_8.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_9 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_9.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_10 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_10.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_11 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_11.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_12 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_12.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_13 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_13.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_14 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_14.png")), + (6, 12) +) + +ASSET_NUMBER_CHAINS_15 = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_15.png")), + (6, 12) +) + + +# ================== # +# === OLD ASSETS === # +# ================== # + +ASSET_MINE_A = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_a.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_B = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_b.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_F = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_f.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_MINE_K = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_k.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_ORANGE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_orange.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_RED = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_red.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_BLUE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_blue.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_PURPLE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_purple.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_GREEN = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_green.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_YELLOW = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_yellow.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) + +ASSET_TILE_WHITE = pygame.transform.scale( + pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")), + (V_TILE_SIZE, V_TILE_SIZE) +) diff --git a/display_assets.py b/assets/display_assets.py similarity index 73% rename from display_assets.py rename to assets/display_assets.py index 72060e1..1d05c64 100644 --- a/display_assets.py +++ b/assets/display_assets.py @@ -1,6 +1,7 @@ import pygame import project_constants as const +from assets import asset_constants as asset from mine_models.standard_mine import StandardMine from mine_models.chained_mine import ChainedMine @@ -12,15 +13,15 @@ from mine_models.time_mine import TimeMine # ================================= # tile_asset_options = { - "MUD": const.ASSET_MUD, - "GRASS": const.ASSET_GRASS, - "CONCRETE": const.ASSET_CONCRETE + "MUD": asset.ASSET_MUD, + "GRASS": asset.ASSET_GRASS, + "CONCRETE": asset.ASSET_CONCRETE } mine_asset_options = { - "MINE": const.ASSET_MINE, - "CHAINS": const.ASSET_CHAINS, - "TIME_MINE": const.ASSET_TIME_MINE, + "MINE": asset.ASSET_MINE, + "CHAINS": asset.ASSET_CHAINS, + "TIME_MINE": asset.ASSET_TIME_MINE, } @@ -33,7 +34,7 @@ def blit_graphics(minefield): # background grid (fills frame with white, blits grid) const.SCREEN.fill((255, 255, 255)) const.SCREEN.blit( - const.ASSET_BACKGROUND, + asset.ASSET_BACKGROUND, ( const.V_SCREEN_PADDING, const.V_SCREEN_PADDING @@ -112,22 +113,22 @@ def display_sapper(coords, direction): if direction == const.Direction.UP: const.SCREEN.blit( - const.ASSET_SAPPER, + asset.ASSET_SAPPER, sapper_screen_coords ) elif direction == const.Direction.RIGHT: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 270), + pygame.transform.rotate(asset.ASSET_SAPPER, 270), sapper_screen_coords ) elif direction == const.Direction.DOWN: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 180), + pygame.transform.rotate(asset.ASSET_SAPPER, 180), sapper_screen_coords ) elif direction == const.Direction.LEFT: const.SCREEN.blit( - pygame.transform.rotate(const.ASSET_SAPPER, 90), + pygame.transform.rotate(asset.ASSET_SAPPER, 90), sapper_screen_coords ) @@ -139,21 +140,21 @@ def display_sapper(coords, direction): def display_concrete(coords): const.SCREEN.blit( - const.ASSET_CONCRETE, + asset.ASSET_CONCRETE, calculate_screen_position(coords) ) def display_mud(coords): const.SCREEN.blit( - const.ASSET_MUD, + asset.ASSET_MUD, calculate_screen_position(coords) ) def display_grass(coords): const.SCREEN.blit( - const.ASSET_GRASS, + asset.ASSET_GRASS, calculate_screen_position(coords) ) @@ -165,7 +166,7 @@ def display_grass(coords): def display_mine(coords): const.SCREEN.blit( - const.ASSET_MINE, + asset.ASSET_MINE, calculate_screen_position(coords) ) @@ -173,35 +174,35 @@ def display_mine(coords): def display_chained_mine(coords, parent_coords=None): def display_number(which_coord, number): - number_asset = const.ASSET_NUMBER_CHAINS_0 + number_asset = asset.ASSET_NUMBER_CHAINS_0 if number == 1: - number_asset = const.ASSET_NUMBER_CHAINS_1 + number_asset = asset.ASSET_NUMBER_CHAINS_1 elif number == 3: - number_asset = const.ASSET_NUMBER_CHAINS_3 + number_asset = asset.ASSET_NUMBER_CHAINS_3 elif number == 4: - number_asset = const.ASSET_NUMBER_CHAINS_4 + number_asset = asset.ASSET_NUMBER_CHAINS_4 elif number == 5: - number_asset = const.ASSET_NUMBER_CHAINS_5 + number_asset = asset.ASSET_NUMBER_CHAINS_5 elif number == 6: - number_asset = const.ASSET_NUMBER_CHAINS_6 + number_asset = asset.ASSET_NUMBER_CHAINS_6 elif number == 7: - number_asset = const.ASSET_NUMBER_CHAINS_7 + number_asset = asset.ASSET_NUMBER_CHAINS_7 elif number == 8: - number_asset = const.ASSET_NUMBER_CHAINS_8 + number_asset = asset.ASSET_NUMBER_CHAINS_8 elif number == 9: - number_asset = const.ASSET_NUMBER_CHAINS_9 + number_asset = asset.ASSET_NUMBER_CHAINS_9 elif number == 10: - number_asset = const.ASSET_NUMBER_CHAINS_10 + number_asset = asset.ASSET_NUMBER_CHAINS_10 elif number == 11: - number_asset = const.ASSET_NUMBER_CHAINS_11 + number_asset = asset.ASSET_NUMBER_CHAINS_11 elif number == 12: - number_asset = const.ASSET_NUMBER_CHAINS_12 + number_asset = asset.ASSET_NUMBER_CHAINS_12 elif number == 13: - number_asset = const.ASSET_NUMBER_CHAINS_13 + number_asset = asset.ASSET_NUMBER_CHAINS_13 elif number == 14: - number_asset = const.ASSET_NUMBER_CHAINS_14 + number_asset = asset.ASSET_NUMBER_CHAINS_14 elif number == 15: - number_asset = const.ASSET_NUMBER_CHAINS_15 + number_asset = asset.ASSET_NUMBER_CHAINS_15 mine_coords = calculate_screen_position(coords) number_coords = mine_coords @@ -218,11 +219,17 @@ def display_chained_mine(coords, parent_coords=None): display_mine(coords) const.SCREEN.blit( - const.ASSET_CHAINS, + asset.ASSET_CHAINS, calculate_screen_position(coords) ) if parent_coords is not None: + + const.SCREEN.blit( + asset.ASSET_CHAIN_COUNTER, + calculate_screen_position(coords) + ) + display_number(const.Coords.X, parent_coords[0]) display_number(const.Coords.Y, parent_coords[1]) @@ -231,25 +238,25 @@ def display_time_mine(coords, time): def display_number(which_digit, number): - number_asset = const.ASSET_NUMBER_TIME_0 + number_asset = asset.ASSET_NUMBER_TIME_0 if number == 1: - number_asset = const.ASSET_NUMBER_TIME_1 + number_asset = asset.ASSET_NUMBER_TIME_1 elif number == 2: - number_asset = const.ASSET_NUMBER_TIME_2 + number_asset = asset.ASSET_NUMBER_TIME_2 elif number == 3: - number_asset = const.ASSET_NUMBER_TIME_3 + number_asset = asset.ASSET_NUMBER_TIME_3 elif number == 4: - number_asset = const.ASSET_NUMBER_TIME_4 + number_asset = asset.ASSET_NUMBER_TIME_4 elif number == 5: - number_asset = const.ASSET_NUMBER_TIME_5 + number_asset = asset.ASSET_NUMBER_TIME_5 elif number == 6: - number_asset = const.ASSET_NUMBER_TIME_6 + number_asset = asset.ASSET_NUMBER_TIME_6 elif number == 7: - number_asset = const.ASSET_NUMBER_TIME_7 + number_asset = asset.ASSET_NUMBER_TIME_7 elif number == 8: - number_asset = const.ASSET_NUMBER_TIME_8 + number_asset = asset.ASSET_NUMBER_TIME_8 elif number == 9: - number_asset = const.ASSET_NUMBER_TIME_9 + number_asset = asset.ASSET_NUMBER_TIME_9 mine_coords = calculate_screen_position(coords) number_coords = mine_coords @@ -264,7 +271,7 @@ def display_time_mine(coords, time): ) const.SCREEN.blit( - const.ASSET_TIME_MINE, + asset.ASSET_TIME_MINE, calculate_screen_position(coords) ) diff --git a/game.py b/game.py index 1000a20..9545f53 100644 --- a/game.py +++ b/game.py @@ -2,7 +2,7 @@ from random import randint import project_constants as const -from display_assets import blit_graphics +from assets.display_assets import blit_graphics from searching_algorithms import a_star from minefield import Minefield diff --git a/project_constants.py b/project_constants.py index 8c72078..b8b15d9 100644 --- a/project_constants.py +++ b/project_constants.py @@ -10,7 +10,7 @@ from ui.input_box import InputBox # STRUCT a list or other structure of values # FUNC a function # OBJ a classes instance -# ASSET a png file (or other graphic format) +# ASSET a png file (or other graphic format) (moved to asset_constants) # MAP a JSON map file @@ -19,9 +19,10 @@ from ui.input_box import InputBox # ================= # V_NAME_OF_WINDOW = "MineFusion TM" -DIR_ASSETS = os.path.join("resources", "assets") V_FPS = 60 +DIR_ASSETS = os.path.join("resources", "assets") + TURN_INTERVAL = 0.3 # interval between two turns in seconds V_TILE_SIZE = 60 @@ -211,248 +212,4 @@ OK_BUTTON = Button( MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json") -# ============== # -# === ASSETS === # -# ============== # -ASSET_BACKGROUND = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), - (650, 650) -) - -ASSET_SAPPER = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_WALL = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_CONCRETE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "concrete.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MUD = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "mud.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_GRASS = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "grass.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "mine.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_CHAINS = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chains.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TIME_MINE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_mine.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -# ==================== # -# === TIME NUMBERS === # -# ==================== # - -ASSET_NUMBER_TIME_0 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_0.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_1 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_1.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_2 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_2.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_3 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_3.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_4 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_4.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_5 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_5.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_6 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_6.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_7 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_7.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_8 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_8.png")), - (6, 16) -) - -ASSET_NUMBER_TIME_9 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_9.png")), - (6, 16) -) - -# ====================== # -# === CHAINS NUMBERS === # -# ====================== # - -ASSET_NUMBER_CHAINS_0 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_0.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_1 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_1.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_2 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_2.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_3 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_3.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_4 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_4.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_5 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_5.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_6 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_6.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_7 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_7.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_8 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_8.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_9 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_9.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_10 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_10.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_11 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_11.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_12 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_12.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_13 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_13.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_14 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_14.png")), - (6, 12) -) - -ASSET_NUMBER_CHAINS_15 = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_15.png")), - (6, 12) -) - -# ================== # -# === OLD ASSETS === # -# ================== # - -ASSET_MINE_A = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_a.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_B = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_b.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_F = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_f.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_MINE_K = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_k.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_ORANGE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_orange.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_RED = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_red.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_BLUE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_blue.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_PURPLE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_purple.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_GREEN = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_green.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_YELLOW = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_yellow.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) - -ASSET_TILE_WHITE = pygame.transform.scale( - pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")), - (V_TILE_SIZE, V_TILE_SIZE) -) diff --git a/resources/assets/chain_counter.png b/resources/assets/chain_counter.png new file mode 100644 index 0000000000000000000000000000000000000000..c4be0afb7203b93ec25de6b0e8434afd9b1c8b19 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3*`6+rAs(G?r(WbdV8G#GJbU&X zfpw2pebZKGb;!QtHM_b%K;=U~Q)cgkw*jH?fy*m8I(BsISXE_zJZA0kqnkau&+1IQ zS9>O)Y@da8-I8Pmz6Z61k;i4e*2k6JWSSW}d;8IewRJ0s3>D`;VmQ3X(UMJmVHeO^ N22WQ%mvv4FO#m#5KbZgk literal 0 HcmV?d00001 diff --git a/resources/assets/chains.png b/resources/assets/chains.png index 9a7d67cb6dc1dbc18883e9d16c567cf19586bf31..a4cafbe05bae4c3bf1f2974d4059e1fa6118ebe3 100644 GIT binary patch delta 221 zcmV<303!dz0{8)tBYyzDNkl_zS42^N5H8fQWdEtE!*5@9-HvgaN?J{CvoX0*t-Nk6Ob=hd{+Qv(Yh=T_w%< zgRqFWnK?<>9CRR7Y94F?D?oEcVzuKqyia?)LU{OpnP?PFjaHSVXhPY_viXge4)3bT zo;pr1coVkuc0a!j<8;}(@zZz! X=w7w!N}r_q00000NkvXXu0mjf_Q-7z delta 299 zcmV+`0o4BZ0mTB4BYy!5Nkl64D8^ai7~8M4~a~b9XYs zsJO|xKoW@_`wMHW8C*n+h)6`t$6IR_u`_tYKg2{ts%p`J@dSun#e1&ZLma@&yUA76 znAxu2@u53nyo@Pg<}{^II`iz z9V*TyopE2jp&Dagwj4$r>b?8<$v;HkU1F~|3fmC-RGcZUwOXxph`8IlS@Bn-8pPd> z&R(u0K2#hR_{vl-t?}1%_2qTEY6F?tx$bP6z2-d*zU}ToF|7FR5t!j2u3O_3hknF+ xvb3vx2K=@6K_oNybOZ68#bm6HGf diff --git a/resources/assets/mine.png b/resources/assets/mine.png index 1a42234e8835b59be71e0fc806b7ad8faefdf82d..ad8a727e35130223a12230e94605832584059faa 100644 GIT binary patch delta 159 zcmV;Q0AT;b0mK22Eq}ocfItWY!0XjAtieir*o^(?*O(JnTp*ew;XQ1k9IcHKYF(y7 z>QHds=5A95uz>UdQ1EGhRMdsDP#9;TS3EVXIduf8rbg1<7sspAUKGV$u(mP>{Czm= z<0|=`kkp=5H&@BZj7n{Ool2fXCSG!dQ0}hOV-FpG3Q7a?nivlLs!j?96F;Jocmn_c N002ovPDHLkV1l&?N6P>J delta 159 zcmV;Q0AT;b0mK22Eq_4@fItWZ(78tt-J$!m@BRmRr7LYyw3O)^xin?$X3gb-lil?SEr;b3?)JWR<;&_$Xi=wy-)>h_#zYm9f zTqVB~lG@Yi<|64D8^ai7~8M4~a~b9XYssJO|xKoW@_`wMHW8C*n+h)6`t$6IR_ zu`_tYKg2{ts%p`J@dSun#e1&ZLma@&yUA76nAxu2@u53nyo@Pg<}{^n z?rfXA<~HrpyJ^%_n z4Umeua25*VO!SJUrZuOIK-JVp+WX>omD-D_8H6p=;Dgg zKGWV}Sg<30;mFzB!BNoL_t(YiS3rp34<^c#$Cdb^biEKc+np0MZA@I><-<*5judB zjL=O4$q4n(Au_<%Q-Xh@1#4PS10OH>9^{u7LK4GRZ7b6RWtyOfd_49psyM*wa+0dz zK18wq!ou& z-l%0<8j&B!BctL_t(YiDO_GXmG;A?*9o7yZ=YcwEr*DRR4e5#^C?`09QD^ zZDW8{9G@Ia{HU4sf0+3+u~>21XB13Riw&hG{nwFbhFgRzr#S61Z7epFo&=Xuoc8&@ zjzlxuLb>)^aGI(X!z@Mi8O#Cb;)>Hg)81lOup`GY%`Arb6n`cM3v%Sd1+yH*Qe`#e z|Kwmp=}9Pj#c7{$szsKg*kW=qhQ;RYMl{6)EoPXK49D2`!_#7XG_qspZt;Nmc=!eN z$V%0;!h^5K{C`RVg+^yn-C|g^`2Uo~|D$Hw|No!TfLC$ Date: Sun, 23 May 2021 06:14:12 +0200 Subject: [PATCH 4/5] created a package for objects, changed ui into a package --- assets/display_assets.py | 6 +++--- game.py | 4 ++-- json_generator.py | 8 ++++---- minefield.py | 5 ++--- objects/__init__.py | 0 agent.py => objects/agent.py | 0 objects/mines/__init__.py | 0 {mine_models => objects/mines}/chained_mine.py | 0 {mine_models => objects/mines}/mine.py | 0 {mine_models => objects/mines}/standard_mine.py | 0 {mine_models => objects/mines}/time_mine.py | 0 tile.py => objects/tile.py | 0 project_constants.py | 2 +- ui/__init__.py | 0 14 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 objects/__init__.py rename agent.py => objects/agent.py (100%) create mode 100644 objects/mines/__init__.py rename {mine_models => objects/mines}/chained_mine.py (100%) rename {mine_models => objects/mines}/mine.py (100%) rename {mine_models => objects/mines}/standard_mine.py (100%) rename {mine_models => objects/mines}/time_mine.py (100%) rename tile.py => objects/tile.py (100%) create mode 100644 ui/__init__.py diff --git a/assets/display_assets.py b/assets/display_assets.py index 1d05c64..3f81db5 100644 --- a/assets/display_assets.py +++ b/assets/display_assets.py @@ -3,9 +3,9 @@ import pygame import project_constants as const from assets import asset_constants as asset -from mine_models.standard_mine import StandardMine -from mine_models.chained_mine import ChainedMine -from mine_models.time_mine import TimeMine +from objects.mines.standard_mine import StandardMine +from objects.mines.chained_mine import ChainedMine +from objects.mines.time_mine import TimeMine # ================================= # diff --git a/game.py b/game.py index 9545f53..929a4cc 100644 --- a/game.py +++ b/game.py @@ -7,7 +7,7 @@ from searching_algorithms import a_star from minefield import Minefield -from mine_models.time_mine import TimeMine +from objects.mines.time_mine import TimeMine from ui.ui_components_manager import UiComponentsManager from ui.text_box import TextBox @@ -187,7 +187,7 @@ class Game: self.minefield = self.initial_minefield.__copy__() self.agent = self.initial_minefield.agent - # initializes ui components and assigns them to attributes + # initializes old ui components and assigns them to attributes def initialize_gui_components(self): # calculating in game gui coordinates gui_width = const.V_SIDE_MENU_WIDTH diff --git a/json_generator.py b/json_generator.py index 601cbbd..34f594a 100644 --- a/json_generator.py +++ b/json_generator.py @@ -4,12 +4,12 @@ import random import project_constants as const # import tile class -from tile import Tile +from objects.tile import Tile # import mine models -from mine_models.standard_mine import StandardMine -from mine_models.time_mine import TimeMine -from mine_models.chained_mine import ChainedMine +from objects.mines.standard_mine import StandardMine +from objects.mines.time_mine import TimeMine +from objects.mines.chained_mine import ChainedMine class JsonGenerator: diff --git a/minefield.py b/minefield.py index 58ffa38..61ecf3a 100644 --- a/minefield.py +++ b/minefield.py @@ -1,7 +1,6 @@ -import agent as ag import project_constants as const -import tile as tl -from mine_models.time_mine import TimeMine +from objects import tile as tl, agent as ag +from objects.mines.time_mine import TimeMine import json_generator as jg diff --git a/objects/__init__.py b/objects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/agent.py b/objects/agent.py similarity index 100% rename from agent.py rename to objects/agent.py diff --git a/objects/mines/__init__.py b/objects/mines/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mine_models/chained_mine.py b/objects/mines/chained_mine.py similarity index 100% rename from mine_models/chained_mine.py rename to objects/mines/chained_mine.py diff --git a/mine_models/mine.py b/objects/mines/mine.py similarity index 100% rename from mine_models/mine.py rename to objects/mines/mine.py diff --git a/mine_models/standard_mine.py b/objects/mines/standard_mine.py similarity index 100% rename from mine_models/standard_mine.py rename to objects/mines/standard_mine.py diff --git a/mine_models/time_mine.py b/objects/mines/time_mine.py similarity index 100% rename from mine_models/time_mine.py rename to objects/mines/time_mine.py diff --git a/tile.py b/objects/tile.py similarity index 100% rename from tile.py rename to objects/tile.py diff --git a/project_constants.py b/project_constants.py index b8b15d9..808d2d2 100644 --- a/project_constants.py +++ b/project_constants.py @@ -150,7 +150,7 @@ def get_tile_coordinates(position): # initializing pygame modules so all instances can be constructed properly pygame.init() -# creating ui components used in menu +# creating old ui components used in menu HIGHLIGHT = pygame.transform.scale( pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")), (V_TILE_SIZE, V_TILE_SIZE) diff --git a/ui/__init__.py b/ui/__init__.py new file mode 100644 index 0000000..e69de29 From cfe686ca247faba3707811dd32e78d7767b3bf7c Mon Sep 17 00:00:00 2001 From: s452645 Date: Sun, 23 May 2021 08:43:31 +0200 Subject: [PATCH 5/5] implemented auto-mode --- game.py | 17 +++++++++++++++-- main.py | 19 +++++++++++++++++-- searching_algorithms/a_star.py | 4 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/game.py b/game.py index 1000a20..9e34c6d 100644 --- a/game.py +++ b/game.py @@ -1,4 +1,4 @@ -from random import randint +from random import choice, randint import project_constants as const @@ -112,8 +112,20 @@ class Game: def get_turn_number(self): return self.turn + # draws a random mine to disarm (in auto mode) + def set_random_mine_as_target(self): + self.goal = choice(self.minefield.get_active_mines()).position + + # display new destination + self.input_box_row.set_texts(user_input=str(self.goal[0])) + self.input_box_column.set_texts(user_input=str(self.goal[1])) + + # prevents highlighting input_box_row, + # couldn't find any better solution w/o major Game class changes + self.input_box_row.set_is_selected(False) + # gets action sequence for agent - def get_action_sequence(self): + def get_action_sequence(self, target_type: str = "tile"): return a_star.graphsearch( initial_state=a_star.State( row=self.agent.row, @@ -121,6 +133,7 @@ class Game: direction=self.agent.direction ), minefield=self.minefield, + target_type=target_type, tox=self.goal[0], toy=self.goal[1] ) diff --git a/main.py b/main.py index 3da6402..6c19ad1 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,7 @@ def main(): # setting flags for program running = True in_menu = True + auto = False is_game_over = False # create and initialize_gui_components game instance @@ -38,7 +39,7 @@ def main(): # ==== MENU ==== # # ============== # - while running and in_menu: + while running and in_menu and not auto: events = pygame.event.get() # checking if game should stop running @@ -59,12 +60,21 @@ def main(): # if ok button is clicked then leave menu section in_menu = not game.button_ok.is_clicked(pygame.mouse.get_pos(), events) + # if auto button is clicked then leave menu and start auto-mode + auto = game.button_auto.is_clicked(pygame.mouse.get_pos(), events) + # ========================== # # ==== BEFORE GAME LOOP ==== # # ========================== # # getting action sequence for agent - action_sequence = game.get_action_sequence() + if auto: + in_menu = False + game.set_random_mine_as_target() + action_sequence = game.get_action_sequence("mine") + + else: + action_sequence = game.get_action_sequence("tile") # initializing game attributes before the game loop game.initialize_before_game_loop() @@ -88,6 +98,11 @@ def main(): # drawing minefield and agent instances game.draw_minefield() + # handling auto button (clicking quits auto-mode) + if auto: + game.button_auto.set_flags(is_active=True) + auto = not game.button_auto.is_clicked(pygame.mouse.get_pos(), events) + # drawing inactive gui components so they don't "disappear" game.run_in_game_menu_overlay(pygame.mouse.get_pos(), events) game.set_is_active_flag_for_all_in_game_gui_components(False) diff --git a/searching_algorithms/a_star.py b/searching_algorithms/a_star.py index 5c42f66..227c1ad 100644 --- a/searching_algorithms/a_star.py +++ b/searching_algorithms/a_star.py @@ -111,6 +111,10 @@ def graphsearch(initial_state: State, goal_test = mine_goal_test else: goal_test = tile_goal_test + if minefield.matrix[GOAL[0]][GOAL[1]].mine is not None and minefield.matrix[GOAL[0]][GOAL[1]].mine.active: + # TODO: cross-platform popup, move to separate function + ctypes.windll.user32.MessageBoxW(0, "Brak rozwiązania", "GAME OVER", 1) + return [] # fringe and explored initialization if fringe is None: