I am currently making a mines game with python but i have some problems withe the mines repartition : To choose the places of the different mines, i use the python random module to generate x and y coordinates. Firstly i choosed to place all the mines before the player first play but the problem was that the first play was generally a mine or a cas with mines as neighbours. So I decided to place the mines after the player first play to be sure that the first cas revealed will not have mines as neighbours but the problem is that the mines's repartition is not very interesting for a mines game. How can I make it better ?
Here is my function wich place mines in the Board class after player first play where pos is coords of first cas revealed :
def place_mines(self, pos):
posed_mines = 0
while posed_mines < self.mines_number:
x = random.randrange(0, COLUMN_NUMBER-1)
y = random.randrange(0, LINE_NUMBER-1)
if not self.Matrix[y][x].is_mined and (x < pos[0]-1 or x > pos[0]+1) and (y < pos[1]-1 or y > pos[1]+1):
self.Matrix[y][x].mine()
posed_mines += 1
And the result in game :
Here is the function that place all the mines before the player first play :
def place_mines(self):
posed_mines = 0
while posed_mines < self.mines_number:
x = random.randrange(0, COLUMN_NUMBER-1)
y = random.randrange(0, LINE_NUMBER-1)
if not self.Matrix[y][x].is_mined:
self.Matrix[y][x].mine()
posed_mines += 1
And the result in game :
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire