From c2a80c56ab157a2237f31045595091c28f37944e Mon Sep 17 00:00:00 2001 From: s452645 Date: Sun, 11 Apr 2021 19:29:12 +0200 Subject: [PATCH] minor Minefield changes --- minefield.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/minefield.py b/minefield.py index 4b431dc..f7227b8 100644 --- a/minefield.py +++ b/minefield.py @@ -26,15 +26,6 @@ mine_asset_options = { } -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, - ) - - return coords - - class Minefield: def __init__(self, json_path): self.turn = 0 @@ -66,13 +57,22 @@ class Minefield: self.matrix[row][column].color = tile_data["color"].upper() + @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, + ) + + return coords + def draw(self, window): # iterate through tiles for row in self.matrix: for tile in row: # calculate tile position on the screen - tile_screen_coords = calculate_screen_position(tile.position[0], tile.position[1]) + tile_screen_coords = self.calculate_screen_position(tile.position[0], tile.position[1]) # draw a tile window.blit(tile_asset_options.get(tile.color), tile_screen_coords) @@ -84,7 +84,7 @@ class Minefield: 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]) + sapper_screen_coords = self.calculate_screen_position(self.agent.position[0], self.agent.position[1]) window.blit(const.ASSET_SAPPER, sapper_screen_coords) # ================ # @@ -118,7 +118,7 @@ class Minefield: elif mine_type == "chained": if mine_data["predecessor"] is not None: # locate predecessor - x, y = map(int, mine_data["predecessor"].split(',')) + row, column = map(int, mine_data["predecessor"].split(',')) # get predecessor object and assign it to the new mine predecessor = self.matrix[row][column].mine