You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.9 KiB

9 months ago
import tkinter as tk
import alien_invasion
9 months ago
class GameWelcomeScreen(tk.Tk):
9 months ago
def __init__(self):
super().__init__()
self.title("欢迎界面")
self.geometry("1300x750") # 设置窗口大小
9 months ago
# self.set_background_image()
9 months ago
# 添加标签和按钮
9 months ago
self.welcome_label = tk.Label(self, text="WELCOM TO \nThe Alien Invasion", font=("comicsansms", 50),
foreground="lightblue")
9 months ago
self.welcome_label.pack(pady=50) # 使用pack布局管理器
9 months ago
self.start_button = tk.Button(self, text="进入游戏", font=("comicsansms", 20), command=self.start_button,
background="lightblue")
9 months ago
self.start_button.pack(pady=20)
9 months ago
self.quit_button = tk.Button(self, text="退出游戏", font=("comicsansms", 20), command=self.quit,
background="lightgreen")
9 months ago
self.quit_button.pack(pady=20)
9 months ago
self.about_button = tk.Button(self, text="关于游戏", font=("comicsansms", 20), command=self.about_button,
background="lightyellow")
9 months ago
self.about_button.pack(pady=20)
self.mainloop()
9 months ago
# def set_background_image(self):
# # 加载图片
# bg_image = tk.PhotoImage(file="images/bg.gif")
# # 创建一个标签来承载图片,并设置到最底层
# bg_label = tk.Label(self, image=bg_image)
# bg_label.place(x=0, y=0, relwidth=1, relheight=1)
# # 确保图片保持引用否则它会被Python的垃圾回收机制销毁
# bg_label.image = bg_image
9 months ago
def start_button(self):
9 months ago
self.withdraw() # 点击开始游戏后隐藏开始界面
9 months ago
alien_invasion.run_game()
def about_button(self):
print("本游戏是外星人入侵游戏")
root = tk.Tk() # 建立第二个窗口
root.title("关于游戏")
root.geometry("400x300")
tk.Label(root, text="这是一款使用Pygame包来开发的2D游戏。"
"\n它在玩家每消灭一群向下移动的外星人后,将玩家提高一个等级。\n每射杀一个外星人获得的相应的分数,等级越高,"
9 months ago
"\n游戏的节奏越快,难度越大,击杀每个外星人获得的分数就越高。\n"
"玩家的任务就是击落每个从屏幕上方移动下来的外星人,\n当外星人碰到飞船或者屏幕底部时该飞船被摧毁,\n"
"每个玩家可拥有三艘飞船,当三艘飞船都被摧毁时结束游戏\n得出最高分。\n\n\n"
"游戏使用:左右键移动飞船,空格键发射子弹",
9 months ago
font=("comicsansms", 10), foreground='black').pack(pady=20)
root.mainloop()
if __name__ == "__main__":
app = GameWelcomeScreen()
9 months ago
app.mainloop()