main logo
Subject: [dabo-dev] dabodemo Commit 275
Author: Paul McNett

Posted: 2005/08/31 14:53:50
 
View Entire Thread
New Search


dabodemo Commit
Revision 275
Date: 2005-08-31 13:02:54 -0700 (Wed, 31 Aug 2005)
Author: paul

Changed:
U trunk/minesweeper.py

Log:
Added an "end game" button. Added a label to the toolbar that gives
the player the current game setup (dimension and # of mines in game).
Changed the working of the Preferences dialog to require that a game
isn't in progress, and to automatically start a new game if the
dialog was accepted. Made the preference dialog smart in selecting
whether to display the preset page or the manual setting page,
depending on whether the player is currently set up with a preset
game or not.


Diff:
Modified: trunk/minesweeper.py
===================================================================
--- trunk/minesweeper.py 2005-08-31 18:25:40 UTC (rev 274)
+++ trunk/minesweeper.py 2005-08-31 20:02:54 UTC (rev 275)
@@ -381,6 +381,7 @@
assert len(size) == 2
assert (type(size[0]), type(size[1])) == (int, int)
self._boardSize = size
+ self.Form.updateGameInfo()
self.Application.setUserSetting("minesweeper_boardwidth", size[0])
self.Application.setUserSetting("minesweeper_boardheight", size[1])

@@ -397,6 +398,7 @@
def _setMineCount(self, count):
assert type(count) == int
self._mineCount = count
+ self.Form.updateGameInfo()
self.Application.setUserSetting("minesweeper_minecount", count)

def _getMinesRemaining(self):
@@ -490,17 +492,24 @@
self.pausebutton.raiseEvent(dEvents.Hit)
self._autopause = False

+ def updateGameInfo(self):
+ """The board setup has changed: reflect in the game info label in the toolbar."""
+ b = self.board
+ s = b.BoardSize
+ m = b.MineCount
+ self.lblGameInfo.Caption = "%sx%s,%s" % (s[0], s[1], m)
+
def onEditPreferences(self, evt):
+ if self.board._GameInProgress and (self.pausebutton.Value or self.board.StopWatch.Running):
+ dabo.ui.stop("Please end your game before changing the preferences.")
+ return
dlg = PreferenceDialog(self)
dlg.show()
if dlg.accepted:
- ng = dabo.ui.areYouSure("Do you want to start a new game with your new settings?")
- if ng is not None:
- self.board.BoardSize = (dlg.boardWidth, dlg.boardHeight)
- self.board.MineCount = dlg.boardMines
- self.preset = dlg.preset
- if ng:
- self.newGame()
+ self.board.BoardSize = (dlg.boardWidth, dlg.boardHeight)
+ self.board.MineCount = dlg.boardMines
+ self.preset = dlg.preset
+ self.newGame()
dlg.release()

def onPause(self, evt):
@@ -519,6 +528,10 @@
def onNewGame(self, evt):
self.newGame()

+ def onEndGame(self, evt):
+ self.board.showAllSquares()
+ self.board._GameInProgress = False
+
def newGame(self):
bs = self.board.BoardSize
mc = self.board.MineCount
@@ -542,12 +555,19 @@
tb.appendButton("New", pic="new", toggle=False, bindfunc=self.onNewGame,
tip="New Game", help="Start a new game")

+ tb.appendButton("End", pic="delete", toggle=False, bindfunc=self.onEndGame,
+ tip="End Game", help="End the current game")
+
tb.appendButton("Preferences", pic="configure", toggle=False,
bindfunc=self.onEditPreferences,
tip="Preferences", help="Edit preferences")

tb.appendSeparator()

+ self.lblGameInfo = tb.appendControl(dabo.ui.dLabel(tb))
+
+ tb.appendSeparator()
+
self.pausebutton = tb.appendControl(dabo.ui.dToggleButton(tb, Caption="Pause",
ToolTipText="Pause/Resume",
StatusText="Pause/Resume the game"),
@@ -682,7 +702,9 @@

p2.Sizer = vs
self.Sizer.append1x(pgf)
- if preset["Id"] is None:
+ if preset["Id"] is None or (preset["Width"] != self.boardWidth or
+ preset["Height"] != self.boardHeight or
+ preset["Mines"] != self.boardMines):
pgf.SelectedPageNum = 1

def onOK(self, evt):





 
©2005 Paul McNett
<-- Prior Message New Search Next Message -->