Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy4
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
64bfc0c5
authored
Jun 17, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9f65c214
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletions
my_game.py
my_game.py
View file @
64bfc0c5
import
pygame
from
pygame
import
locals
import
random
import
json
pygame
.
init
class
Block
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
...
...
@@ -45,6 +47,13 @@ screen = 0
old_screen
=
screen
block_list
=
pygame
.
sprite
.
Group
()
with
open
(
'score.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
content
=
f
.
read
()
record
=
json
.
loads
(
content
)
one
=
content
[
"第一名"
]
two
=
content
[
"第二名"
]
thr
=
content
[
"第三名"
]
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -90,6 +99,17 @@ while True:
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
screen
.
blit
(
gameover
,
(
400
,
200
))
gametate
=
False
if
score
>
three
:
if
score
>
one
:
record
[
"第一名"
]
=
score
record
[
"第二名"
]
=
one
record
[
"第三名"
]
=
two
elif
score
>
two
:
record
[
"第二名"
]
=
score
record
[
"第三名"
]
=
two
else
:
record
[
"第三名"
]
=
score
record
=
json
.
dumps
(
record
,
ensure_ascii
=
False
)
else
:
if
(
sprite
.
rect
.
x
+
sprite
.
rect
.
width
)
<
wukong
.
rect
.
x
:
score
+=
sprite
.
score
...
...
@@ -103,7 +123,14 @@ while True:
aa
.
rect
.
x
-=
8
scoreSurf
=
basic_font
.
render
(
"分数:"
+
str
(
score
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
scoreSurf
=
basic_font
.
render
(
"第一名:"
+
str
(
one
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
50
))
scoreSurf
=
basic_font
.
render
(
"第二名:"
+
str
(
two
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
80
))
scoreSurf
=
basic_font
.
render
(
"第三名:"
+
str
(
thr
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
110
))
screen
.
blit
(
aa
.
image
,
(
aa
.
rect
.
x
,
aa
.
rect
.
y
))
# 刷新画面
pygame
.
display
.
update
()
...
...
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