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
d299463e
authored
Aug 08, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
25160652
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
my_Tetris.py
my_Tetris.py
View file @
d299463e
...
@@ -10,6 +10,7 @@ grid_num_height = 25 # 纵向格子数量
...
@@ -10,6 +10,7 @@ grid_num_height = 25 # 纵向格子数量
FPS
=
30
# 帧率
FPS
=
30
# 帧率
count
=
0
count
=
0
states
=
False
states
=
False
gameover
=
False
num_list
=
[]
num_list
=
[]
for
i
in
range
(
25
):
for
i
in
range
(
25
):
num_list
.
append
([
0
]
*
15
)
num_list
.
append
([
0
]
*
15
)
...
@@ -64,6 +65,8 @@ while True:
...
@@ -64,6 +65,8 @@ while True:
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
gameover
==
True
:
gameover
=
False
if
event
.
key
==
locals
.
K_LEFT
:
# 向左
if
event
.
key
==
locals
.
K_LEFT
:
# 向左
center
[
1
]
=
center
[
1
]
-
1
# 左移1列
center
[
1
]
=
center
[
1
]
-
1
# 左移1列
if
check
(
center
)
==
False
:
if
check
(
center
)
==
False
:
...
@@ -90,14 +93,17 @@ while True:
...
@@ -90,14 +93,17 @@ while True:
if
check
(
center
)
==
False
:
if
check
(
center
)
==
False
:
index
=
old_index
index
=
old_index
current_shape
=
shape
[
index
]
current_shape
=
shape
[
index
]
if
gameover
==
False
:
if
states
==
False
:
if
states
==
False
:
states
=
True
states
=
True
center
=
[
2
,
8
]
# 第2行第8列
center
=
[
2
,
8
]
# 第2行第8列
shape
=
random
.
choice
(
shape_list
)
shape
=
random
.
choice
(
shape_list
)
index
=
random
.
randint
(
0
,
len
(
shape
)
-
1
)
# 随机形状索引
index
=
random
.
randint
(
0
,
len
(
shape
)
-
1
)
# 随机形状索引
current_shape
=
shape
[
index
]
current_shape
=
shape
[
index
]
color
=
random
.
choice
(
cube_colors
)
# 随机选取一种颜色
color
=
random
.
choice
(
cube_colors
)
# 随机选取一种颜色
if
check
(
center
)
==
False
:
gameover
=
True
continue
count
+=
1
count
+=
1
if
count
%
FPS
==
0
:
# 降落速度的算式
if
count
%
FPS
==
0
:
# 降落速度的算式
center
[
0
]
=
center
[
0
]
+
1
center
[
0
]
=
center
[
0
]
+
1
...
@@ -141,6 +147,15 @@ while True:
...
@@ -141,6 +147,15 @@ while True:
else
:
else
:
score
+=
1
score
+=
1
num_list
=
new_list
num_list
=
new_list
if
gameover
==
True
:
num_list
=
[]
for
i
in
range
(
25
):
num_list
.
append
([
0
]
*
15
)
score
=
0
font_2
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
30
)
text_surface2
=
font_2
.
render
(
'勍蓭陾翳姦爞丗'
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
text_surface2
,(
50
,
250
))
# 得分
# 得分
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