科学放置音乐播放代码位置

This commit is contained in:
wszqkzqk 2022-07-26 23:28:48 +08:00
parent 82cebe8288
commit 410cf2cca1
2 changed files with 30 additions and 18 deletions

View File

@ -1422,8 +1422,6 @@ class Level(tool.State):
self.game_info[c.LEVEL_NUM] += 1
self.next = c.GAME_VICTORY
self.done = True
# 播放胜利音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "win.ogg")).play()
with open(c.USERDATA_PATH, "w") as f:
userdata = {}
for i in self.game_info:
@ -1434,9 +1432,6 @@ class Level(tool.State):
elif self.checkLose():
self.next = c.GAME_LOSE
self.done = True
# 播放失败音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "lose.ogg")).play()
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "scream.ogg")).play()
def drawMouseShow(self, surface):
if self.hint_plant:

View File

@ -1,22 +1,14 @@
import pygame as pg
import os
from .. import tool
from .. import constants as c
class Screen(tool.State):
def __init__(self, caption=c.ORIGINAL_CAPTION):
tool.State.__init__(self)
def __init__(self):
self.end_time = 3000
self.caption = caption
def startup(self, current_time, persist):
self.start_time = current_time
self.next = c.LEVEL
self.persist = persist
self.game_info = persist
name = self.getImageName()
self.setupImage(name)
self.next = self.set_next_state()
pg.display.set_caption(self.caption)
pass
def getImageName(self):
pass
@ -40,20 +32,45 @@ class Screen(tool.State):
class GameVictoryScreen(Screen):
def __init__(self):
Screen.__init__(self, caption="pypvz: 战斗胜利!")
Screen.__init__(self)
def getImageName(self):
return c.GAME_VICTORY_IMAGE
def set_next_state(self):
return c.LEVEL
def startup(self, current_time, persist):
self.start_time = current_time
self.next = c.LEVEL
self.persist = persist
self.game_info = persist
name = self.getImageName()
self.setupImage(name)
self.next = self.set_next_state()
pg.display.set_caption("pypvz: 战斗胜利!")
# 播放胜利音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "win.ogg")).play()
class GameLoseScreen(Screen):
def __init__(self):
Screen.__init__(self, caption="pypvz: 战斗失败!")
Screen.__init__(self)
def getImageName(self):
return c.GAME_LOSE_IMAGE
def set_next_state(self):
return c.LEVEL
def startup(self, current_time, persist):
self.start_time = current_time
self.next = c.LEVEL
self.persist = persist
self.game_info = persist
name = self.getImageName()
self.setupImage(name)
self.next = self.set_next_state()
pg.display.set_caption("pypvz: 战斗失败!")
# 播放失败音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "lose.ogg")).play()
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "scream.ogg")).play()