Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9e429dff9f
24
minefield.py
24
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:
|
class Minefield:
|
||||||
def __init__(self, json_path):
|
def __init__(self, json_path):
|
||||||
self.turn = 0
|
self.turn = 0
|
||||||
@ -66,13 +57,22 @@ class Minefield:
|
|||||||
|
|
||||||
self.matrix[row][column].color = tile_data["color"].upper()
|
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):
|
def draw(self, window):
|
||||||
# iterate through tiles
|
# iterate through tiles
|
||||||
for row in self.matrix:
|
for row in self.matrix:
|
||||||
for tile in row:
|
for tile in row:
|
||||||
|
|
||||||
# calculate tile position on the screen
|
# 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
|
# draw a tile
|
||||||
window.blit(tile_asset_options.get(tile.color), tile_screen_coords)
|
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)
|
window.blit(mine_asset_options['A'], tile_screen_coords)
|
||||||
|
|
||||||
# draw the sapper
|
# 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)
|
window.blit(const.ASSET_SAPPER, sapper_screen_coords)
|
||||||
|
|
||||||
# ================ #
|
# ================ #
|
||||||
@ -118,7 +118,7 @@ class Minefield:
|
|||||||
elif mine_type == "chained":
|
elif mine_type == "chained":
|
||||||
if mine_data["predecessor"] is not None:
|
if mine_data["predecessor"] is not None:
|
||||||
# locate predecessor
|
# 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
|
# get predecessor object and assign it to the new mine
|
||||||
predecessor = self.matrix[row][column].mine
|
predecessor = self.matrix[row][column].mine
|
||||||
|
Loading…
Reference in New Issue
Block a user