代码
'''
游戏玩法:回车开始游戏;空格暂停游戏/继续游戏;方向键/wsad控制小蛇走向
'''
'''
思路:用列表存储蛇的身体;用浅色表示身体,深色背景将身体凸显出来;
蛇的移动:仔细观察,是:身体除头和尾不动、尾部消失,头部增加,所以,新添加的元素放在列表头部、删除尾部元素;
游戏结束判定策略:超出边界;触碰到自己的身体:蛇前进的下一格子为身体的一部分(即在列表中)。
'''
import random
import sys
import time
import pygame
from pygame.locals import *
from collections import deque
Screen_Height=480
Screen_Width=600
Size=20
Line_Width=1
Area_x=(0,Screen_Width//Size-1)
Area_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)
Back_Ground=(40,40,60)
def Print_Txt(screen,font,x,y,text,fcolor=(255,255,255)):
Text=font.render(text,True,fcolor)
screen.blit(Text,(x,y))
def init_snake():
snake=deque