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
34f5e514
authored
Aug 11, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
ce16b2e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
my_game.py
record.txt
my_game.py
View file @
34f5e514
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
import
json
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
...
@@ -55,6 +56,14 @@ old_score=0
...
@@ -55,6 +56,14 @@ old_score=0
speed
=
9
speed
=
9
block_list
=
pygame
.
sprite
.
Group
()
# 创建精灵组
block_list
=
pygame
.
sprite
.
Group
()
# 创建精灵组
with
open
(
'record.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
record1
=
file
.
read
()
record
=
json
.
loads
(
record1
)
one
=
record
[
"第一名"
]
two
=
record
[
"第二名"
]
three
=
record
[
"第三名"
]
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -127,9 +136,22 @@ while True:
...
@@ -127,9 +136,22 @@ while True:
score
+=
sprite
.
score
score
+=
sprite
.
score
sprite
.
score
=
0
sprite
.
score
=
0
defen
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
40
)
defen
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
30
)
text
=
defen
.
render
(
'得分:'
+
str
(
score
),
True
,(
0
,
0
,
0
))
text
=
defen
.
render
(
'得分:'
+
str
(
score
),
True
,(
1
,
225
,
225
))
screen
.
blit
(
text
,(
400
,
20
))
screen
.
blit
(
text
,(
800
,
20
))
reco1
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
30
)
record1
=
reco1
.
render
(
'第一名:'
+
str
(
one
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
record1
,(
800
,
60
))
reco2
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
30
)
record2
=
reco2
.
render
(
'第二名:'
+
str
(
two
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
record2
,(
800
,
100
))
reco3
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
30
)
record3
=
reco3
.
render
(
'第一名:'
+
str
(
three
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
record3
,(
800
,
140
))
score_audio
=
pygame
.
mixer
.
Sound
(
'score.wav'
)
score_audio
=
pygame
.
mixer
.
Sound
(
'score.wav'
)
if
score
>
old_score
:
if
score
>
old_score
:
...
...
record.txt
View file @
34f5e514
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第一名": 0, "第二名": 0, "第三名": 0}
\ 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