Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_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
3966656c
authored
Nov 06, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
42f1723b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
54 deletions
snake.py
新.py
snake.py
View file @
3966656c
import
pygame
import
random
from
pygame
import
locals
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
e
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
zx
=
'right'
cx
=
right
x
,
y
=
240
,
120
x1
,
y1
=
360
,
300
lb
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
elif
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
and
zx
!=
'down'
:
zx
=
'up'
cx
=
up
if
event
.
key
==
locals
.
K_DOWN
and
zx
!=
'up'
:
zx
=
'down'
cx
=
down
if
event
.
key
==
locals
.
K_LEFT
and
zx
!=
'right'
:
zx
=
'left'
cx
=
left
if
event
.
key
==
locals
.
K_RIGHT
and
zx
!=
'left'
:
zx
=
'right'
cx
=
right
if
zx
==
'right'
:
x
+=
30
elif
zx
==
'left'
:
x
-=
30
elif
zx
==
'up'
:
y
-=
30
else
:
y
+=
30
lb
.
append
((
x
,
y
))
lb
.
pop
(
0
)
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
cx
,
(
x
,
y
))
for
i
in
range
(
len
(
lb
)
-
1
):
screen
.
blit
(
body
,
lb
[
i
])
screen
.
blit
(
food
,
(
x1
,
y1
))
pygame
.
display
.
update
()
e
.
tick
(
3
)
\ No newline at end of file
新.py
0 → 100644
View file @
3966656c
import
pygame
import
pygame
import
random
from
pygame
import
locals
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
e
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
zx
=
'right'
cx
=
right
x
,
y
=
240
,
120
x1
,
y1
=
360
,
300
lb
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
elif
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
and
zx
!=
'down'
:
zx
=
'up'
cx
=
up
if
event
.
key
==
locals
.
K_DOWN
and
zx
!=
'up'
:
zx
=
'down'
cx
=
down
if
event
.
key
==
locals
.
K_LEFT
and
zx
!=
'right'
:
zx
=
'left'
cx
=
left
if
event
.
key
==
locals
.
K_RIGHT
and
zx
!=
'left'
:
zx
=
'right'
cx
=
right
if
zx
==
'right'
:
x
+=
30
elif
zx
==
'left'
:
x
-=
30
elif
zx
==
'up'
:
y
-=
30
else
:
y
+=
30
lb
.
append
((
x
,
y
))
if
x
==
x1
and
y
==
y1
:
x1
=
random
.
randint
(
0
,
660
)
y1
=
random
.
randint
(
0
,
480
)
lb
.
pop
(
0
)
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
cx
,
(
x
,
y
))
for
i
in
range
(
len
(
lb
)
-
1
):
screen
.
blit
(
body
,
lb
[
i
])
screen
.
blit
(
food
,
(
x1
,
y1
))
pygame
.
display
.
update
()
e
.
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