Fix
This commit is contained in:
34
game/game.py
34
game/game.py
@@ -26,49 +26,49 @@ class Minesweeper:
|
|||||||
"""Put a single mine on the board.
|
"""Put a single mine on the board.
|
||||||
The mine have a -1 value just for reference
|
The mine have a -1 value just for reference
|
||||||
"""
|
"""
|
||||||
mine_position_row = random.randrange(0, self.rows)
|
row = random.randrange(0, self.rows)
|
||||||
mine_position_col = random.randrange(0, self.cols)
|
col = random.randrange(0, self.cols)
|
||||||
|
|
||||||
if self.is_mine(mine_position_row, mine_position_col):
|
if self.is_mine(row, col):
|
||||||
self.put_mine()
|
self.put_mine()
|
||||||
|
|
||||||
self.board[mine_position_row][mine_position_col] = -1
|
self.board[row][col] = -1
|
||||||
return mine_position_row, mine_position_col
|
return row, col
|
||||||
|
|
||||||
def put_mines(self):
|
def put_mines(self):
|
||||||
""" Put the desired amount of mines on the board """
|
""" Put the desired amount of mines on the board """
|
||||||
for mine in range(1, self.mines + 1):
|
for mine in range(1, self.mines + 1):
|
||||||
mine_position_row, mine_position_col = self.put_mine()
|
row, col = self.put_mine()
|
||||||
|
|
||||||
self.create_mine_points(mine_position_row, mine_position_col)
|
self.create_mine_points(row, col)
|
||||||
|
|
||||||
def create_mine_points(self, mine_position_row, mine_position_col):
|
def create_mine_points(self, row, col):
|
||||||
"""Populate the board with points that sorrounds the mine.
|
"""Populate the board with points that sorrounds the mine.
|
||||||
The reference used is the mine that was already placed"""
|
The reference used is the mine that was already placed"""
|
||||||
|
|
||||||
# North
|
# North
|
||||||
self.increment_safe_point(mine_position_row - 1, mine_position_col)
|
self.increment_safe_point(row - 1, col)
|
||||||
|
|
||||||
# North-east
|
# North-east
|
||||||
self.increment_safe_point(mine_position_row - 1, mine_position_col + 1)
|
self.increment_safe_point(row - 1, col + 1)
|
||||||
|
|
||||||
# East
|
# East
|
||||||
self.increment_safe_point(mine_position_row, mine_position_col + 1)
|
self.increment_safe_point(row, col + 1)
|
||||||
|
|
||||||
# South-east
|
# South-east
|
||||||
self.increment_safe_point(mine_position_row + 1, mine_position_col + 1)
|
self.increment_safe_point(row + 1, col + 1)
|
||||||
|
|
||||||
# South
|
# South
|
||||||
self.increment_safe_point(mine_position_row + 1, mine_position_col)
|
self.increment_safe_point(row + 1, col)
|
||||||
|
|
||||||
# South-west
|
# South-west
|
||||||
self.increment_safe_point(mine_position_row + 1, mine_position_col - 1)
|
self.increment_safe_point(row + 1, col - 1)
|
||||||
|
|
||||||
# West
|
# West
|
||||||
self.increment_safe_point(mine_position_row, mine_position_col - 1)
|
self.increment_safe_point(row, col - 1)
|
||||||
|
|
||||||
# North-west
|
# North-west
|
||||||
self.increment_safe_point(mine_position_row - 1, mine_position_col - 1)
|
self.increment_safe_point(row - 1, col - 1)
|
||||||
|
|
||||||
def is_mine(self, row, col):
|
def is_mine(self, row, col):
|
||||||
""" Checks whether the given location have a mine """
|
""" Checks whether the given location have a mine """
|
||||||
@@ -105,7 +105,7 @@ class Minesweeper:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Verify if the position have a mine on it
|
# Verify if the position have a mine on it
|
||||||
if self.is_mine(row, col):
|
if self.board[row][col] == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Increment the value of the position becaus is close to some mine
|
# Increment the value of the position becaus is close to some mine
|
||||||
|
|||||||
Reference in New Issue
Block a user