snake/main.py
2024-07-18 16:48:01 +08:00

37 lines
831 B
Python

import pygame
from settings import Settings
import game_functions as gf
from snake import Snake
from apple import Apple
settings = Settings()
# 设置屏幕
screen = pygame.display.set_mode((settings.width, settings.height))
# 添加游戏标题
pygame.display.set_caption('贪吃蛇')
# 创建蛇
snake = Snake(settings)
# 创建苹果
apple = Apple(settings)
#手动模式
def run_game1():
gf.check_play_events(snake)
gf.update_screen(settings, screen, snake,apple)
def run_game():
while True:
if settings.game_mode == 0:
gf.show_start(settings, screen)
elif settings.game_mode == -1:
gf.show_end(settings, screen)
snake.reset(settings)
elif settings.game_mode == 1:
run_game1()
if __name__ == "__main__":
pygame.init()
run_game()