Commit 0fa8e4b7 by BellCodeEditor

save project

parent 43975e73
import json
jsonData='{"第一名":122,"第二名":109,"第三名":88}'
text=json.loads(jsonData)
print("第一名:",text['第一名'])
print("第二名:",text['第二名'])
print("第三名:",text['第三名'])
\ No newline at end of file
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类 class Block(pygame.sprite.Sprite): # 障碍物精灵类
...@@ -50,7 +50,12 @@ time = 0 ...@@ -50,7 +50,12 @@ time = 0
gamestate = True gamestate = True
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
with open('score.txt','r',encoding='utf-8')as f:
content=f.read()
record = json.loads(content)
one = record['第一名']
two = record['第二名']
thr = record['第三名']
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:
......
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
score=0 score=0
speed=8 speed=8
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -100,7 +101,12 @@ while True: ...@@ -100,7 +101,12 @@ while True:
screen.blit(road, (road_x, 500)) # 道路 screen.blit(road, (road_x, 500)) # 道路
screen.blit(wukong.image, (150, y)) # 悟空 screen.blit(wukong.image, (150, y)) # 悟空
with open('record.txt','r',encoding='utf-8')as f:
content=f.read()
record = json.loads(content)
one = record['第一名']
two = record['第二名']
thr = record['第三名']
time += 1 time += 1
if time >= 60: # 创建障碍物精灵 if time >= 60: # 创建障碍物精灵
time = 0 time = 0
...@@ -124,6 +130,13 @@ while True: ...@@ -124,6 +130,13 @@ while True:
speed=8+score//3 speed=8+score//3
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0)) scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20)) screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第一名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,50))
scoreSurf = basic_font.render("第二名:"+str(two),True,(255,0,0))
screen.blit(scoreSurf,(850,80))
scoreSurf = basic_font.render("第三名:"+str(thr),True,(255,0,0))
screen.blit(scoreSurf,(850,110))
if old_score<score: if old_score<score:
score_audio.play() score_audio.play()
old_score=score old_score=score
......
{"第1名": 0, "第2名": 0, "第3名": 0} {"第一名": 0, "第二名": 0, "第三名": 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