Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_diy3
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
dc90dbc7
authored
Aug 19, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
01beaadc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
61 deletions
snake.py
snake.py
View file @
dc90dbc7
import
pygame
from
pygame
import
locals
# 初始化pygame,为使用硬件做准备
pygame
.
init
()
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
asdfk
=
pygame
.
time
.
Clock
()
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
x
=
240
y
=
120
qwer
=
[(
210
,
120
),(
180
,
120
),(
180
,
90
),(
x
,
y
)]
qwert
=
'right'
qaz
=
right
import
random
import
turtle
c
=
turtle
.
Screen
()
d
=
turtle
.
Pen
()
a
=
random
.
randint
(
0
,
100
)
q
=
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
and
qwert
!=
'left'
:
qwert
=
'right'
qaz
=
right
elif
event
.
key
==
locals
.
K_UP
and
qwert
!=
'down'
:
qwert
=
'up'
qaz
=
up
elif
event
.
key
==
locals
.
K_LEFT
and
qwert
!=
'right'
:
qwert
=
'left'
qaz
=
left
elif
event
.
key
==
locals
.
K_DOWN
and
qwert
!=
'up'
:
qwert
=
'down'
qaz
=
down
if
qwert
==
'right'
:
x
+=
30
elif
qwert
==
'up'
:
y
-=
30
elif
qwert
==
'left'
:
x
-=
30
elif
qwert
==
'down'
:
y
+=
30
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇画上去
qwer
.
append
((
x
,
y
))
qwer
.
pop
(
0
)
screen
.
blit
(
qaz
,
(
x
,
y
))
for
i
in
range
(
len
(
qwer
)
-
1
):
screen
.
blit
(
body
,
qwer
[
i
])
pygame
.
display
.
update
()
asdfk
.
tick
(
5
)
\ No newline at end of file
b
=
c
.
textinput
(
'猜数字'
,
'输入一个数'
)
d
.
clear
()
b
=
int
(
b
)
if
b
==
a
:
d
.
write
(
'yes'
,
font
=
(
'Times'
,
30
,
'normal'
))
elif
b
<
a
:
d
.
write
(
'big'
,
font
=
(
'Times'
,
30
,
'normal'
))
q
+=
1
elif
b
>
a
:
d
.
write
(
's'
,
font
=
(
'Times'
,
30
,
'normal'
))
q
+=
1
turtle
.
done
()
\ 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