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
1a54bc4d
authored
Jan 20, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
bc0c4549
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
Coin.wav
my_game.py
score.txt
Coin.wav
0 → 100644
View file @
1a54bc4d
File added
my_game.py
View file @
1a54bc4d
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
import
json
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建一个窗口
# 创建一个窗口
...
@@ -43,11 +44,22 @@ time=0
...
@@ -43,11 +44,22 @@ time=0
road_x
=
0
road_x
=
0
bg_x
=
0
bg_x
=
0
c
=
True
c
=
True
score
=
0
score
=
2
speed
=
8
speed
=
10
old_score
=
0
score_music
=
pygame
.
mixer
.
Sound
(
"Coin.wav"
)
with
open
(
"score.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
fion
:
abc
=
fion
.
read
()
bdc
=
json
.
loads
(
abc
)
one
=
bdc
[
"第1名"
]
two
=
bdc
[
"第2名"
]
three
=
bdc
[
"第3名"
]
while
True
:
while
True
:
speed
=
8
+
score
//
3
speed
=
10
+
score
//
2
if
score
>
old_score
:
score_music
.
play
()
old_score
=
score
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
...
@@ -103,6 +115,19 @@ while True:
...
@@ -103,6 +115,19 @@ while True:
gameover
=
pygame
.
image
.
load
(
"gameover.png"
)
gameover
=
pygame
.
image
.
load
(
"gameover.png"
)
screen
.
blit
(
gameover
,(
400
,
200
))
screen
.
blit
(
gameover
,(
400
,
200
))
c
=
False
c
=
False
if
score
>
three
:
if
score
>
one
:
bdc
[
"第1名"
]
=
score
bdc
[
"第2名"
]
=
one
bdc
[
"第3名"
]
=
two
elif
score
>
two
:
bdc
[
"第2名"
]
=
score
bdc
[
"第3名"
]
=
two
else
:
bdc
[
"第3名"
]
=
score
bdc
=
json
.
dumps
(
bdc
,
ensure_ascii
=
False
)
with
open
(
"score.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
fion_1
:
fion_1
.
write
(
bdc
)
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
...
@@ -110,6 +135,12 @@ while True:
...
@@ -110,6 +135,12 @@ while True:
info
=
"游戏分数:"
+
str
(
score
)
info
=
"游戏分数:"
+
str
(
score
)
text
=
font
.
render
(
info
,
True
,(
255
,
255
,
255
))
text
=
font
.
render
(
info
,
True
,(
255
,
255
,
255
))
screen
.
blit
(
text
,(
880
,
20
))
screen
.
blit
(
text
,(
880
,
20
))
one_1
=
font
.
render
(
"第一名"
+
str
(
one
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
one_1
,(
880
,
45
))
two_1
=
font
.
render
(
"第二名"
+
str
(
two
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
two_1
,(
880
,
70
))
three_1
=
font
.
render
(
"第三名"
+
str
(
three
),
True
,(
255
,
255
,
255
))
screen
.
blit
(
three_1
,(
880
,
95
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
61
)
\ No newline at end of file
\ No newline at end of file
score.txt
View file @
1a54bc4d
{"第1名": 0, "第2名": 0, "第3名": 0}
{"第1名": 75, "第2名": 15, "第3名": 10}
\ 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