Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson11_diy1
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
0489faac
authored
Nov 21, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
ccd648a2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
my_Tetris.py
my_Tetris.py
View file @
0489faac
import
pygame
from
pygame
import
locals
from
random
import
randint
from
random
import
*
pygame
.
init
()
# 初始化
score
=
0
...
...
@@ -18,10 +18,7 @@ background = pygame.image.load('bg.png')
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
# 俄罗斯方块所有形状
O
=
[[(
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
1
,
1
)],
[(
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
1
,
1
)],
[(
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
1
,
1
)],
[(
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
1
,
1
)]]
O
=
[[(
0
,
0
),
(
0
,
1
),
(
1
,
0
),
(
1
,
1
)]]
I
=
[[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
0
,
2
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
2
,
0
)]]
Z
=
[[(
0
,
-
1
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)],
...
...
@@ -49,8 +46,15 @@ cube_colors = [
(
153
,
0
,
51
),
(
204
,
255
,
102
),
(
255
,
153
,
0
)]
center
=
[
2
,
8
]
# 第2行第8列
current_shape
=
shape_list
[
randint
(
0
,
6
)][
randint
(
0
,
3
)]
color
=
cube_colors
[
randint
(
0
,
10
)]
shape
=
choice
(
shape_list
)
ind
=
randint
(
0
,
len
(
shape
)
-
1
)
current_shape
=
shape
[
ind
]
color
=
choice
(
cube_colors
)
def
check
(
center
):
for
cube
in
current_shape
:
cube
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
if
cube
[
0
]
<
1
or
cube
[
1
]
<
1
while
True
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -66,7 +70,20 @@ while True:
elif
event
.
key
==
locals
.
K_DOWN
:
# 向下
if
center
[
0
]
<
25
:
center
[
0
]
+=
1
elif
event
.
key
==
locals
.
K_z
:
if
ind
>
0
:
ind
-=
1
current_shape
=
shape
[
ind
]
else
:
ind
=
len
(
shape
)
-
1
current_shape
=
shape
[
ind
]
elif
event
.
key
==
locals
.
K_x
:
if
ind
<
len
(
shape
)
-
1
:
ind
+=
1
current_shape
=
shape
[
ind
]
else
:
ind
=
0
current_shape
=
shape
[
ind
]
# 将背景图画上去
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