Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson9_diy1
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
3db53a74
authored
Jul 17, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
3bb2e58c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
3 deletions
my_game.py
record.txt
score.txt
my_game.py
View file @
3db53a74
import
pygame
from
pygame
import
locals
import
random
import
json
pygame
.
init
()
# 初始化
...
...
@@ -51,6 +52,16 @@ gamestate = True
block_list
=
pygame
.
sprite
.
Group
()
# 创建精灵组
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
20
)
score
=
0
with
open
(
'score.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
content
=
file
.
read
()
recode
=
json
.
loads
(
content
)
one
=
recode
[
'第1名'
]
two
=
recode
[
'第2名'
]
three
=
recode
[
'第3名'
]
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -109,12 +120,39 @@ while True:
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
score
+=
1
sprite
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
# 精灵碰撞检测
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
# 游戏结束
screen
.
blit
(
gameover
,
(
400
,
200
))
gamestate
=
False
gamestate
=
False
if
score
>
three
:
if
score
>
one
:
recode
[
'第1名'
]
=
score
recode
[
'第2名'
]
=
one
recode
[
'第3名'
]
=
two
elif
score
>
two
:
recode
[
'第2名'
]
=
score
recode
[
'第3名'
]
=
two
else
:
recode
[
'第3名'
]
=
score
recode
=
json
.
dumps
(
recode
,
ensure_ascii
=
False
)
with
open
(
'score.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
recode
)
text
=
font
.
render
(
'分数:'
+
str
(
score
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
900
,
20
))
text1
=
font
.
render
(
'第1名:'
+
str
(
one
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
text1
,(
900
,
50
))
text2
=
font
.
render
(
'第2名:'
+
str
(
two
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
text2
,(
900
,
80
))
text3
=
font
.
render
(
'第3名:'
+
str
(
three
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
text3
,(
900
,
110
))
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
record.txt
deleted
100644 → 0
View file @
3bb2e58c
{"第1名": 0, "第2名": 0, "第3名": 0}
\ No newline at end of file
score.txt
0 → 100644
View file @
3db53a74
{"第1名": 4, "第2名": 4, "第3名": 1}
\ 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