Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson11_diy4
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
064c7eed
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
944cad6e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
my_Tetris.py
my_Tetris.py
View file @
064c7eed
...
@@ -8,6 +8,8 @@ grid_size = 20 # 格子大小
...
@@ -8,6 +8,8 @@ grid_size = 20 # 格子大小
grid_num_width
=
15
# 横向格子数量
grid_num_width
=
15
# 横向格子数量
grid_num_height
=
25
# 纵向格子数量
grid_num_height
=
25
# 纵向格子数量
FPS
=
30
FPS
=
30
count
=
0
states
=
False
# 创建窗口
# 创建窗口
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
...
@@ -58,8 +60,15 @@ def comon(center):
...
@@ -58,8 +60,15 @@ def comon(center):
k
=
(
i
[
0
]
+
center
[
0
],
i
[
1
]
+
center
[
1
])
k
=
(
i
[
0
]
+
center
[
0
],
i
[
1
]
+
center
[
1
])
if
k
[
1
]
>=
16
or
k
[
1
]
<=
0
or
k
[
0
]
>=
26
or
k
[
0
]
<=
0
:
if
k
[
1
]
>=
16
or
k
[
1
]
<=
0
or
k
[
0
]
>=
26
or
k
[
0
]
<=
0
:
return
False
return
False
states
=
True
while
True
:
while
True
:
if
states
==
False
:
current_shape1
=
random
.
choice
(
shape_list
)
index
=
random
.
randint
(
0
,
len
(
current_shape1
)
-
1
)
current_shape
=
current_shape1
[
index
]
color
=
random
.
choice
(
cube_colors
)
states
=
True
comon
(
center
)
comon
(
center
)
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -95,7 +104,14 @@ while True:
...
@@ -95,7 +104,14 @@ while True:
index
=
old_index
index
=
old_index
current_shape
=
current_shape1
[
index
]
current_shape
=
current_shape1
[
index
]
count
+=
1
if
count
%
FPS
==
0
:
if
center
[
0
]
<
25
:
center
[
0
]
+=
1
if
comon
(
center
)
==
False
:
center
[
0
]
-=
1
if
center
[
0
]
>=
grid_num_height
:
states
=
False
...
@@ -103,6 +119,8 @@ while True:
...
@@ -103,6 +119,8 @@ while True:
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 计算出所有小方块的行、列位置
# 计算出所有小方块的行、列位置
current_pos
=
[]
current_pos
=
[]
for
cube
in
current_shape
:
for
cube
in
current_shape
:
pos
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
pos
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
...
@@ -113,6 +131,7 @@ while True:
...
@@ -113,6 +131,7 @@ 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
)
# 得分
# 得分
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
))
...
...
This diff is collapsed.
Click to expand it.
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