Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_diy3
This project
Loading...
Sign in
Toggle navigation
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
47205131
authored
Jul 31, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
7bc95711
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
11 deletions
my_game.py
record.txt
my_game.py
View file @
47205131
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
()
...
...
record.txt
View file @
47205131
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第1名": 99999999, "第2名": 9999999, "第3名": 999999}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment