-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
base: master
Are you sure you want to change the base?
New #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be nice to add argument parser and set this to |
||
MINES_TO_SET = 9 | ||
|
||
STATE_DEFAULT = 0 | ||
STATE_CLICKED = 1 | ||
STATE_FLAGGED = 2 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({}) | ||
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -130,7 +147,9 @@ def gameOver(self, won): | |
if res: | ||
self.restart() | ||
else: | ||
self.tk.quit() | ||
self.tk.destroy() #shut down the window | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will throw errors on quit due to updateTimer running in |
||
#self.tk.quit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
There was a problem hiding this comment.
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