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
1e46acfe
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
44c9876c
c157690l1462p256a14638/wx727515
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
my_Tetris.py
my_Tetris.py
View file @
1e46acfe
...
@@ -15,7 +15,7 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...
@@ -15,7 +15,7 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材
# 载入素材
background
=
pygame
.
image
.
load
(
'bg.png'
)
background
=
pygame
.
image
.
load
(
'bg.png'
)
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
bian
=
[]
st
=
False
# 俄罗斯方块所有形状
# 俄罗斯方块所有形状
O
=
[[(
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
)],
I
=
[[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
0
,
2
)],
...
@@ -37,25 +37,27 @@ L = [[(-1, 0), (0, 0), (1, 0), (1, 1)],
...
@@ -37,25 +37,27 @@ L = [[(-1, 0), (0, 0), (1, 0), (1, 1)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
-
1
,
-
1
)],
[(
-
1
,
0
),
(
0
,
0
),
(
1
,
0
),
(
-
1
,
-
1
)],
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
-
1
,
1
)]]
[(
0
,
-
1
),
(
0
,
0
),
(
0
,
1
),
(
-
1
,
1
)]]
shape_list
=
[
I
,
J
,
L
,
O
,
S
,
T
,
Z
]
# 7种类型俄罗斯方块
shape_list
=
[
I
,
J
,
L
,
O
,
S
,
T
,
Z
]
# 7种类型俄罗斯方块
a
=
random
.
choice
(
shape_list
)
c
=
random
.
choice
(
a
)
suoyin
=
random
.
randint
(
0
,
len
(
a
)
-
1
)
p
=
1
p
=
1
# 一些RGB颜色
# 一些RGB颜色
cube_colors
=
[
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
)]
num_list
=
[]
for
i
in
range
(
25
):
num_list
.
append
([
0
]
*
15
)
center
=
[
2
,
8
]
# 第2行第8列
center
=
[
2
,
8
]
# 第2行第8列
#current_shape = [(0, -1), (0, 0), (0, 1), (-1, 0)]
#current_shape = [(0, -1), (0, 0), (0, 1), (-1, 0)]
b
=
random
.
choice
(
cube_colors
)
current_shape
=
c
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
[
1
]
<
1
or
cube
[
1
]
>
15
or
cube
[
0
]
>
25
:
if
cube
[
1
]
<
1
or
cube
[
1
]
>
15
or
cube
[
0
]
>
25
:
return
False
return
False
if
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
!=
0
:
return
False
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -89,11 +91,22 @@ while True:
...
@@ -89,11 +91,22 @@ while True:
if
check
(
center
)
==
False
:
if
check
(
center
)
==
False
:
suoyin
=
old_suoyin
suoyin
=
old_suoyin
current_shape
=
a
[
suoyin
]
current_shape
=
a
[
suoyin
]
if
st
==
False
:
st
=
True
center
=
[
2
,
8
]
a
=
random
.
choice
(
shape_list
)
c
=
random
.
choice
(
a
)
suoyin
=
random
.
randint
(
0
,
len
(
a
)
-
1
)
b
=
random
.
choice
(
cube_colors
)
current_shape
=
c
p
+=
1
p
+=
1
if
p
%
8
==
1
:
if
p
%
8
==
1
:
center
[
0
]
+=
1
center
[
0
]
+=
1
if
check
(
center
)
==
False
:
if
check
(
center
)
==
False
:
center
[
0
]
-=
1
center
[
0
]
-=
1
st
=
False
for
cube
in
current_pos
:
num_list
[
cube
[
0
]
-
1
][
cube
[
1
]
-
1
]
=
b
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
...
...
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