Commit 1a54bc4d by BellCodeEditor

save project

parent bc0c4549
Showing with 38 additions and 7 deletions
File added
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -43,11 +44,22 @@ time=0 ...@@ -43,11 +44,22 @@ time=0
road_x=0 road_x=0
bg_x=0 bg_x=0
c=True c=True
score=0 score=2
speed=8 speed=10
old_score=0
score_music=pygame.mixer.Sound("Coin.wav")
with open("score.txt","r",encoding="utf-8") as fion:
abc=fion.read()
bdc=json.loads(abc)
one=bdc["第1名"]
two=bdc["第2名"]
three=bdc["第3名"]
while True: while True:
speed=8+score//3 speed=10+score//2
if score>old_score:
score_music.play()
old_score=score
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -103,6 +115,19 @@ while True: ...@@ -103,6 +115,19 @@ while True:
gameover=pygame.image.load("gameover.png") gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200)) screen.blit(gameover,(400,200))
c=False c=False
if score>three:
if score>one:
bdc["第1名"]=score
bdc["第2名"]=one
bdc["第3名"]=two
elif score>two:
bdc["第2名"]=score
bdc["第3名"]=two
else:
bdc["第3名"]=score
bdc=json.dumps(bdc,ensure_ascii=False)
with open("score.txt","w",encoding="utf-8") as fion_1:
fion_1.write(bdc)
else: else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x: if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score+=sprite.score score+=sprite.score
...@@ -110,6 +135,12 @@ while True: ...@@ -110,6 +135,12 @@ while True:
info="游戏分数:"+str(score) info="游戏分数:"+str(score)
text=font.render(info,True,(255,255,255)) text=font.render(info,True,(255,255,255))
screen.blit(text,(880,20)) screen.blit(text,(880,20))
one_1=font.render("第一名"+str(one),True,(255,255,255))
screen.blit(one_1,(880,45))
two_1=font.render("第二名"+str(two),True,(255,255,255))
screen.blit(two_1,(880,70))
three_1=font.render("第三名"+str(three),True,(255,255,255))
screen.blit(three_1,(880,95))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(61)
\ No newline at end of file \ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0} {"第1名": 75, "第2名": 15, "第3名": 10}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment