在自学Python的过程中在网上查询资料时发现了一些好玩的东西,python的游戏库模块,它可以自己弄一个小游戏来玩玩,然后我在网上找了一些游戏的代码,,自己改了一些,弄出了一个简单贪吃蛇,代码也是照着敲的只是稍微的改了一下
import pygame, sys, random, time
from pygame.locals import * # 从pygame模块导入常用的函数和常量
#定义颜色变量
black_colour = pygame.Color(28, 56, 20)
white_colour = pygame.Color(255, 144, 20)
red_colour = pygame.Color(255,34 , 20)
grey_colour = pygame.Color(150, 150, 150)
#定义游戏结束函数
def GameOver(gamesurface):
# 设置提示字体的格式
GameOver_font = pygame.font.SysFont("MicrosoftYaHei", 16)
# 设置提示字体的颜色
GameOver_colour = GameOver_font.render('GameOver', True, grey_colour)#只能英文
# 设置提示位置
GameOver_location = GameOver_colour.get_rect()
GameOver_location.midtop = (310, 200)
# 绑定以上设置到句柄
gamesurface.blit(GameOver_colour, GameOver_location)
# 提示运行信息
pygame.display.flip()
# 休眠5秒
time.sleep(5)
# 退出游戏
pygame.quit()
# 退出程序
sys.exit()
#定义主函数
def main():
# 初始化pygame,为使用硬件做准备
pygame.init()
pygame.time.Clock()
ftpsClock =