Commit fea54e88 by BellCodeEditor

save project

parent 60a0cbb3
Showing with 31 additions and 2 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
with open ('record.txt','r', encoding='utf-8') as file:
record_o=file.read()
record = json.loads(record_o)
one = record['第一名']
two = record['第二名']
three = record['第三名']
class Block(pygame.sprite.Sprite): # 障碍物精灵类 class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
...@@ -119,10 +126,31 @@ while True: ...@@ -119,10 +126,31 @@ 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 score1>three:
if score1>one:
record['第一名'] = score1
record['第二名'] = one
record['第三名'] = two
elif score1>two:
record['第二名'] = score1
record['第三名'] = two
else:
record['第三名'] = three
paim1 = basic_font.render('第一名:'+str(record['第一名']),True, (255,255,255))
paim2 = basic_font.render('第二名:'+str(record['第二名']),True, (255,255,255))
paim3 = basic_font.render('第三名:'+str(record['第三名']),True, (255,255,255))
screen.blit(paim1,(880,50))
screen.blit(paim2,(880,80))
screen.blit(paim3,(880,110))
record=json.dumps(record, ensure_ascii=False)
with open('record.txt','w',encoding='utf-8') as file:
file.write(record)
scoreSurf = basic_font.render('分数:'+str(score1),True, (255,255,255)) scoreSurf = basic_font.render('分数:'+str(score1),True, (255,255,255))
screen.blit(scoreSurf,(880,20)) screen.blit(scoreSurf,(880,20))
if score1 %100==0: if score1 %100==0:
score_audio.play() score_audio.play()
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0} {"第一名": 39, "第二名": 15, "第三名": 0}
\ 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