diff --git a/README.md b/README.md index d6045dc..ed9d7a0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,6 @@ Contents: To Do: ---------- -- Have specific number of mines, rather than random +- ~~Have specific number of mines, rather than random~~ - Highscore table - Adjustable grid and mine count via UI diff --git a/minesweeper.py b/minesweeper.py index 4c32893..8796195 100644 --- a/minesweeper.py +++ b/minesweeper.py @@ -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 +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) # 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 + + 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 + #self.tk.quit() + def updateTimer(self): ts = "00:00:00"