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

cell.py

parent d62c8aef
Branches
No related tags found
No related merge requests found
......@@ -61,16 +61,18 @@ def neighborhood(x: int, y: int, width: int, height: int) -> list[tuple[int, int
$$$ neighborhood(3, 9, 10, 10)
[(2, 8), (2, 9), (3, 8), (4, 8), (4, 9)]
"""
res =[]
res=[]
if x>0:
res.append(x-1,y)
res+=[(x-1,y)]
if x< width-1:
res.append(x+1,y)
res+=[(x+1,y)]
if y>0:
res.append(x,y-1)
res+=[(x,y-1)]
if y<height-1:
res.append(x,y+1)
res+=[(x,y+1)]
return res
class Minesweeper():
"""
$$$ game = Minesweeper(20, 10, 4)
......@@ -80,13 +82,18 @@ class Minesweeper():
10
$$$ game.nbombs
4
$$$ game == GameState.unfinished
$$$ game.state== GameStat.unfinished
True
$$$ cel = game.get_cell(1, 2)
$$$ cel.is_revealed
$$$ cel= game.get_cell(1, 2)
$$$ cell.is revealed
False
$$$
$$$
"""
def __init__(self, width: int=30, height: int=20, nbombs: int=99):
"""
......@@ -108,10 +115,17 @@ class Minesweeper():
10
$$$ game.nbombs
4
$$$ game.state == GameState.unfinished
$$$ game.state ==GameState.unfinished
True
"""
...
self.width= width
self.height= height
self.nbombs= nbombs
self.grid=[(cell() for x in range(width) for y in range(height))]
def get_cell(self, x: int, y: int) -> Cell:
"""
......@@ -123,7 +137,14 @@ class Minesweeper():
$$$ sum(1 for x in range(20) for y in range(10) if game.get_cell(x, y).is_bomb)
4
"""
...
count=0
for x in range(game.width):
for y in range(game.height):
if game.get_cell(x,y).is_bomb:
count+=1
return count
def _put_a_bomb_at(self, x: int, y: int):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment