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
dbde0b47
authored
Aug 23, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
f711a782
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
7 deletions
my_Tetris.py
text
tt.py
my_Tetris.py
View file @
dbde0b47
import
pygame
import
pygame
import
random
as
r
import
random
as
r
from
pygame
import
locals
from
pygame
import
locals
def
shade
(
list
,
object
):
for
i
in
list
:
if
i
[
0
]
==
object
[
0
]
and
i
[
1
]
==
object
[
1
]
and
i
[
3
]
!=
object
[
3
]:
return
1
return
0
c
=
0
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
score
=
0
score
=
0
grid_size
=
20
# 格子大小
grid_size
=
20
# 格子大小
...
@@ -9,8 +14,9 @@ grid_num_width = 15 # 横向格子数量
...
@@ -9,8 +14,9 @@ grid_num_width = 15 # 横向格子数量
grid_num_height
=
25
# 纵向格子数量
grid_num_height
=
25
# 纵向格子数量
FPS
=
30
FPS
=
30
sqare
=
[]
sqare
=
[]
mo
=
[[(
120
,
20
),(
120
,
40
)
(
140
,
40
),(
140
,
60
)],[(
120
,
20
),(
140
,
20
),(
160
,
20
),(
180
,
20
)],[(
120
,
20
),(
120
,
40
),(
140
,
20
),(
140
,
4
0
)]]
mo
=
[[(
120
,
20
),(
120
,
40
)
,(
140
,
60
),(
140
,
40
)],[(
120
,
20
),(
140
,
20
),(
180
,
20
),(
160
,
20
)],[(
120
,
20
),(
120
,
40
),(
140
,
20
),(
140
,
40
)],[(
120
,
0
),(
140
,
20
),(
100
,
20
),(
120
,
20
)],[(
120
,
20
),(
100
,
40
),(
80
,
40
),(
100
,
20
)],[(
120
,
20
),(
120
,
40
),(
140
,
60
),(
120
,
6
0
)]]
grass
=
(
21
,
219
,
58
)
grass
=
(
21
,
219
,
58
)
peach
=
(
255
,
218
,
185
)
white
=
(
255
,
255
,
255
)
white
=
(
255
,
255
,
255
)
red
=
(
255
,
0
,
0
)
red
=
(
255
,
0
,
0
)
blue
=
(
0
,
0
,
255
)
blue
=
(
0
,
0
,
255
)
...
@@ -20,9 +26,7 @@ crimson=(220,20,60)
...
@@ -20,9 +26,7 @@ crimson=(220,20,60)
fuchsia
=
(
255
,
0
,
255
)
fuchsia
=
(
255
,
0
,
255
)
slate
=
(
112
,
128
,
144
)
slate
=
(
112
,
128
,
144
)
aqua
=
(
0
,
255
,
255
)
aqua
=
(
0
,
255
,
255
)
color
=
[
grass
,
red
,
blue
,
green
,
orchid
,
crimson
,
fuchsia
,
slate
,
aqua
]
color
=
[
grass
,
red
,
blue
,
green
,
orchid
,
crimson
,
fuchsia
,
slate
,
aqua
]
for
i
in
r
.
choice
(
mo
):
# 创建窗口
# 创建窗口
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
screen
=
pygame
.
display
.
set_mode
((
460
,
500
))
pygame
.
display
.
set_caption
(
"俄罗斯方块"
)
pygame
.
display
.
set_caption
(
"俄罗斯方块"
)
...
@@ -36,14 +40,65 @@ while True:
...
@@ -36,14 +40,65 @@ while True:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_LEFT
:
flag
=
0
for
i
in
range
(
len
(
sqare
)):
if
sqare
[
i
][
3
]
==
c
:
sqare
[
i
][
0
]
-=
20
if
sqare
[
i
][
0
]
<=-
20
or
shade
(
sqare
,
sqare
[
i
]):
flag
=
1
if
flag
==
1
:
for
i
in
range
(
len
(
sqare
)):
if
sqare
[
i
][
3
]
==
c
:
sqare
[
i
][
0
]
+=
20
if
event
.
key
==
locals
.
K_RIGHT
:
flag
=
0
for
i
in
range
(
len
(
sqare
)):
if
sqare
[
i
][
3
]
==
c
:
sqare
[
i
][
0
]
+=
20
if
sqare
[
i
][
0
]
>=
300
or
shade
(
sqare
,
sqare
[
i
]):
flag
=
1
if
flag
==
1
:
for
i
in
range
(
len
(
sqare
)):
if
sqare
[
i
][
3
]
==
c
:
sqare
[
i
][
0
]
-=
20
if
event
.
key
==
locals
.
K_DOWN
:
flag
=
0
for
i
in
range
(
len
(
sqare
)):
if
sqare
[
i
][
3
]
==
c
:
sqare
[
i
][
1
]
+=
20
if
sqare
[
i
][
1
]
>=
480
or
shade
(
sqare
,[
sqare
[
i
][
0
],
sqare
[
i
][
1
]
+
20
,
0
,
sqare
[
i
][
3
]]):
flag
=
1
if
flag
==
1
:
c
+=
1
cc
=
r
.
choice
(
color
)
for
i
in
r
.
choice
(
mo
):
print
(
i
)
sqare
.
append
([
i
[
0
],
i
[
1
],
cc
,
c
])
if
event
.
key
==
locals
.
K_UP
:
for
i
in
range
(
len
(
sqare
)
-
1
):
if
sqare
[
i
][
3
]
==
c
:
difx
=
sqare
[
i
][
0
]
-
sqare
[
-
1
][
0
]
dify
=
sqare
[
i
][
1
]
-
sqare
[
-
1
][
1
]
sqare
[
i
][
0
]
=
sqare
[
-
1
][
0
]
-
dify
sqare
[
i
][
1
]
=
sqare
[
-
1
][
1
]
-
difx
for
i
in
range
(
0
,
500
,
20
):
flag
=
1
for
j
in
range
(
0
,
300
,
20
):
if
if
c
==
0
:
c
+=
1
cc
=
r
.
choice
(
color
)
for
i
in
r
.
choice
(
mo
):
print
(
i
)
sqare
.
append
([
i
[
0
],
i
[
1
],
cc
,
c
])
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
background
,(
0
,
0
))
# 得分
# 得分
score_text
=
font
.
render
(
str
(
score
),
True
,(
0
,
255
,
200
))
score_text
=
font
.
render
(
str
(
score
),
True
,(
0
,
255
,
200
))
screen
.
blit
(
score_text
,(
350
,
70
))
screen
.
blit
(
score_text
,(
350
,
70
))
# 刷新画面
# 刷新画面
sqare
.
append
([
120
,
20
,
grass
])
for
i
in
sqare
:
for
i
in
sqare
:
pygame
.
draw
.
rect
(
screen
,
i
[
2
],(
i
[
0
],
i
[
1
],
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,
i
[
2
],(
i
[
0
],
i
[
1
],
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,
white
,(
i
[
0
],
i
[
1
],
20
,
20
),
1
)
pygame
.
draw
.
rect
(
screen
,
white
,(
i
[
0
],
i
[
1
],
20
,
20
),
1
)
...
...
text
0 → 100644
View file @
dbde0b47
tt.py
0 → 100644
View file @
dbde0b47
mo
=
[(
120
,
20
),(
120
,
40
),(
140
,
40
),(
140
,
60
)]
\ No newline at end of file
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