本文整理匯總了Python中stopwatch.Stopwatch.getSeconds方法的典型用法代碼示例。如果您正苦於以下問題:Python Stopwatch.getSeconds方法的具體用法?Python Stopwatch.getSeconds怎麽用?Python Stopwatch.getSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stopwatch.Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.getSeconds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Game
# 需要導入模塊: from stopwatch import Stopwatch [as 別名]
# 或者: from stopwatch.Stopwatch import getSeconds [as 別名]
#.........這裏部分代碼省略.........
def init(self):
self.initStyles()
self.initMaps()
Terrain.initImages()
Terrain.initSounds()
self.initMenus()
self.stopwatch = Stopwatch()
self.initHelp()
self.mode = "menu"
self.menu = self.mainMenu
def loadLevel(self):
terrain, self.startpos = self.maps.load(self.level)
self.terrain = pygame.sprite.Group(*terrain)
self.ball = Ball(*self.startpos)
self.score = 0
self.stopwatch.restart()
if self.level != "test":
highscore = self.progress[self.level]["score"]
bestTime = self.progress[self.level]["time"]
else:
highscore, bestTime = None, None
self.highscoreText = str(highscore) if highscore != None else "---"
if bestTime != None:
self.bestTimeText = Stopwatch.secToMin(bestTime)
else:
self.bestTimeText = "---"
def nextLevel(self):
# Update and save progress
saved = self.progress[self.level]
if saved["score"] == None or self.score > saved["score"]:
saved["score"] = self.score
duration = self.stopwatch.getSeconds()
if saved["time"] == None or duration < saved["time"]:
saved["time"] = duration
self.progress.save()
# Load next level
Terrain.playSound("happy")
index = self.maps.levels.index(self.level) + 1
if index >= len(self.maps.levels):
self.mode = "win"
else:
self.level = self.maps.levels[index]
self.loadLevel()
def initGame(self, level):
self.level = level
self.loadLevel()
def killBall(self):
Terrain.playSound("sad")
self.loadLevel()
def keyPressed(self, keyCode, modifier):
#print(keyCode)
if self.mode == "menu":
self.menu.key(keyCode)
elif self.mode == "play":
if keyCode == 27:
self.mode = "pause"
self.menu = self.pauseMenu
elif self.mode == "pause":
self.menu.key(keyCode)
if keyCode == 27:
self.mode = "play"