封装为类

This commit is contained in:
chicrobot committed 2026-07-26 01:52:50 +08:00
1 parent 8fba77d1c0
commit 2f7261f59c
1 file changed
+22 -17
+22 -17
View File
@@ -1,38 +1,43 @@
import pygame
from src.config.color import Color
from src.config.game_config import GameConfig
rect = [10,20,30,40]
class Game:
def __init__(self):
# 初始化
pygame.init()
# 设置窗口大小
window_size = (1920/2, 1080/2)
screen = pygame.display.set_mode(window_size)
size = (GameConfig.window_x, GameConfig.window_y)
self.screen = pygame.display.set_mode(size)
# 设置标题
pygame.display.set_caption("Test Name")
pygame.display.set_caption(GameConfig.game_name)
rect = [10,20,30,40]
black = (0,0,0)
white = (255,255,255)
def update():
pass
def main():
# 运行循环
running = True
while running:
self.running = True
self.run()
def run(self):
while self.running:
# 事件处理
for event in pygame.event.get():
# 检查是否关闭
if event.type == pygame.QUIT:
running = False
self.running = False
screen.fill(black)
self.screen.fill(GameConfig.bg_color)
pygame.draw.rect(screen, white, rect)
self.update()
# 更新显示
pygame.display.update()
def update(self):
pygame.draw.rect(self.screen, Color.white, rect)
if __name__ == "__main__":
main()
Game()