Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson3-1-1_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
0153b43e
authored
a year ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
5481f1fb
c374653l762p219a8068/wx013242
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
772 additions
and
16 deletions
diy1.py
diy1.py
View file @
0153b43e
# 利用write()帮助悟空给诺依回信吧~
import
turtle
# pen=turtle.Pen()
# pen.write("菜就多练",font=("Times",20,"normal"))
# pen1.hideturtle()
# turtle.done()
pen1
=
turtle
.
Pen
()
pen1
.
left
(
45
)
pen1
.
forward
(
100
)
pen1
.
circle
(
50
,
180
)
pen1
.
right
(
90
)
pen1
.
circle
(
50
,
180
)
pen1
.
forward
(
100
)
pen1
.
hideturtle
()
turtle
.
done
()
\ No newline at end of file
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
# 利用write()帮助悟空给诺依回信吧~"菜就多练!"
import
pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.pug'
)
right
=
pygame
.
image
.
load
(
'right.pug'
)
food
=
pygame
.
image
.
load
(
'food.pug'
)
body
=
pygame
.
image
.
load
(
'body.pug'
)
left
=
pygame
.
image
.
load
(
'left.pug'
)
up
=
pygame
.
image
.
load
(
'up.pug'
)
down
=
pygame
.
image
.
load
(
'down.pug'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
apple_x
=
360
apple_y
=
300
setheading
=
"right"
snake_head
=
right
score
=
0
while
True
:
for
event
in
pygame
.
event
.
get
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"left"
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"right"
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"down"
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_RIGHT
setheading
!=
"up"
setheading
=
'down'
snake_head
=
down
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num1
-
30
else
:
position
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,(
apple_x
,
apple_y
))
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