Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson11_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
9ae82456
authored
Jul 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
6ab3f11c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
my_Tetris.py
my_Tetris.py
View file @
9ae82456
...
@@ -9,6 +9,8 @@ grid_num_width = 15 # 横向格子数量
...
@@ -9,6 +9,8 @@ grid_num_width = 15 # 横向格子数量
grid_num_height
=
25
# 纵向格子数量
grid_num_height
=
25
# 纵向格子数量
FPS
=
30
FPS
=
30
index
=
0
index
=
0
count
=
0
skakes
=
False
# 创建窗口
# 创建窗口
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
...
@@ -45,7 +47,6 @@ cube_colors = [
...
@@ -45,7 +47,6 @@ cube_colors = [
(
204
,
153
,
153
),
(
102
,
102
,
153
),(
153
,
0
,
102
),
(
204
,
153
,
153
),
(
102
,
102
,
153
),(
153
,
0
,
102
),
(
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
)]
center
=
[
2
,
8
]
# 第2行第8列
center
=
[
2
,
8
]
# 第2行第8列
random_shape
=
shape_list
[
random
.
randint
(
0
,
len
(
shape_list
)
-
1
)]
random_shape
=
shape_list
[
random
.
randint
(
0
,
len
(
shape_list
)
-
1
)]
shape_index
=
random
.
randint
(
0
,
len
(
random_shape
)
-
1
)
shape_index
=
random
.
randint
(
0
,
len
(
random_shape
)
-
1
)
...
@@ -55,7 +56,7 @@ color = cube_colors[random.randint(0,len(cube_colors)-1)]
...
@@ -55,7 +56,7 @@ color = cube_colors[random.randint(0,len(cube_colors)-1)]
def
check
(
center
):
def
check
(
center
):
for
cube
in
current_shape
:
for
cube
in
current_shape
:
cube
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
cube
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
or
cube
[
1
]
>
15
or
cube
[
0
]
>
25
:
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
or
cube
[
1
]
>
grid_num_width
or
cube
[
0
]
>
grid_num_height
:
return
False
return
False
while
True
:
while
True
:
...
@@ -86,7 +87,21 @@ while True:
...
@@ -86,7 +87,21 @@ while True:
if
check
(
center
)
==
False
:
if
check
(
center
)
==
False
:
shape_index
=
old_index
shape_index
=
old_index
current_shape
=
random_shape
[
shape_index
]
current_shape
=
random_shape
[
shape_index
]
if
skakes
==
False
:
skakes
=
True
center
=
[
2
,
8
]
# 第2行第8列
random_shape
=
shape_list
[
random
.
randint
(
0
,
len
(
shape_list
)
-
1
)]
shape_index
=
random
.
randint
(
0
,
len
(
random_shape
)
-
1
)
current_shape
=
random_shape
[
shape_index
]
color
=
cube_colors
[
random
.
randint
(
0
,
len
(
cube_colors
)
-
1
)]
count
+=
1
if
count
%
FPS
==
0
:
center
[
0
]
+=
1
if
check
(
center
)
==
False
:
center
[
0
]
-=
1
skakes
=
False
print
(
skakes
)
print
(
count
)
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
# 计算出所有小方块的行、列位置
# 计算出所有小方块的行、列位置
...
...
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