Skip to content

New #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

New #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Contents:

To Do:
----------
- Have specific number of mines, rather than random
- ~~Have specific number of mines, rather than random~~
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just remove this line entirely

- Highscore table
- Adjustable grid and mine count via UI
31 changes: 25 additions & 6 deletions minesweeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
SIZE_X = 10
SIZE_Y = 10

FIXED_MINE_NUMBER = True #if True set a fixed number of mines, rather than a random outcome
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to add argument parser and set this to False if run with --random 🤔

MINES_TO_SET = 9

STATE_DEFAULT = 0
STATE_CLICKED = 1
STATE_FLAGGED = 2
Expand Down Expand Up @@ -61,6 +64,12 @@ def setup(self):
self.correctFlagCount = 0
self.clickedCount = 0
self.startTime = None

if FIXED_MINE_NUMBER:
#if fixed number, generate random list of mines
#for simplicity generate set of random numbers going up to x*y size
#will then compare with mine number, counting across row then row by row
mine_list = random.sample(range(SIZE_X*SIZE_Y-1),MINES_TO_SET)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after the comma for consistent formatting, please


# create buttons
self.tiles = dict({})
Expand All @@ -75,11 +84,19 @@ def setup(self):

# tile image changeable for debug reasons:
gfx = self.images["plain"]

# currently random amount of mines
if random.uniform(0.0, 1.0) < 0.1:
isMine = True
self.mines += 1

if FIXED_MINE_NUMBER:
#fixed amount of mines
if x*SIZE_X+y in mine_list:
#count which square number we're on and see if in mine list
isMine = True
self.mines += 1

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank line just so the if-else block is grouped visually

else:
# currently random amount of mines
if random.uniform(0.0, 1.0) < 0.1:
isMine = True
self.mines += 1

tile = {
"id": id,
Expand Down Expand Up @@ -130,7 +147,9 @@ def gameOver(self, won):
if res:
self.restart()
else:
self.tk.quit()
self.tk.destroy() #shut down the window
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw errors on quit due to updateTimer running in after, I think wrapping this in an after also should resolve it, i.e. self.tk.after(100, self.tk.destroy) although I haven't had the chance to test it yet.

#self.tk.quit()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to keep commented-out lines, please remove



def updateTimer(self):
ts = "00:00:00"
Expand Down