Commit 47205131 by BellCodeEditor

save project

parent 7bc95711
Showing with 17 additions and 11 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -25,8 +27,12 @@ class Player(pygame.sprite.Sprite): # 悟空 ...@@ -25,8 +27,12 @@ class Player(pygame.sprite.Sprite): # 悟空
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = 150 self.rect.x = 150
self.rect.y = 400 self.rect.y = 400
with open('record.txt','r',encoding='utf-8') as : with open('record.txt','r',encoding='utf-8') as f:
record = content = f.read()
record = json.loads(content)
one = record['第1名']
two = record['第2名']
three = record['第3名']
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -128,14 +134,14 @@ while True: ...@@ -128,14 +134,14 @@ while True:
if score > oldscore: if score > oldscore:
scoremusic.play() scoremusic.play()
oldscore = score oldscore = score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0)) scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第一名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第二名:"+str(two),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第三名:"+str(three),True,(255,0,0))
screen.blit(scoreSurf,(850,20)) screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第一名:"+str(one),True,(255,255,255))
screen.blit(scoreSurf,(850,60))
scoreSurf = basic_font.render("第二名:"+str(two),True,(255,255,255))
screen.blit(scoreSurf,(850,100))
scoreSurf = basic_font.render("第三名:"+str(three),True,(255,255,255))
screen.blit(scoreSurf,(850,140))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
{"第1名": 0, "第2名": 0, "第3名": 0} {"第1名": 99999999, "第2名": 9999999, "第3名": 999999}
\ 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