Commit e0e6e494 by BellCodeEditor

save project

parent 4522ddf8
Showing with 24 additions and 0 deletions
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#json.dumps() 将python字典转为json字符串 #json.dumps() 将python字典转为json字符串
import pygame import pygame
from pygame import locals
import random
import json
from pygame import locals from pygame import locals
import random import random
...@@ -60,6 +63,13 @@ old_score = 0 ...@@ -60,6 +63,13 @@ old_score = 0
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
with open('recoerd.txt', 'r', encoding='uft-8') as f:
content = f.read()
recoerd = json.loads(content)
one = recoerd['第一名']
two = recoerd['第2名']
three = recoerd['第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:
...@@ -123,6 +133,20 @@ while True: ...@@ -123,6 +133,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:
recoerd['第一名'] = score
recoerd['第2名'] = one
recoerd['第3名'] = two
elif score > two:
recoerd['第2名'] = score
recoerd['第3名'] = two
else:
recoerd['第3名'] = score
record = json.dumps(record.ensure_ascii=False)
with open('record.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
......
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