Skip to content
Snippets Groups Projects
Commit 33c98436 authored by Dahmane Lynda's avatar Dahmane Lynda
Browse files

tp5

parent 9513f6e1
Branches
No related tags found
No related merge requests found
File added
File added
File added
......@@ -78,7 +78,7 @@ class Minesweeper():
10
$$$ game.nbombs
4
$$$ game.state== GameStat.unfinished
$$$ game.state== GameState.unfinished
True
$$$ cel= game.get_cell(1, 2)
$$$ cell.is revealed
......@@ -113,13 +113,13 @@ class Minesweeper():
4
$$$ game.state ==GameState.unfinished
True
"""
self.width= width
self.height= height
self.state= GameState.unfinished
self.nbombs=nbombs
self.grid=[(cell() for x in range(width) for y in range(height))]
self.state=GameState.unfinished
self.grid=[[Cell() for x in range(width)] for y in range(height)]
......@@ -134,9 +134,7 @@ class Minesweeper():
$$$ sum(1 for x in range(20) for y in range(10) if game.get_cell(x, y).is_bomb)
4
"""
return self.grid[x][y]
def _put_a_bomb_at(self, x: int, y: int):
......@@ -162,7 +160,13 @@ class Minesweeper():
$$$ all(game.get_cell(x, y).nbombs_in_neighborhood == 1 for x, y in voisins)
True
"""
...
Cell=self.get_cell(x,y)
if not Cell.is_bomb:
Cell.is_bomb=True
neighbors=self.get_neighbors(x,y)
for neighbors in neighbors:
neighbors.nbombs_in_neighborhood+=1
def all_cells_are_revealed_or_bomb(self) -> bool:
"""
......@@ -171,7 +175,11 @@ class Minesweeper():
précondition: none
"""
...
for row in self.grid:
for Cell in row:
if not Cell.is_revealed and not Cell.is_bomb:
return Fals
return True
def reveal_all_cells_from(self, x, y):
"""
......@@ -184,7 +192,7 @@ class Minesweeper():
winning
precondition: 0 <= x < width of game and O <= y < height of game
exemples:
$$$ game = Minesweeper(20, 10, 0)
......@@ -209,8 +217,26 @@ class Minesweeper():
$$$ game.state
GameState.losing
"""
...
Cell=self.get_cell(x,y)
if Cell.is_bomb:
self.state=GameState.losing
else:
Cell.is_revealed=True
if Cell.nbomb_in_neighborhood==0:
neighbor =self.get_neighbors(x,y)
for neighbor in neighbors:
if not neighbor.is_revealed:
self.reveal_all_Cells_from(neighbor.x,neighbor.y)
if self.all_Cells_are_revealed_or_bomb():
self.state=GameState.winning
if (__name__ == '__main__'):
import apl1test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment