新手一枚 长期潜水
再不冒泡 怕我号没
代码用意:上班摸鱼,练习脖子和手防止久坐疾病
欢迎大佬给予建议帮助优化
[Python] 纯文本查看 复制代码 python
import pygame
import random
# 初始化 Pygame
pygame.init()
# 设置游戏窗口大小
screen_width = 480
screen_height = 700
screen = pygame.display.set_mode((screen_width, screen_height))
# 设置游戏标题
pygame.display.set_caption("贪吃蛇")
# 设置颜色
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
# 设置方块大小和颜色
block_size = 20
block_color = (255, 0, 0)
# 设置蛇的初始长度和速度
snake_length = 1
snake_speed = 5
# 设置游戏结束标志
game_over = False
# 设置游戏循环标志
game_over_label = pygame.Label("游戏结束!")
game_over_label.set_font(pygame.font.SysFont("Arial", 30))
game_over_label.set_color(red)
game_over_label.set_position((screen_width / 2, screen_height - game_over_label.get_height()))
# 设置游戏计分板
score_board = pygame.Surface((10, 10))
score_board.fill((0, 0, 0))
score_board_text = pygame.font.Font("Arial", 30).render("Score: 0", True, black)
score_board_text_rect = score_board_text.get_rect(center=(score_board_text_rect.width / 2, score_board_text_rect.height / 2))
score_board_text_rect.centerx = score_board_text_rect.width / 2
score_board_text_rect.bottom = score_board_text_rect.height
score_board_text_rect.left = score_board_text_rect.width / 2
score_board_text_rect.top = score_board_text_rect.height
score_board_text_rect.right = score_board_text_rect.width
score_board_text_rect.height = 10
score_board_text_rect.x = score_board_text_rect.left
score_board_text_rect.y = score_board_text_rect.top
score_board_text_rect.width = score_board_text_rect.height
score_board_text_rect.height = score_board_text_rect.height
score_board_text_rect.x += score_board_text_rect.width / 2
score_board_text_rect.y += score_board_text_rect.height / 2
score_board_text_rect.width -= score_board_text_re |