Installed retro and got a cursor that moves...

Need to do:
-Populate 10 mines randomly
-Have the game end when a mine is selected (figure
out how to select something)
-Figure out an algorithm to reveal squares
-Figure out how to show numbers in revealed
squares
-Add flag functionality?
This commit is contained in:
Cory
2024-05-18 20:24:36 -04:00
parent 6145f70c95
commit cff4129336
5 changed files with 49 additions and 0 deletions

28
cursor.py Normal file
View File

@@ -0,0 +1,28 @@
# cursor.py
# ------------
# By MWC Contributors
# This module defines a spaceship agent class.
class Cursor:
name = "cursos"
character = 'O'
def __init__(self, board_size):
board_width, board_height = board_size
self.position = (board_width // 2, board_height - 1)
def handle_keystroke(self, keystroke, game):
x, y = self.position
if keystroke.name in ("KEY_LEFT", "KEY_RIGHT", "KEY_UP", "KEY_DOWN"):
if keystroke.name == "KEY_LEFT":
new_position = (x - 1, y)
elif keystroke.name == "KEY_RIGHT":
new_position = (x + 1, y)
elif keystroke.name == "KEY_UP":
new_position = (x, y - 1)
else:
new_position = (x, y + 1)
if game.on_board(new_position):
if game.is_empty(new_position):
self.position = new_position
else:
game.end()