Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson11_diy01
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
9f90b7b3
authored
Nov 27, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
16e606f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
my_Tetris.py
my_Tetris.py
View file @
9f90b7b3
import
pygame
import
pygame
import
random
from
pygame
import
locals
from
pygame
import
locals
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
...
@@ -7,8 +8,7 @@ grid_size = 20 # 格子大小
...
@@ -7,8 +8,7 @@ grid_size = 20 # 格子大小
grid_num_width
=
15
# 横向格子数量
grid_num_width
=
15
# 横向格子数量
grid_num_height
=
25
# 纵向格子数量
grid_num_height
=
25
# 纵向格子数量
FPS
=
30
FPS
=
30
position
=
[
2
,
7
]
current_pos
=
[(
0
,
-
1
),(
0
,
0
),(
0
,
1
),(
-
1
,
0
)]
...
@@ -21,6 +21,39 @@ background = pygame.image.load('bg.png')
...
@@ -21,6 +21,39 @@ background = pygame.image.load('bg.png')
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
# 俄罗斯方块所有形状
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
)],
[(
-
1
,
0
),
(
0
,
0
),
(
0
,
-
1
),
(
1
,
-
1
)]]
S
=
[[(
-
1
,
0
),
(
0
,
0
),
(
0
,
1
),
(
1
,
1
)],
[(
1
,
-
1
),
(
1
,
0
),
(
0
,
0
),
(
0
,
1
)]]
T
=
[[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
-
1
,
0
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
0
,
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
1
,
0
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
0
,
-
1
)]]
J
=
[[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
1
,
-
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
-
1
,
-
1
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
-
1
,
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
1
,
1
)]]
L
=
[[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
1
,
-
1
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
-
1
,
-
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
-
1
,
1
)]]
shape_list
=
[
I
,
J
,
L
,
O
,
S
,
T
,
Z
]
# 7种类型俄罗斯方块
# 一些RGB颜色
cube_colors
=
[
(
204
,
153
,
153
),
(
102
,
102
,
153
),(
153
,
0
,
102
),
(
255
,
204
,
0
),
(
204
,
0
,
51
),(
255
,
0
,
51
),
(
0
,
102
,
153
),
(
153
,
0
,
51
),
(
204
,
255
,
102
),
(
255
,
153
,
0
)]
position
=
[
2
,
8
]
shape
=
random
.
choice
(
shape_list
)
color
=
random
.
choice
(
cube_colors
)
direction
=
random
.
randint
(
0
,
len
(
shape
)
-
1
)
current_pos
=
shape
[
direction
]
while
True
:
while
True
:
...
@@ -53,7 +86,7 @@ while True:
...
@@ -53,7 +86,7 @@ while True:
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
background
,(
0
,
0
))
for
mypos
in
cube
:
for
mypos
in
cube
:
pygame
.
draw
.
rect
(
screen
,
(
0
,
0
,
250
)
,
pygame
.
draw
.
rect
(
screen
,
color
,
((
mypos
[
1
]
-
1
)
*
grid_size
,(
mypos
[
0
]
-
1
)
*
grid_size
,
grid_size
,
grid_size
),
0
)
((
mypos
[
1
]
-
1
)
*
grid_size
,(
mypos
[
0
]
-
1
)
*
grid_size
,
grid_size
,
grid_size
),
0
)
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),
((
mypos
[
1
]
-
1
)
*
grid_size
,(
mypos
[
0
]
-
1
)
*
grid_size
,
grid_size
,
grid_size
),
1
)
((
mypos
[
1
]
-
1
)
*
grid_size
,(
mypos
[
0
]
-
1
)
*
grid_size
,
grid_size
,
grid_size
),
1
)
...
...
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