From d47e46313c5da9d8667c5f5a813abb41d2647974 Mon Sep 17 00:00:00 2001 From: s452635 Date: Sun, 2 May 2021 21:04:41 +0200 Subject: [PATCH] added coords to background --- display_assets.py | 4 +- main.py | 12 +++-- minefield.py | 4 +- project_constants.py | 46 +++++++++--------- resources/assets/chained_mine.png | Bin 406 -> 0 bytes resources/assets/numbered_grid.png | Bin 0 -> 903 bytes .../assets/{ => simple assets}/mine_a.png | Bin .../assets/{ => simple assets}/mine_b.png | Bin .../assets/{ => simple assets}/mine_f.png | Bin .../assets/{ => simple assets}/mine_k.png | Bin .../assets/{ => simple assets}/sapper.png | Bin searching_algorithms/bfs.py | 2 +- 12 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 resources/assets/chained_mine.png create mode 100644 resources/assets/numbered_grid.png rename resources/assets/{ => simple assets}/mine_a.png (100%) rename resources/assets/{ => simple assets}/mine_b.png (100%) rename resources/assets/{ => simple assets}/mine_f.png (100%) rename resources/assets/{ => simple assets}/mine_k.png (100%) rename resources/assets/{ => simple assets}/sapper.png (100%) diff --git a/display_assets.py b/display_assets.py index 54b40e4..62fbcfd 100644 --- a/display_assets.py +++ b/display_assets.py @@ -7,8 +7,8 @@ import project_constants as const def calculate_screen_position(row, column): coords = ( - const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, - const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, ) return coords diff --git a/main.py b/main.py index 802d310..7cefe05 100644 --- a/main.py +++ b/main.py @@ -25,11 +25,13 @@ def main(): # create an instance of Minefield, pass necessary data minefield = mf.Minefield(const.MAP_RANDOM_10x10) - # get sequence of actions found by BFS algorythm - action_sequence = bfs.graphsearch(initial_state=bfs.State(row=minefield.agent.position[0], - column=minefield.agent.position[1], - direction=const.Direction.UP), - minefield=minefield) + # get sequence of actions found by BFS algorithm + action_sequence = bfs.graphsearch( + initial_state=bfs.State( + row=minefield.agent.position[0], + column=minefield.agent.position[1], + direction=const.Direction.UP), + minefield=minefield) running = True while running: diff --git a/minefield.py b/minefield.py index d82c039..070b7fb 100644 --- a/minefield.py +++ b/minefield.py @@ -59,8 +59,8 @@ class Minefield: @staticmethod def calculate_screen_position(row, column): coords = ( - const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, - const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, ) return coords diff --git a/project_constants.py b/project_constants.py index c9447c8..b49d62f 100644 --- a/project_constants.py +++ b/project_constants.py @@ -14,21 +14,23 @@ from enum import Enum # ================= # V_NAME_OF_WINDOW = "MineFusion TM" -ASSETS_DIR = os.path.join("resources", "assets") +DIR_ASSETS = os.path.join("resources", "assets") V_FPS = 60 ACTION_INTERVAL = 1 # interval between two actions in seconds V_TILE_SIZE = 60 -V_GRID_VER_TILES = V_GRID_HOR_TILES = 10 # vertical (number of rows), horizontal (number of columns) +V_GRID_VER_TILES = 10 # vertical (number of rows) +V_GRID_HOR_TILES = 10 # horizontal (number of columns) V_SCREEN_PADDING = 10 -V_WINDOW_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES -V_WINDOW_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES +V_NUMBER_PADDING = 50 +V_TILE_AREA_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES +V_TILE_AREA_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES SCREEN = pygame.display.set_mode( ( - V_TILE_SIZE * V_GRID_HOR_TILES + 2 * V_SCREEN_PADDING, # screen width - V_TILE_SIZE * V_GRID_HOR_TILES + 2 * V_SCREEN_PADDING # screen height + V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING, # screen width + V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING # screen height ) ) @@ -48,7 +50,7 @@ class Direction(Enum): v = (self.value + 1) % 4 return Direction(v) - def previous (self): + def previous(self): v = (self.value - 1) % 4 return Direction(v) @@ -113,71 +115,71 @@ MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "secondmap.json") # ============== # ASSET_BACKGROUND = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "new_grid.png")), - (V_WINDOW_WIDTH, V_WINDOW_WIDTH) + pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), + (650, 650) ) ASSET_SAPPER = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "robot_sapper.png")), + 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(ASSETS_DIR, "brick_wall.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_MINE_A = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "mine_a.png")), + 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(ASSETS_DIR, "mine_b.png")), + 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(ASSETS_DIR, "mine_f.png")), + 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(ASSETS_DIR, "mine_k.png")), + 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(ASSETS_DIR, "tile_orange.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_orange.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_RED = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_red.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_red.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_BLUE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_blue.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_blue.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_PURPLE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_purple.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_purple.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_GREEN = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_green.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_green.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_YELLOW = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_yellow.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_yellow.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_WHITE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_white.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_white.png")), (V_TILE_SIZE, V_TILE_SIZE) ) diff --git a/resources/assets/chained_mine.png b/resources/assets/chained_mine.png deleted file mode 100644 index 5a5abbca33114806400eae36572956bc5aeeabc7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 406 zcmV;H0crk;P)J;Q8#Bv(u44I@b8CAhcFwt!l9YfVO#s_F|K-@S zkdmu<(Le0xDnw)w5Rti{mOq45#P}Fvl;zlRScu3BDeUDIwEV$wA!cStDP<>}G*DLJ z6FU+P;w~elbje)ry?F11i1M?>s2$PJ;<}2hN$&u}%dyp=M*Ok2n%FuHBY=7h%zq(X zj;(ThN~{%YVHGh#F`_txAR&Yy;&Ll5#QNi`P=gr7#w@2$49A(oUB&u<&kps}J^nRW z{qZ@TRX}c4t|w(vHwn#JjqHAMAz1cd#ZRw5?XMH6dmqoZ^tFGP$rZ5ODs0rf523?3)`|mE>V!QR{l(6&LS?j%8 zwoIN>uKi@cLH53orY*jF|Ib?6sK5SpT}E)1VB&8E)tr~yk-uD`-|v577}Y!Db#77I zfd)wLhJn!`UkZg^g zGEV%?Gxuy|`^mQFvOAJFE`m=OT_^NMWKUpUV|v29ESp!)u>W{;$)x&k-;GQvG9+ew zPYIMO_@#krJxJSrXHUCLyZa_gUM=qMMEa`Kw|zS-|L!f{UF8|FFK}(5Zj!v-Yt7Du0Y~DY8;X!AhYjIg^Q9Gr7#{w08nLlP*yw5!T zAm8oRWx)4dHUCosP>bO5{!a}`C)`CGk;16(mj*vDdO%SG42^A%*P8a6tj?IgzR$wF op?WUQN$c7v=O2hV$~DMGWPM!5bjxlXFoQ98y85}Sb4q9e0El3tdjJ3c literal 0 HcmV?d00001 diff --git a/resources/assets/mine_a.png b/resources/assets/simple assets/mine_a.png similarity index 100% rename from resources/assets/mine_a.png rename to resources/assets/simple assets/mine_a.png diff --git a/resources/assets/mine_b.png b/resources/assets/simple assets/mine_b.png similarity index 100% rename from resources/assets/mine_b.png rename to resources/assets/simple assets/mine_b.png diff --git a/resources/assets/mine_f.png b/resources/assets/simple assets/mine_f.png similarity index 100% rename from resources/assets/mine_f.png rename to resources/assets/simple assets/mine_f.png diff --git a/resources/assets/mine_k.png b/resources/assets/simple assets/mine_k.png similarity index 100% rename from resources/assets/mine_k.png rename to resources/assets/simple assets/mine_k.png diff --git a/resources/assets/sapper.png b/resources/assets/simple assets/sapper.png similarity index 100% rename from resources/assets/sapper.png rename to resources/assets/simple assets/sapper.png diff --git a/searching_algorithms/bfs.py b/searching_algorithms/bfs.py index 309c2be..c93dca0 100644 --- a/searching_algorithms/bfs.py +++ b/searching_algorithms/bfs.py @@ -6,7 +6,7 @@ from project_constants import Direction, Action from minefield import Minefield # temporary goal for testing -GOAL = (13, 9) +GOAL = (9, 9) class State: