Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson10_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
227303cb
authored
Feb 08, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
7f2c9dce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
my_Tetris.py
my_Tetris.py
View file @
227303cb
...
...
@@ -4,8 +4,7 @@ from pygame import locals
xy
=
[
2
,
8
]
# class FK():
# def __init__(self):
pygame
.
init
()
# 初始化
score
=
0
...
...
@@ -61,6 +60,12 @@ index = random.randint(0,len(shape)-1)
current_shape
=
shape
[
index
]
color
=
random
.
choice
(
shape_colors
)
def
check
(
xy
):
#检测方块是否超出网格自定义函数
for
i
in
current_shape
:
i
=
(
i
[
0
]
+
xy
[
0
],
i
[
1
]
+
xy
[
1
])
if
i
[
0
]
<
1
or
i
[
1
]
<
1
or
i
[
0
]
>
grid_num_width
or
i
[
1
]
>
grid_num_width
:
return
False
while
True
:
...
...
@@ -72,14 +77,28 @@ while True:
exit
()
if
event
.
key
==
locals
.
K_RIGHT
:
if
xy
[
1
]
<
15
:
xy
[
1
]
+=
1
xy
[
1
]
+=
1
if
check
(
xy
)
==
False
:
xy
[
1
]
-=
1
elif
event
.
key
==
locals
.
K_LEFT
:
if
xy
[
1
]
>
1
:
xy
[
1
]
+=
-
1
xy
[
1
]
-=
1
if
check
(
xy
)
==
False
:
xy
[
1
]
+=
1
elif
event
.
key
==
locals
.
K_DOWN
:
if
xy
[
0
]
<
25
:
xy
[
0
]
+=
1
xy
[
0
]
+=
1
if
check
(
xy
)
==
False
:
xy
[
0
]
+=
-
1
elif
event
.
key
==
locals
.
KEY_UP
:
old_index
=
index
index
+=
1
if
index
>=
len
(
shape
):
index
=
0
current_shape
=
shape
[
index
]
if
check
(
xy
)
==
False
:
# 将背景图画上去
...
...
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