|
import sys
import pygame
class AlienInvasion:
def __init__(self):
"""初始化并创建游戏资源"""
pygame.init()
self.cereen = pygame.display.set_mode((250, 600))
pygame.display.set.caption("Alien Invasion")
def run_game(self):
"""开始游戏的主循环"""
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#让最近绘制的屏幕可见
pygame.display.flip()
if __name__ == "__main__":
#创建游戏实例并运行
ai = AlienInvasion
ai.run_game()
D:\常试\Scripts\python.exe D:/pythonProject/常试/游戏代码/窗口.pyTraceback (most recent call last): File "D:\pythonProject\常试\游戏代码\窗口.py", line 27, in <module> ai.run_game()TypeError: run_game() missing 1 required positional argument: 'self'pygame 2.1.2 (SDL 2.0.18, Python 3.9.7)Hello from the pygame community. https://www.pygame.org/contribute.html进程已结束,退出代码为 1
|
|