Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson12_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
54bc2474
authored
Dec 11, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
19bc610f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
my_Tetris.py
my_Tetris.py
View file @
54bc2474
...
@@ -47,7 +47,7 @@ cube_colors = [
...
@@ -47,7 +47,7 @@ cube_colors = [
(
255
,
204
,
0
),
(
204
,
0
,
51
),(
255
,
0
,
51
),
(
0
,
102
,
153
),
(
255
,
204
,
0
),
(
204
,
0
,
51
),(
255
,
0
,
51
),
(
0
,
102
,
153
),
(
153
,
0
,
51
),
(
204
,
255
,
102
),
(
255
,
153
,
0
)]
(
153
,
0
,
51
),
(
204
,
255
,
102
),
(
255
,
153
,
0
)]
num_list
=
[]
num_list
=
[]
for
i
in
range
(
25
):
for
i
in
range
(
25
):
num_list
.
append
([
0
]
*
15
)
num_list
.
append
([
0
]
*
15
)
...
@@ -58,7 +58,7 @@ def check(center):
...
@@ -58,7 +58,7 @@ def check(center):
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
or
cube
[
0
]
>
grid_num_height
\
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
or
cube
[
0
]
>
grid_num_height
\
or
cube
[
1
]
>
grid_num_width
:
or
cube
[
1
]
>
grid_num_width
:
return
False
return
False
if
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
!=
0
:
if
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
!=
0
:
return
False
return
False
while
True
:
while
True
:
...
@@ -105,7 +105,7 @@ while True:
...
@@ -105,7 +105,7 @@ while True:
center
[
0
]
=
center
[
0
]
-
1
center
[
0
]
=
center
[
0
]
-
1
states
=
False
states
=
False
for
cube
in
current_pos
:
for
cube
in
current_pos
:
num_list
[(
cube
[
0
]
-
1
)][
cube
[
1
]
-
1
]
=
color
num_list
[(
cube
[
0
]
-
1
)][
cube
[
1
]
-
1
]
=
color
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 计算出所有小方块的行、列位置
# 计算出所有小方块的行、列位置
...
@@ -119,31 +119,31 @@ while True:
...
@@ -119,31 +119,31 @@ while True:
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
0
)
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
1
)
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
1
)
for
i
,
p
in
zip
(
range
(
1
,
26
),
num_list
):
for
i
,
p
in
zip
(
range
(
1
,
26
),
num_list
):
#把两个列表组合成元组
for
j
,
colors
in
zip
(
range
(
1
,
16
),
p
):
for
j
,
colors
in
zip
(
range
(
1
,
16
),
p
):
if
colors
!=
0
:
if
colors
!=
0
:
pygame
.
draw
.
rect
(
screen
,
color
,
pygame
.
draw
.
rect
(
screen
,
color
,
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
0
)
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
1
)
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
1
)
new_list
=
[]
new_list
=
[]
for
i
in
range
(
25
):
for
i
in
range
(
25
):
new_list
.
append
([
0
]
*
15
)
new_list
.
append
([
0
]
*
15
)
p_index
=
24
p_index
=
24
#索引(0-24) 代表25行
for
i
in
range
(
24
,
-
1
,
-
1
):
for
i
in
range
(
24
,
-
1
,
-
1
):
is_full
=
True
is_full
=
True
#创建新的变量用来记录是否被填满
for
j
in
range
(
grid_num_width
):
for
j
in
range
(
grid_num_width
):
if
num_list
[
i
][
j
]
==
0
:
if
num_list
[
i
][
j
]
==
0
:
is_full
=
False
is_full
=
False
if
is_full
==
False
:
if
is_full
==
False
:
#当没被填满 就进行替换
new_list
[
p_index
]
=
num_list
[
i
]
new_list
[
p_index
]
=
num_list
[
i
]
p_index
-=
1
p_index
-=
1
# 从下往上换行替换
else
:
else
:
#被替换满了,成绩加1
score
+=
1
score
+=
1
num_list
=
new_list
num_list
=
new_list
#用旧的替换掉新的
# 得分
# 得分
text_surface
=
font
.
render
(
str
(
score
),
True
,
(
0
,
0
,
0
))
text_surface
=
font
.
render
(
str
(
score
),
True
,
(
0
,
0
,
0
))
screen
.
blit
(
text_surface
,
(
350
,
70
))
screen
.
blit
(
text_surface
,
(
350
,
70
))
...
...
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