Commit e49a3760 by BellCodeEditor

save project

parent 67686519
Showing with 23 additions and 11 deletions
......@@ -43,7 +43,7 @@ gameover = pygame.image.load('gameover.png')
chenggong = pygame.image.load('cg.png')
block_list = pygame.sprite.Group()
basic_font = pygame.font.Font('STKAITI.TTF',32)
basic_font = pygame.font.Font('STKAITI.TTF',30)
score_music = pygame.mixer.Sound('score.wav')
#pygame.mixer.music.load('孤勇者.mp3')
pygame.mixer.music.load('西瓜冬瓜哈密瓜(抖音DJ完整版) - 莹酱.mp3')
......@@ -59,12 +59,12 @@ speed = 15
kaishi = 'T'
score = 0
#创建障碍物
with open("score.txt","r",encoding="utf-8") as f:
with open("record.txt","r",encoding="utf-8") as f:
content = f.read()
zhi = json.loads(content)
one = zhi["第1名"]
two = zhi["第2名"]
three = zhi["第3名"]
record = json.loads(content)
one = record["第1名"]
two = record["第2名"]
three = record["第3名"]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -126,6 +126,19 @@ while True:
if pygame.sprite.collide_rect(wukong,sprite):
screen.blit(gameover, (400,200))
kaishi = 'F'
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)
with open("record.txt","w",encoding="utf-8") as s:
s.write()
else:
if sprite.rect.x + sprite.rect.width < 150:
score += sprite.score
......@@ -143,9 +156,9 @@ while True:
yi = basic_font.render("第1名:" + str(one),True,(0,0,0))
er = basic_font.render("第2名:" + str(two),True,(0,0,0))
san = basic_font.render("第3名:" + str(three),True,(0,0,0))
screen.blit(yi,(850,100))
screen.blit(er,(850,150))
screen.blit(san,(850,200))
screen.blit(yi,(850,50))
screen.blit(er,(850,80))
screen.blit(san,(850,110))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0}
\ 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