Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_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
85e005d6
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
24e404e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
snake.py
snake.py
View file @
85e005d6
...
@@ -30,12 +30,14 @@ setheading = "right"
...
@@ -30,12 +30,14 @@ setheading = "right"
snake_head
=
right
snake_head
=
right
while
True
:
while
True
:
a
=
random
.
randint
(
0
,
10
)
a
=
random
.
randint
(
2
,
5
)
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
print
(
"您已退出"
)
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
setheading
=
'right'
setheading
=
'right'
...
@@ -66,6 +68,15 @@ while True:
...
@@ -66,6 +68,15 @@ while True:
score
+=
10
score
+=
10
else
:
else
:
position
.
pop
(
0
)
position
.
pop
(
0
)
if
x
<
0
or
x
>
630
or
y
<
0
or
y
>
450
:
print
(
'您撞到了边框'
)
exit
()
if
position
[
-
1
]
in
position
[:
-
1
]:
print
(
'您撞到了自己'
)
exit
()
# if (apple_x,apple_y) in position[:len[position]-2]:
# if (apple_x,apple_y) in position[:len[position]-2]:
# apple_x=(random.randint(0,630))//30*30
# apple_x=(random.randint(0,630))//30*30
# apple_y=(random.randint(0,450))//30*30
# apple_y=(random.randint(0,450))//30*30
...
@@ -76,7 +87,6 @@ while True:
...
@@ -76,7 +87,6 @@ while True:
# 将贪吃蛇的身体画上去
# 将贪吃蛇的身体画上去
for
i
in
range
(
len
(
position
)
-
1
):
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
body
,
position
[
i
])
# 将果实画上去
# 将果实画上去
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
info
=
'Score:'
+
str
(
score
)
info
=
'Score:'
+
str
(
score
)
...
...
This diff is collapsed.
Click to expand it.
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