Commit 2be7033f by BellCodeEditor

save project

parent 660206c6
Showing with 26 additions and 12 deletions
...@@ -61,10 +61,10 @@ old_fenshu = 0 ...@@ -61,10 +61,10 @@ old_fenshu = 0
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
with open("record.txt","r",encoding="utf-8") as f: with open("record.txt","r",encoding="utf-8") as f:
content = f.read() content = f.read()
score = json.loads(content) record = json.loads(content)
a = content["第1名"] a = record["第1名"]
b = content["第2名"] b = record["第2名"]
c = content["第3名"] c = record["第3名"]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -128,6 +128,19 @@ while True: ...@@ -128,6 +128,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))
gamestate = False gamestate = False
if fenshu > c:
if fenshu > a:
record["第1名"] = fenshu
record["第2名"] = a
record["第3名"] = b
elif fenshu >b:
record["第2名"] = fenshu
record["第3名"] = b
else:
record["第3名"] = fenshu
record = json.dumps(record,ensure_ascii=False)
with open("record.txt","w",encoding="utf-8") as f:
f.write(record)
else: else:
if (sprite.rect.x + sprite.rect.width) < wukong.rect.x: if (sprite.rect.x + sprite.rect.width) < wukong.rect.x:
fenshu = sprite.fenshu + fenshu fenshu = sprite.fenshu + fenshu
...@@ -142,14 +155,14 @@ while True: ...@@ -142,14 +155,14 @@ while True:
v = my_v.render(info1,True,(220,180,200)) v = my_v.render(info1,True,(220,180,200))
screen.blit(v, (900, 40)) screen.blit(v, (900, 40))
chengjia = "第1名" + ":" + str(a) chengjia = "第1名" + ":" + str(a)
aa = my_chengjia.render(chengjia,True,(200,220,150)) aa = my_chengjia.render(chengjia,True,(200,0,150))
screen.blit(aa, (100, 20)) screen.blit(aa, (50, 20))
chengjib = "第2名" + ":" + str(b) chengjib = "第2名" + ":" + str(b)
bb = my_chengjib.render(chengjib,True,(200,220,150)) bb = my_chengjib.render(chengjib,True,(200,100,150))
screen.blit(bb, (100, 40)) screen.blit(bb, (50, 40))
chengjic = "第3名" + ":" + str(c) chengjic = "第3名" + ":" + str(c)
cc = my_chengjic.render(chengjic,True,(200,220,150)) cc = my_chengjic.render(chengjic,True,(200,150,150))
screen.blit(cc, (100, 60)) screen.blit(cc, (50, 60))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0} {"第1名": 11, "第2名": 2, "第3名": 1}
\ 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