import pygame, sys, time, random
from pygame.locals import *
redColour = pygame.Color(255, 0, 0)
greenColour = pygame.Color(0, 255, 0)
blueColour = pygame.Color(0, 0, 255)
blackColour = pygame.Color(0, 0, 0)
whiteColour = pygame.Color(255, 255, 255)
greyColour = pygame.Color(150, 150, 150)
yellowColour =pygame.Color(255, 255, 0)
purpleColour =pygame.Color(255, 0, 255)
brownColour =pygame.Color(150, 75, 75)
DeepPinkColour=pygame.Color(255 ,20 ,147)
#初始化并播放背景音乐
#pygame.mixer.init() #初始化混音器
#pygame.mixer.music.load('Ken Arai - NEXT TO YOU.mp3') #加载背景音乐
#pygame.mixer.music.set_volume(0.2) #设置音量
#pygame.mixer.music.play() #播放背景音乐
# 定义游戏结束函数。当双方长度相等且头头相撞时,为平局。游戏结束,并显示双方分数。
def gameOver (playSurface,score1,score2):
gameOverFont = pygame.font.SysFont('arial', 32)
gameOverSurf = gameOverFont.render('tie '+'pink:'+str(score1-3)+' '+'blue:'+str(score2-3), True, greyColour)
gameOverRect = gameOverSurf.get_rect()
gameOverRect.midtop = (320, 10)
playSurface.blit(gameOverSurf, gameOverRect)
pygame.display.flip()
time.sleep(5)
main()
# 定义游戏结束函数。当1号玩家撞墙或被2号玩家吃了时,游戏结束,显示1号玩家失败,以及双方分数。
def gameOver1(playSurface,score1,score2):
gameOverFont = pygame.font.SysFont('arial', 32)
gameOverSurf = gameOverFont.render('green snake Game Over '+'pink:'+str(score1-3)+' '+'blue:'+str(score2-3), True, greyColour)
gameOverRect = gameOverSurf.get_rect()
gameOverRect.midtop = (320, 10)
playSurface.blit(gameOverSurf, gameOverRect)
pygame.display.flip()
time.sleep(5)
main()
# 定义游戏结束函数。当2号玩家撞墙或被1号玩家吃了时,游戏结束,显示2号玩家失败,以及双方分数。
def gameOver2(playSurface,score1,score2):
gameOverFont = pygame.font.SysFont('arial', 32)
gameOverSurf = gameOverFont.render(' blue snake Game Over '+'pink'+str(score1-3)+' '+'blue:'+str(score2-3), True, greyColour)
gameOverRect = gameOverSurf.get_rect()
【pygame】一个精简版的双人贪吃蛇
最新推荐文章于 2022-03-17 10:22:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)