Commit 550fef4a by BellCodeEditor

save project

parent 4cd18c00
import json
j='{"第一名":122,"第二名":119,"第三名":100}'
text=json.loads(j)
print("第一名",text["第一名"])
print("第二名",text["第二名"])
print("第三名",text["第三名"])
\ No newline at end of file
import pygame
from pygame import locals
import random
import json
score=0
pygame.init() # 初始化
speed=8
speed=20
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -53,8 +53,15 @@ road_x = 0
bg_x = 0
time = 0
gamestate = True
block_list =pygame.sprite.Group() # 创建精灵组
p=0
block_list =pygame.sprite.Group()
# 创建精灵组
with open("record.txt","r",encoding="utf-8") as f:
content=f.read()
recond=json.loads(content)
one=recond["第1名"]
two=recond["第2名"]
three=recond["第3名"]
p=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -90,7 +97,7 @@ while True:
t =30
# 将背景图画上去
bg_x -= 1
bg_x -= 10
if bg_x<=-1000:
bg_x = 0
screen.blit(background, (bg_x, 0)) # 远景
......@@ -118,16 +125,38 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
gamestate = False
if score > one:
recond["第1名"]=score
recond["第2名"]=one
recond["第3名"]=two
elif score>two:
recond["第2名"]=score
recond["第3名"]=two
else:
recond["第3名"]=score
text=json.dumps(recond,ensure_ascii=False)
with open('score.txt','w',encoding='utf-8')as f:
f.write(text)
else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score+=sprite.score
sprite.score=0
speed=8+score//3
speed=15+score//3
if p<score:
score_audio.play()
p=score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第1名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,50))
scoreSurf = basic_font.render("第2名:"+str(two),True,(255,0,0))
screen.blit(scoreSurf,(850,80))
scoreSurf = basic_font.render("第3名:"+str(three),True,(255,0,0))
screen.blit(scoreSurf,(850,110))
# 刷新画面
pygame.display.update()
......
{"第1名": 8, "第2名": 0, "第3名": 0}
\ 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