minor Minefield changes

This commit is contained in:
s452645 2021-04-11 19:29:12 +02:00
parent edca418fed
commit c2a80c56ab

View File

@ -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