Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_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
5d3b0def
authored
Sep 16, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
26ee8c67
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
score.txt
w.py
score.txt
View file @
5d3b0def
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第1名": 69, "第2名": 32, "第3名": 10}
\ No newline at end of file
\ No newline at end of file
w.py
View file @
5d3b0def
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
import
json
pygame
.
init
()
pygame
.
init
()
...
@@ -52,6 +53,13 @@ gamestate = True
...
@@ -52,6 +53,13 @@ gamestate = True
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
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
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -114,6 +122,20 @@ while True:
...
@@ -114,6 +122,20 @@ while True:
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gameover
,(
400
,
200
))
screen
.
blit
(
gameover
,(
400
,
200
))
gamestate
=
False
gamestate
=
False
if
score
>
three
:
if
score
>
one
:
record
[
"第1名"
]
=
score
record
[
"第2名"
]
=
two
record
[
"第3名"
]
=
three
elif
score
>
two
:
record
[
"第2名"
]
=
score
record
[
"第3名"
]
=
two
else
:
record
[
"第3名"
]
=
score
record
=
json
.
dumps
(
record
,
ensure_ascii
=
False
)
with
open
(
'score.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
record
)
else
:
else
:
if
sprite
.
rect
.
x
+
sprite
.
rect
.
width
<
wukong
.
rect
.
x
:
if
sprite
.
rect
.
x
+
sprite
.
rect
.
width
<
wukong
.
rect
.
x
:
score
+=
sprite
.
score
score
+=
sprite
.
score
...
@@ -125,6 +147,12 @@ while True:
...
@@ -125,6 +147,12 @@ while True:
scoreSurf
=
basic_font
.
render
(
"分数:"
+
str
(
score
),
True
,(
255
,
255
,
0
))
scoreSurf
=
basic_font
.
render
(
"分数:"
+
str
(
score
),
True
,(
255
,
255
,
0
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
scoreSurf
=
basic_font
.
render
(
"第1名:"
+
str
(
one
),
True
,(
255
,
255
,
0
))
screen
.
blit
(
scoreSurf
,(
880
,
50
))
scoreSurf
=
basic_font
.
render
(
"第2名:"
+
str
(
two
),
True
,(
255
,
255
,
0
))
screen
.
blit
(
scoreSurf
,(
880
,
80
))
scoreSurf
=
basic_font
.
render
(
"第3名:"
+
str
(
three
),
True
,(
255
,
255
,
0
))
screen
.
blit
(
scoreSurf
,(
880
,
110
))
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ 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