Commit 97ab3873 by BellCodeEditor

save project

parent c27e22d2
Showing with 19 additions and 7 deletions
...@@ -57,12 +57,12 @@ old_score=score ...@@ -57,12 +57,12 @@ old_score=score
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
with open("score.txt","r",encoding='utf-8')as f: with open("record.txt","r",encoding='utf-8')as f:
content=f.read() content=f.read()
record=json.loads(content) record=json.loads(content)
fir=content["第一名"] fir=record["第1名"]
sec=content["第二名"] sec=record["第2名"]
thr=content["第三名"] thr=record["第3名"]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -128,6 +128,18 @@ while True: ...@@ -128,6 +128,18 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束 gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200)) screen.blit(gameover, (400, 200))
gamestate = False gamestate = False
if score>fir:
record['第1名']=score
record['第2名']=sec
record['第3名']=thr
if score>sec:
record['第2名']=score
record['第3名']=thr
else:
record['第3名']=score
record=json.dumps(record,ensure_ascii=False)
with open("record.txt","w",encoding='utf-8')as f:
f.wrte(record)
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
...@@ -139,11 +151,11 @@ while True: ...@@ -139,11 +151,11 @@ while True:
scoreSurf=basic_font.render('分数'+str(score),True,(255,255,255)) scoreSurf=basic_font.render('分数'+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,20)) screen.blit(scoreSurf,(880,20))
scoreSurf=basic_font.render('第名'+str(fir),True,(255,255,255)) scoreSurf=basic_font.render('第1名'+str(fir),True,(255,255,255))
screen.blit(scoreSurf,(880,50)) screen.blit(scoreSurf,(880,50))
scoreSurf=basic_font.render('第名'+str(sec),True,(255,255,255)) scoreSurf=basic_font.render('第2名'+str(sec),True,(255,255,255))
screen.blit(scoreSurf,(880,80)) screen.blit(scoreSurf,(880,80))
scoreSurf=basic_font.render('第名'+str(thr),True,(255,255,255)) scoreSurf=basic_font.render('第3名'+str(thr),True,(255,255,255))
screen.blit(scoreSurf,(880,110)) screen.blit(scoreSurf,(880,110))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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