从主pygame zero窗口调用另一个pygame zero程序



我想在pygame zero中创建多个小游戏,有一个主窗口,你可以在上面点击按钮——点击按钮时,它会启动一个新窗口和一个新的子名称(在另一个文件中单独编码(。如果比赛赢了或输了,第二场比赛应该能够回来。这可能使用pygame zero吗?我认为应该将子游戏封装在某个函数中,以便能够给出返回值,但我不确定这在pygame zero中是否可行,因为它本身调用了一些函数。。。知道吗?

还是我最好在主程序中添加某种游戏状态,然后像这样做?

def update():
if state == 'game1':
#all of the game1 update code here
elif state == 'game2':
#all of the game2 update code here
#etc
def draw():
if state == 'game1':
#all of the game1 draw code here
elif state == 'game2':
#all of the game2 draw code here
#etc

我认为实现游戏状态肯定会更好。我会使用一种面向对象的方法,比如:

class GameState:
def update():
pass
def draw():
pass
class Game1(GameState):
def update():
# ...
def draw():
# ...
class GameChooser(GameState):
def update():
# choose game here
global state
if ...:
state = Game1()
def draw():
# ...
state = GameChooser()
def update():
state.update()
def draw():
state.draw()

最新更新