Python 如何在一个.py文件中包含多个pygame程序,以便可以从同一窗口访问它们
我想做的是,我想在初始窗口中提供不同的小游戏作为选项供选择。因此,无论用户选择什么游戏选项,该游戏都将在同一窗口中运行。这可能吗?如果可能,那么如何实现?这可能是您想要的伪代码:Python 如何在一个.py文件中包含多个pygame程序,以便可以从同一窗口访问它们,python,pygame,Python,Pygame,我想做的是,我想在初始窗口中提供不同的小游戏作为选项供选择。因此,无论用户选择什么游戏选项,该游戏都将在同一窗口中运行。这可能吗?如果可能,那么如何实现?这可能是您想要的伪代码: class Menu(): #Has all menu-related knick-knacks def main(screen): if on_main_menu == True: Menu.draw(screen) if Menu.start_button_1.is_pre
class Menu():
#Has all menu-related knick-knacks
def main(screen):
if on_main_menu == True:
Menu.draw(screen)
if Menu.start_button_1.is_pressed:
on_main_menu = False
playing_game1 = True
if Menu.start_button_2.is_pressed:
on_main_menu = False
playing_game2 = True
while playing_game1:
#play the epic game
while playing_game2:
#play the even more epic game
您可以在第一个窗口中创建一个简单的菜单。但这通常被认为不是一个好的做法,即使一个游戏只有一个文件。查看sourceforge上python程序的示例,了解人们是如何构造代码、分离模型、视图、控制器、文档、配置等的。感谢您为一些基本游戏提供了这些功能