diff --git a/__pycache__/free_space.cpython-312.pyc b/__pycache__/free_space.cpython-312.pyc index 5677651..83010ca 100644 Binary files a/__pycache__/free_space.cpython-312.pyc and b/__pycache__/free_space.cpython-312.pyc differ diff --git a/__pycache__/mine.cpython-312.pyc b/__pycache__/mine.cpython-312.pyc index e770c25..86b998b 100644 Binary files a/__pycache__/mine.cpython-312.pyc and b/__pycache__/mine.cpython-312.pyc differ diff --git a/__pycache__/mine_spawner.cpython-312.pyc b/__pycache__/mine_spawner.cpython-312.pyc index 39cb7b2..f5266f9 100644 Binary files a/__pycache__/mine_spawner.cpython-312.pyc and b/__pycache__/mine_spawner.cpython-312.pyc differ diff --git a/free_space.py b/free_space.py index db53f85..1b1f182 100644 --- a/free_space.py +++ b/free_space.py @@ -5,14 +5,64 @@ class FreeSpace: character = '*' display = True + revealed = False + neighbors = 0 def __init__(self, position): self.position = position + self.width , self.height = position def handle_keystroke(self, keystroke, game): if keystroke.name in ("KEY_ENTER"): if not game.is_empty(self.position): game.log(str(self.position) + " is clear!") + self.revealed = True def hide(self): - self.display = False \ No newline at end of file + self.display = False + + def play_turn(self, game): + if (not game.is_empty(self.position)) and self.revealed: + self.display = False + elif game.is_empty(self.position) and self.revealed and self.neighbors > 0: + self.display = True + + def name_me(self, named): + self.name = named + + def check_neighbors(self,game): + names_of_mines = ["mine0","mine1","mine2","mine3","mine4","mine5","mine6","mine7","mine8","mine9"] + if game.on_board((self.width + 1,self.height)): + if len(game.get_agents_by_position()[(self.width + 1,self.height)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height)): + if len(game.get_agents_by_position()[(self.width - 1,self.height)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width,self.height + 1)): + if len(game.get_agents_by_position()[(self.width,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width,self.height - 1)): + if len(game.get_agents_by_position()[(self.width,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width + 1,self.height + 1)): + if len(game.get_agents_by_position()[(self.width + 1,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width + 1,self.height - 1)): + if len(game.get_agents_by_position()[(self.width + 1,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height + 1)): + if len(game.get_agents_by_position()[(self.width - 1,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height - 1)): + if len(game.get_agents_by_position()[(self.width - 1,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if self.neighbors > 0: + self.character = str(self.neighbors) \ No newline at end of file diff --git a/mine.py b/mine.py index b8eefc9..4104325 100644 --- a/mine.py +++ b/mine.py @@ -15,4 +15,13 @@ class Mine: game.end() def hide(self): - self.display = False \ No newline at end of file + self.display = False + + def name_me(self, named): + self.name = named + + def check_neighbors(self,game): + pass + + def reveal(): + pass \ No newline at end of file diff --git a/mine_spawner.py b/mine_spawner.py index 3c25a27..eb66810 100644 --- a/mine_spawner.py +++ b/mine_spawner.py @@ -22,20 +22,23 @@ class Spawner: for i in range(self.board_width): for j in range(self.board_height): free_space = FreeSpace((i,j)) + free_space.name_me("freespace"+str(i)+str(j)) game.add_agent(free_space) # Then spawn 10 mines for i in range(10): mine = Mine(((randint(0, self.board_width - 1)),(randint(0, self.board_height - 1)))) - game.log(mine.position) + mine.name_me("mine"+str(i)) + game.log(str(mine.name) + " is located at " + str(mine.position)) # If there is a free space where a mine is going to be, remove the free space and then add the mine. if not game.is_empty(mine.position): game.remove_agent(game.get_agents_by_position()[mine.position][0]) game.add_agent(mine) - # Now ask all of the mines and free spaces to hide themselves. + # Now ask all free spaces to keep track of their neighbors that are mines + # and all of the mines and free spaces to hide themselves. for i in range(self.board_width): for j in range(self.board_height): if len(game.get_agents_by_position()[(i,j)]) != 0: + game.get_agents_by_position()[(i,j)][0].check_neighbors(game) game.get_agents_by_position()[(i,j)][0].hide() # Now create a cursor. - game.add_agent(Cursor((self.board_width - 1, self.board_height - 1))) - + game.add_agent(Cursor((self.board_width - 1, self.board_height - 1)))