I got the numbers to show up! Now I just need to

add flag functionality and I think we're good?
This commit is contained in:
Cory 2024-05-19 00:52:09 -04:00
parent f0e166d6bd
commit 75618c1de1
7 changed files with 67 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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))
game.log("The cursor is at " + str(self.position))

View File

@ -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)
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)

View File

@ -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