Commit 6770fbf5 by BellCodeEditor

auto save

parent 0c19e969
Showing with 22 additions and 10 deletions
......@@ -18,7 +18,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
self.rect.y = 500 - self.rect.height
class Player(pygame.sprite.Sprite): # 悟空
def __init__( self, image):
def __init__(self, image):
super().__init__()
# 加载悟空精灵图像
self.image = image
......@@ -52,15 +52,15 @@ bg_x = 0
time = 0
gamestate = True
score = 0
ole_score = score
old_score = score
block_list =pygame.sprite.Group() # 创建精灵组
with open('score.txt','r',encoding='utf-8')as f:
concert = f.read()
recond=json.loads(content)
one=content['第一名']
two=content['第二名']
thr=content['第三名']
recond=json.loads(concert)
one=recond['第1名']
two=recond['第2名']
three=recond['第3名']
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -124,10 +124,23 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
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:
if(sprite.rect.x+sprite.rect.width)<wukong.rect.x:
score+=sprite.score
sprite.score+0
if score>old_score:
score_audio.play()
old_score=score
......@@ -142,5 +155,4 @@ while True:
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