"""贪吃蛇""" 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):
文章来源地址https://www.toymoban.com/news/detail-760290.html
文章来源:https://www.toymoban.com/news/detail-760290.html
到了这里,关于python版贪吃蛇,复制可直接运行的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!