Commit 17c9ea4a by BellCodeEditor

save project

parent 8953883f
Showing with 32 additions and 2 deletions
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
......@@ -57,6 +58,14 @@ old_score = score
block_list =pygame.sprite.Group() # 创建精灵组
with open('record.txt','r',encoding='utf-8') as f:
cotent = f.read()
record = json.loads(content)
one = record["第一名"]
two = record["第二名"]
three = record["第三名"]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -121,6 +130,21 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
gamestate = False
if score > three:
if score > one:
record["第一名"] = score
record["第二名"] = two
record["第三名"] = three
elif score > two:
record["第一名"] = one
record["第二名"] = score
record["第三名"] = three
else:
record["第三名"] = score
record=json.dumps(record,ensure_ascii=False)
with open('record.txt','r',encoding='utf-8') as f:
f.write(recoed)
else:
if(sprite.rect.x+sprite.rect.width) < wukong.rect.x:
score += sprite.score
......@@ -130,8 +154,13 @@ while True:
old_score = score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
screen.blit(scoreSurf,(880,20))
scoreSurf = basic_font.render("第一名:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(880,50))
scoreSurf = basic_font.render("第二名:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(880,80))
scoreSurf = basic_font.render("第三名:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(880,110))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ 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