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
fea54e88
authored
Aug 13, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
60a0cbb3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
my_game.py
record.txt
my_game.py
View file @
fea54e88
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
import
json
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
with
open
(
'record.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
record_o
=
file
.
read
()
record
=
json
.
loads
(
record_o
)
one
=
record
[
'第一名'
]
two
=
record
[
'第二名'
]
three
=
record
[
'第三名'
]
class
Block
(
pygame
.
sprite
.
Sprite
):
# 障碍物精灵类
class
Block
(
pygame
.
sprite
.
Sprite
):
# 障碍物精灵类
def
__init__
(
self
,
image1
,
image2
,
image3
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
...
@@ -119,10 +126,31 @@ while True:
...
@@ -119,10 +126,31 @@ 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
score1
>
three
:
if
score1
>
one
:
record
[
'第一名'
]
=
score1
record
[
'第二名'
]
=
one
record
[
'第三名'
]
=
two
elif
score1
>
two
:
record
[
'第二名'
]
=
score1
record
[
'第三名'
]
=
two
else
:
record
[
'第三名'
]
=
three
paim1
=
basic_font
.
render
(
'第一名:'
+
str
(
record
[
'第一名'
]),
True
,
(
255
,
255
,
255
))
paim2
=
basic_font
.
render
(
'第二名:'
+
str
(
record
[
'第二名'
]),
True
,
(
255
,
255
,
255
))
paim3
=
basic_font
.
render
(
'第三名:'
+
str
(
record
[
'第三名'
]),
True
,
(
255
,
255
,
255
))
screen
.
blit
(
paim1
,(
880
,
50
))
screen
.
blit
(
paim2
,(
880
,
80
))
screen
.
blit
(
paim3
,(
880
,
110
))
record
=
json
.
dumps
(
record
,
ensure_ascii
=
False
)
with
open
(
'record.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
record
)
scoreSurf
=
basic_font
.
render
(
'分数:'
+
str
(
score1
),
True
,
(
255
,
255
,
255
))
scoreSurf
=
basic_font
.
render
(
'分数:'
+
str
(
score1
),
True
,
(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
screen
.
blit
(
scoreSurf
,(
880
,
20
))
if
score1
%
100
==
0
:
if
score1
%
100
==
0
:
score_audio
.
play
()
score_audio
.
play
()
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ No newline at end of file
record.txt
View file @
fea54e88
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第一名": 39, "第二名": 15, "第三名": 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