Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_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
cff5a89d
authored
May 13, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
4d5752a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
snake.py
sb.py → snake_No.2.py
snake.py
View file @
cff5a89d
...
@@ -55,7 +55,6 @@ while True:
...
@@ -55,7 +55,6 @@ while True:
else
:
else
:
y
+=
30
y
+=
30
position
.
append
((
x
,
y
))
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇的头画上去
# 将贪吃蛇的头画上去
...
@@ -63,13 +62,15 @@ while True:
...
@@ -63,13 +62,15 @@ 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
))
if
x
==
apple_x
and
y
==
apple_y
:
if
x
==
apple_x
and
y
==
apple_y
:
apple_x
=
random
.
randint
(
0
,
660
)
a_x
=
random
.
randint
(
1
,
22
)
apple_y
=
random
.
randint
(
0
,
480
)
a_y
=
random
.
randint
(
1
,
16
)
apple_x
=
a_x
*
30
-
30
apple_y
=
a_y
*
30
-
30
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
else
:
position
.
pop
(
0
)
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
FPSCLOCK
.
tick
(
3
)
\ No newline at end of file
s
b
.py
→
s
nake_No.2
.py
View file @
cff5a89d
...
@@ -23,8 +23,8 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
...
@@ -23,8 +23,8 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading
=
"right"
setheading
=
"right"
snake_head
=
right
snake_head
=
right
apple
_x
=
360
food
_x
=
360
apple
_y
=
300
food
_y
=
300
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
...
@@ -65,13 +65,13 @@ while True:
...
@@ -65,13 +65,13 @@ while True:
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
body
,
position
[
i
])
# 将果实画上去
# 将果实画上去
screen
.
blit
(
food
,
(
apple_x
,
apple
_y
))
screen
.
blit
(
food
,
(
food_x
,
food
_y
))
if
x
==
apple_x
and
y
==
apple
_y
:
if
x
==
food_x
and
y
==
food
_y
:
apple_x
=
random
.
randint
(
0
,
2
2
)
apple_x
=
random
.
randint
(
0
,
2
1
)
apple_y
=
random
.
randint
(
0
,
1
6
)
apple_y
=
random
.
randint
(
0
,
1
5
)
food_x
=
food_x
=
apple_x
*
30
food_y
=
food_y
=
apple_y
*
30
screen
.
blit
(
food
,
(
apple_x
*
30
,
apple
_y
*
30
))
screen
.
blit
(
food
,
(
food_x
*
30
,
food
_y
*
30
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
FPSCLOCK
.
tick
(
3
)
\ 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