Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson12_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
9dd5067d
authored
May 09, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
099c6925
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
my_Tetris.py
my_Tetris.py
View file @
9dd5067d
...
...
@@ -48,15 +48,19 @@ cube_colors = [
(
153
,
0
,
51
),
(
204
,
255
,
102
),
(
255
,
153
,
0
)]
def
check
(
center
):
for
cube
m
in
current_shape
:
cube
m
=
(
cubem
[
0
]
+
center
[
0
],
cubem
[
1
]
+
center
[
1
])
for
cube
in
current_shape
:
cube
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
# 当前的小方块超出网格的行、列,就返回False
if
cube
m
[
0
]
<
1
or
cubem
[
1
]
<
1
or
cubem
[
0
]
>
grid_num_height
\
or
cube
m
[
1
]
>
grid_num_width
:
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
or
cube
[
0
]
>
grid_num_height
\
or
cube
[
1
]
>
grid_num_width
:
return
False
if
num_list
[
cube
m
[
0
]
-
1
][
cubem
[
1
]
-
1
]
!=
0
:
if
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
!=
0
:
return
False
num_list
=
[[
0
]
*
15
]
*
25
# 格子基础数字设为0
num_list
=
[]
for
i
in
range
(
25
):
num_list
.
append
([
0
]
*
15
)
while
True
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -87,7 +91,7 @@ while True:
if
check
(
center
)
==
False
:
index
=
old_index
current_shape
=
shape
[
index
]
# 生成新俄罗斯方块
if
states
==
False
:
states
=
True
center
=
[
2
,
8
]
# 第2行第8列
...
...
@@ -100,10 +104,9 @@ while True:
center
[
0
]
=
center
[
0
]
+
1
if
check
(
center
)
==
False
:
center
[
0
]
=
center
[
0
]
-
1
states
=
False
for
i
in
current_pos
:
num_list
[
i
[
0
]
-
1
][
i
[
1
]
-
1
]
=
color
states
=
False
for
cube
in
current_pos
:
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
=
color
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 计算出所有小方块的行、列位置
...
...
@@ -117,15 +120,18 @@ while True:
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
1
)
for
i
,
row
in
zip
(
range
(
1
,
26
),
num_list
):
for
j
,
colors
in
zip
(
range
(
1
,
16
),
row
):
if
colors
!=
0
:
pygame
.
draw
.
rect
(
screen
,
colors
,(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
1
)
# 画出降落后的方块
for
i
,
row
in
zip
(
range
(
1
,
26
),
num_list
):
# i代表的是什么呢? (行)
for
j
,
colors
in
zip
(
range
(
1
,
16
),
row
):
if
colors
!=
0
:
pygame
.
draw
.
rect
(
screen
,
colors
,
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
))
pygame
.
draw
.
rect
(
screen
,
(
255
,
255
,
255
),
(
j
*
20
-
20
,
i
*
20
-
20
,
20
,
20
),
1
)
# 得分
text_surface
=
font
.
render
(
str
(
score
),
True
,
(
0
,
0
,
0
))
screen
.
blit
(
text_surface
,
(
350
,
70
))
# 刷新画面
pygame
.
display
.
update
()
clock
.
tick
(
FPS
)
clock
.
tick
(
FPS
)
\ 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