This is the FINAL version of what I'm submitting.

This is a version of minesweeper. You win by
isolating every mine, which is the same as
revealing all numbered spaces. There is no flag,
so you have to keep track of, or figure out,
what's revealed. The game ends if you win as
described above or you lose by selecting a mine.

I have playtested this and confirmed that the
game ends in a win by meeting the above criterion.
I also (not intentionally) confirmed you lose if
you select a mine. I did the latter far too many
times...

Things to note:
-I have the game in debug mode so that
instructions appear.
-There is no score. I don't think there's a
score in minesweeper. You either survive the mines
or die.
-I have not implemented flagging potential
locations of mines. You can technically play
without them, so I don't think you lose out on
any of the core gameplay.
-I'm not sure why, but when the game ends, some
of the mines don't show up and some of the
revealed numbers disappear.
-Because two displayed agents cannot occupy the
same space, navigating with the cursor over mines
or numbered squares may require pressing an arrow
key multiple times. (I tried to not display the
mines and then display them only when revealing
spaces, but the revealing algorithm didn't work
when I tried it like that. I promise I spent
hours trying to get it to work before settling on
this current iteration.)
-You can lose on the first move...
This commit is contained in:
Cory
2024-05-19 04:06:01 -04:00
parent 8e54c5fe12
commit 374952d65a
9 changed files with 128 additions and 56 deletions

View File

@@ -2,6 +2,7 @@
# ------------
# By Cory
# This module defines a cursor agent class.
class Cursor:
name = "cursor"
character = 'O'
@@ -11,8 +12,10 @@ class Cursor:
self.position = position
def handle_keystroke(self, keystroke, game):
'''
Move the cursor using arrow keys.
'''
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)
@@ -25,9 +28,10 @@ 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))
for i in range(10):
game.log("mine"+str(i) + " is located at " + str(game.get_agent_by_name("mine"+str(i)).position))
def hide(self):
'''
This is called because I was calling this method based on an agent's location, but I don't need the
cursor to do anything.
'''
pass