python版贪吃蛇,复制可直接运行

"""贪吃蛇"""

import random
import sys
import time
import pygame
from pygame.locals import *
from collections import deque

SCREEN_WIDTH = 800  # 屏幕宽度
SCREEN_HEIGHT = 600  # 屏幕高度
SIZE = 20  # 小方格大小
LINE_WIDTH = 1  # 网格线宽度

# 游戏区域的坐标范围
SCOPE_X = (0, SCREEN_WIDTH // SIZE - 1)
SCOPE_Y = (2, SCREEN_HEIGHT // SIZE - 1)

# 食物的分值及颜色
FOOD_STYLE_LIST = [(10, (255, 100, 100)), (20, (100, 255, 100)), (30, (100, 100, 255))]

LIGHT = (100, 100, 100)
DARK = (200, 200, 200)  # 蛇的颜色
BLACK = (0, 0, 0)  # 网格线颜色
RED = (200, 30, 30)  # 红色,GAME OVER 的字体颜色
BGCOLOR = (40, 40, 60)  # 背景色


def print_text(screen, font, x, y, text, fcolor=(255, 0, 0)):
    imgText = font.render(text, True, fcolor)
    screen.blit(imgText, (x, y))


# 初始化蛇
def init_snake():
    snake = deque()
    snake.append((2, SCOPE_Y[0]))
    snake.append((1, SCOPE_Y[0]))
    snake.append((0, SCOPE_Y[0]))
    return snake


def create_food(snake):
 

你可能感兴趣的:(python,python,pygame,开发语言)