Commit 6770fbf5 by BellCodeEditor

auto save

parent 0c19e969
Showing with 22 additions and 10 deletions
...@@ -18,7 +18,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类 ...@@ -18,7 +18,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
self.rect.y = 500 - self.rect.height self.rect.y = 500 - self.rect.height
class Player(pygame.sprite.Sprite): # 悟空 class Player(pygame.sprite.Sprite): # 悟空
def __init__( self, image): def __init__(self, image):
super().__init__() super().__init__()
# 加载悟空精灵图像 # 加载悟空精灵图像
self.image = image self.image = image
...@@ -52,15 +52,15 @@ bg_x = 0 ...@@ -52,15 +52,15 @@ bg_x = 0
time = 0 time = 0
gamestate = True gamestate = True
score = 0 score = 0
ole_score = score 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('score.txt','r',encoding='utf-8')as f:
concert = f.read() concert = f.read()
recond=json.loads(content) recond=json.loads(concert)
one=content['第一名'] one=recond['第1名']
two=content['第二名'] two=recond['第2名']
thr=content['第三名'] three=recond['第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:
...@@ -124,10 +124,23 @@ while True: ...@@ -124,10 +124,23 @@ 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:
recond['第1名']=score
recond['第2名']=one
record['第3名']=two
elif score>two:
recond['第2名']=score
recond['第3名']=two
else:
recond['第3名']=score
recond=json.dumps(recond,ensure_ascii=False)
with open('record.txt','w',encoding='utf_8')as f:
f.write(recond)
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
sprite.score+0
if score>old_score: if score>old_score:
score_audio.play() score_audio.play()
old_score=score old_score=score
...@@ -142,5 +155,4 @@ while True: ...@@ -142,5 +155,4 @@ while True:
screen.blit(scoreSurf,(880,110)) screen.blit(scoreSurf,(880,110))
# 刷新画面 # 刷新画面
pygame.display.update()
FPS.tick(60) \ 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