diff --git a/__pycache__/cursor.cpython-312.pyc b/__pycache__/cursor.cpython-312.pyc index a657f0f..d2a1cc8 100644 Binary files a/__pycache__/cursor.cpython-312.pyc and b/__pycache__/cursor.cpython-312.pyc differ diff --git a/__pycache__/free_space.cpython-312.pyc b/__pycache__/free_space.cpython-312.pyc index e02ba76..808fb7f 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 01360c8..9f03dad 100644 Binary files a/__pycache__/mine.cpython-312.pyc and b/__pycache__/mine.cpython-312.pyc differ diff --git a/__pycache__/spawner.cpython-312.pyc b/__pycache__/spawner.cpython-312.pyc index 9be4ae1..816efc0 100644 Binary files a/__pycache__/spawner.cpython-312.pyc and b/__pycache__/spawner.cpython-312.pyc differ diff --git a/cursor.py b/cursor.py index 3d152b7..47ec299 100644 --- a/cursor.py +++ b/cursor.py @@ -5,6 +5,7 @@ class Cursor: name = "cursor" character = 'O' + revealed = True def __init__(self, position): self.position = position @@ -24,4 +25,5 @@ class Cursor: if game.on_board(new_position): if game.is_empty(new_position): self.position = new_position - game.log("The cursor is at " + str(self.position)) \ No newline at end of file + game.log("The cursor is at " + str(self.position)) + diff --git a/free_space.py b/free_space.py index 97ed419..8eecd14 100644 --- a/free_space.py +++ b/free_space.py @@ -17,16 +17,33 @@ class FreeSpace: 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 + board_width,board_height = game.board_size + for i in range(board_width): + for j in range(board_height): + try: + game.get_agent_by_name("freespace"+str(i)+str(j)).show() + except: + pass + self.reveal(game) + for i in range(board_width): + for j in range(board_height): + try: + game.get_agent_by_name("freespace"+str(i)+str(j)).hide() + except: + pass + def hide(self): - self.display = False + if self.revealed == False: + self.display = False + + def show(self): + self.display = True def play_turn(self, game): - if (not game.is_empty(self.position)) and self.revealed: + if (not game.is_empty(self.position)) and self.revealed and self.display == True: self.display = False - elif game.is_empty(self.position) and self.revealed and self.neighbors > 0: + elif game.is_empty(self.position) and self.revealed and self.neighbors > 0 and self.display == False: self.display = True def name_me(self, named): @@ -67,4 +84,41 @@ class FreeSpace: 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 + self.character = str(self.neighbors) + + def reveal(self,game): + game.log("Revealing " + str(self.position)) + self.revealed = True + if self.neighbors == 0: + if game.on_board((self.width + 1,self.height)): + if len(game.get_agents_by_position()[(self.width + 1,self.height)]) != 0: + if not game.get_agents_by_position()[(self.width + 1,self.height)][0].revealed: + game.get_agents_by_position()[(self.width + 1,self.height)][0].reveal(game) + if game.on_board((self.width - 1,self.height)): + if len(game.get_agents_by_position()[(self.width - 1,self.height)]) != 0: + if not game.get_agents_by_position()[(self.width - 1,self.height)][0].revealed: + game.get_agents_by_position()[(self.width - 1,self.height)][0].reveal(game) + if game.on_board((self.width,self.height + 1)): + if len(game.get_agents_by_position()[(self.width,self.height + 1)]) != 0: + if not game.get_agents_by_position()[(self.width,self.height + 1)][0].revealed: + game.get_agents_by_position()[(self.width,self.height + 1)][0].reveal(game) + if game.on_board((self.width,self.height - 1)): + if len(game.get_agents_by_position()[(self.width,self.height - 1)]) != 0: + if not game.get_agents_by_position()[(self.width,self.height - 1)][0].revealed: + game.get_agents_by_position()[(self.width,self.height - 1)][0].reveal(game) + 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 not game.get_agents_by_position()[(self.width + 1,self.height + 1)][0].revealed: + game.get_agents_by_position()[(self.width + 1,self.height + 1)][0].reveal(game) + 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 not game.get_agents_by_position()[(self.width + 1,self.height - 1)][0].revealed: + game.get_agents_by_position()[(self.width + 1,self.height - 1)][0].reveal(game) + 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 not game.get_agents_by_position()[(self.width - 1,self.height + 1)][0].revealed: + game.get_agents_by_position()[(self.width - 1,self.height + 1)][0].reveal(game) + 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 not game.get_agents_by_position()[(self.width - 1,self.height - 1)][0].revealed: + game.get_agents_by_position()[(self.width - 1,self.height - 1)][0].reveal(game) diff --git a/mine.py b/mine.py index 9afcf62..5c00940 100644 --- a/mine.py +++ b/mine.py @@ -5,6 +5,7 @@ class Mine: character = '_' + revealed = True def __init__(self, position): self.position = position @@ -25,4 +26,7 @@ class Mine: pass def reveal(): + pass + + def show(): pass \ No newline at end of file