Commit 04f88e01 by BellCodeEditor

save project

parent 2502fb50
Showing with 13 additions and 14 deletions
...@@ -6,8 +6,6 @@ pygame.init() # 初始化 ...@@ -6,8 +6,6 @@ pygame.init() # 初始化
with open('record.txt','r',encoding='utf-8')as file: with open('record.txt','r',encoding='utf-8')as file:
content=file.read() content=file.read()
record=json.loads(content) record=json.loads(content)
print(record)
one,two,three=record["第1名"],record["第2名"],record["第3名"]
class Block(pygame.sprite.Sprite): # 障碍物精灵类 class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__() super().__init__()
...@@ -123,19 +121,20 @@ while True: ...@@ -123,19 +121,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名']=one
record['第3名']=two
elif score>two:
record['第2名']=score
record['第3名']=two
else:
record['第3名']=score
record=json.dumps(record,ensure_ascii=False) record=json.dumps(record,ensure_ascii=False)
with open('record.txt','w',encoding='utf-8')as file: with open('record.txt','w',encoding='utf-8')as file:
file.write(record) file.write(record)
one,two,three=record["第1名"],record["第2名"],record["第3名"]
if score>three:
if score>one:
record['第1名']=score
record['第2名']=one
record['第3名']=two
elif score>two:
record['第2名']=score
record['第3名']=two
else:
record['第3名']=score
word='分数:'+str(score)+' 第一名:'+str(one)+' 第二名:'+str(two)+' 第三名:'+str(three) word='分数:'+str(score)+' 第一名:'+str(one)+' 第二名:'+str(two)+' 第三名:'+str(three)
text=f.render(word,True,(0,0,0)) text=f.render(word,True,(0,0,0))
screen.blit(text,(0,0)) screen.blit(text,(0,0))
......
{"第1名": 23, "第2名": 11, "第3名": 0} {"第1名": 30, "第2名": 23, "第3名": 11}
\ 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