Commit 5d3b0def by BellCodeEditor

auto save

parent 26ee8c67
Showing with 31 additions and 2 deletions
{"第1名": 0, "第2名": 0, "第3名": 0} {"第1名": 69, "第2名": 32, "第3名": 10}
\ No newline at end of file \ No newline at end of file
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() pygame.init()
...@@ -52,6 +53,13 @@ gamestate = True ...@@ -52,6 +53,13 @@ gamestate = True
block_list = pygame.sprite.Group() block_list = pygame.sprite.Group()
with open('score.txt','r',encoding='utf-8') as f:
content = f.read()
record = json.loads(content)
one = record["第1名"]
two = record["第2名"]
three = record["第3名"]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -114,6 +122,20 @@ while True: ...@@ -114,6 +122,20 @@ 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 > three:
if score > one:
record["第1名"] = score
record["第2名"] = two
record["第3名"] = three
elif score > two:
record["第2名"] = score
record["第3名"] = two
else:
record["第3名"] = score
record = json.dumps(record,ensure_ascii=False)
with open('score.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:
score += sprite.score score += sprite.score
...@@ -125,6 +147,12 @@ while True: ...@@ -125,6 +147,12 @@ while True:
scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,0)) scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,0))
screen.blit(scoreSurf,(880,20)) screen.blit(scoreSurf,(880,20))
scoreSurf = basic_font.render("第1名:"+str(one),True,(255,255,0))
screen.blit(scoreSurf,(880,50))
scoreSurf = basic_font.render("第2名:"+str(two),True,(255,255,0))
screen.blit(scoreSurf,(880,80))
scoreSurf = basic_font.render("第3名:"+str(three),True,(255,255,0))
screen.blit(scoreSurf,(880,110))
pygame.display.update() pygame.display.update()
FPS.tick(60) 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