Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson15-diy2
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
91346cb6
authored
Aug 28, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
bae41ef6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
181 additions
and
0 deletions
1.py
my_tree.py
1.py
0 → 100644
View file @
91346cb6
import
pygame
,
sys
,
random
,
time
def
new_draw
():
screen
.
fill
(
white
)
for
i
in
range
(
1
,
21
):
for
j
in
range
(
10
):
bolck
=
background
[
i
][
j
]
if
bolck
:
pygame
.
draw
.
rect
(
screen
,
blue
,
(
j
*
25
+
1
,
500
-
i
*
25
+
1
,
23
,
23
))
x
,
y
=
centre
for
i
,
j
in
active
:
i
+=
x
j
+=
y
pygame
.
draw
.
rect
(
screen
,
blue
,
(
j
*
25
+
1
,
500
-
i
*
25
+
1
,
23
,
23
))
pygame
.
display
.
update
()
def
move_LR
(
n
):
"""n=-1代表向左,n=1代表向右"""
x
,
y
=
centre
y
+=
n
for
i
,
j
in
active
:
i
+=
x
j
+=
y
if
j
<
0
or
j
>
9
or
background
[
i
][
j
]:
break
else
:
centre
.
clear
()
centre
.
extend
([
x
,
y
])
def
rotate
():
x
,
y
=
centre
l
=
[(
-
j
,
i
)
for
i
,
j
in
active
]
for
i
,
j
in
l
:
i
+=
x
j
+=
y
if
j
<
0
or
j
>
9
or
background
[
i
][
j
]:
break
else
:
active
.
clear
()
active
.
extend
(
l
)
def
move_down
():
x
,
y
=
centre
x
-=
1
for
i
,
j
in
active
:
i
+=
x
j
+=
y
if
background
[
i
][
j
]:
break
else
:
centre
.
clear
()
centre
.
extend
([
x
,
y
])
return
# 如果新位置未被占用 通过return结束
# 如果新位置被占用则继续向下执行
x
,
y
=
centre
for
i
,
j
in
active
:
background
[
x
+
i
][
y
+
j
]
=
1
l
=
[]
for
i
in
range
(
1
,
20
):
if
0
not
in
background
[
i
]:
l
.
append
(
i
)
# l装 行号,鉴于删去后,部分索引变化,对其降序排列,倒着删除
l
.
sort
(
reverse
=
True
)
for
i
in
l
:
background
.
pop
(
i
)
background
.
append
([
0
for
j
in
range
(
10
)])
# 随删随补
score
[
0
]
+=
len
(
l
)
pygame
.
display
.
set_caption
(
"分数:
%
d"
%
(
score
[
0
]))
active
.
clear
()
active
.
extend
(
list
(
random
.
choice
(
all_block
)))
# all_block保存7种形状的信息,手打出来的
centre
.
clear
()
centre
.
extend
([
20
,
4
])
x
,
y
=
centre
for
i
,
j
in
active
:
i
+=
x
j
+=
y
if
background
[
i
][
j
]:
break
else
:
return
alive
.
append
(
1
)
if
__name__
==
'__main__'
:
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
250
,
500
))
pygame
.
display
.
set_caption
(
"俄罗斯方块"
)
fclock
=
pygame
.
time
.
Clock
()
all_block
=
(((
0
,
0
),
(
0
,
-
1
),
(
0
,
1
),
(
0
,
2
)),
((
0
,
0
),
(
0
,
1
),
(
-
1
,
0
),
(
-
1
,
1
)),
((
0
,
0
),
(
0
,
-
1
),
(
-
1
,
0
),
(
-
1
,
1
)),
((
0
,
0
),
(
0
,
1
),
(
-
1
,
-
1
),
(
-
1
,
0
)),
((
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
0
,
-
1
)),
((
0
,
0
),
(
1
,
0
),
(
-
1
,
0
),
(
1
,
-
1
)),
((
0
,
0
),
(
1
,
0
),
(
-
1
,
0
),
(
1
,
1
)))
background
=
[[
0
for
i
in
range
(
10
)]
for
j
in
range
(
24
)]
background
[
0
]
=
[
1
for
i
in
range
(
10
)]
active
=
list
(
random
.
choice
(
all_block
))
centre
=
[
20
,
4
]
score
=
[
0
]
black
=
0
,
0
,
0
white
=
255
,
255
,
255
blue
=
0
,
0
,
255
times
=
0
alive
=
[]
press
=
False
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
quit
:
sys
.
exit
()
elif
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_LEFT
:
move_LR
(
-
1
)
elif
event
.
key
==
pygame
.
K_RIGHT
:
move_LR
(
1
)
elif
event
.
key
==
pygame
.
K_UP
:
rotate
()
elif
event
.
key
==
pygame
.
K_DOWN
:
press
=
True
elif
event
.
type
==
pygame
.
KEYUP
:
if
event
.
key
==
pygame
.
K_DOWN
:
press
=
False
if
press
:
times
+=
10
if
times
>=
50
:
move_down
()
times
=
0
else
:
times
+=
1
if
alive
:
pygame
.
display
.
set_caption
(
"over分数:
%
d"
%
(
score
[
0
]))
time
.
sleep
(
3
)
break
new_draw
()
fclock
.
tick
(
100
)
\ No newline at end of file
my_tree.py
0 → 100644
View file @
91346cb6
import
turtle
pen
=
turtle
.
Turtle
()
pen
.
speed
(
0
)
pen
.
color
(
'sienna'
)
# 画布大小
w
=
turtle
.
Screen
()
w
.
bgcolor
(
'wheat'
)
# wheat小麦
# 移动到起点
pen
.
left
(
90
)
pen
.
up
()
pen
.
backward
(
150
)
# 后退
pen
.
down
()
#二叉树
def
tree
(
n
):
if
n
>=
50
:
pen
.
forward
(
n
)
pen
.
right
(
30
)
tree
(
n
-
10
)
pen
.
left
(
60
)
tree
(
n
-
10
)
pen
.
right
(
30
)
pen
.
up
()
pen
.
backward
(
n
)
pen
.
down
()
tree
(
100
)
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