snake/main.py

30 lines
675 B
Python
Raw Normal View History

2024-07-15 00:53:49 +08:00
import pygame
2024-07-14 00:10:48 +08:00
from settings import Settings
import game_functions as gf
2024-07-15 00:53:49 +08:00
from snake import Snake
2024-07-14 00:10:48 +08:00
settings = Settings()
2024-07-15 00:53:49 +08:00
#设置屏幕
screen = pygame.display.set_mode((settings.width, settings.height))
#添加游戏标题
pygame.display.set_caption('贪吃蛇')
#创建蛇
snake = Snake(settings)
def run_game1():
gf.check_play_events(snake)
gf.update_screen(settings, screen, snake)
2024-07-14 00:10:48 +08:00
def run_game():
2024-07-15 00:53:49 +08:00
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()
2024-07-14 00:10:48 +08:00
if __name__ == "__main__":
2024-07-15 00:53:49 +08:00
pygame.init()
run_game()