Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson7_diy1

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 96439e85 authored a year ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent 8462f98c
Show whitespace changes
Inline Side-by-side
Showing with 20 additions and 1 deletions
  • my_game.py
  • score.wav
my_game.py
View file @ 96439e85
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -46,9 +47,20 @@ time = 0 ...@@ -46,9 +47,20 @@ time = 0
Game = True Game = True
score = 0 score = 0
speed = 8 speed = 8
music_1 = pygame.mixer.Sound("score.wav")
old_score = 0
with open("score.txt","r",encoding = "utf-8") as f:
content = f.read()
record = json.loads(content)
one = record["第1名"]
two = record["第2名"]
three = record["第3名"]
while True: while True:
speed = 8 + score // 3 speed = 8 + score // 3
if score > old_score:
music_1.play()
old_score = score
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -112,6 +124,12 @@ while True: ...@@ -112,6 +124,12 @@ while True:
# 刷新画面 # 刷新画面
info = "分数:" + str(score) info = "分数:" + str(score)
text = font.render(info,True,(255,255,255)) text = font.render(info,True,(255,255,255))
screen.blit(text,(900,20)) screen.blit(text,(880,20))
one_1 = font.render("第一名:" + str(one),True,(255,255,255))
screen.blit(one_1,(880,40))
two_1 = font.render("第二名:" + str(two),True,(255,255,255))
screen.blit(two_1,(880,60))
three_1 = font.render("第三名:" + str(one),True,(255,255,255))
screen.blit(three_1,(880,80))
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
This diff is collapsed. Click to expand it.
score.wav 0 → 100644
View file @ 96439e85
File added
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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