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
6a60e499
authored
Dec 19, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1d161ee1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
3 deletions
diy.py
my_Tetris.py
diy.py
0 → 100644
View file @
6a60e499
# def quick_sort(data):
# if len(data) >= 2: #递归入口
# mid = data[len(data)//2]
# left,right = [],[] #定义基准值左右两侧列表
# data.remove(mid) #移除基准值
# for num in data:
# if num >= mid:
# right.append(num)
# else:
# left.append(num)
# print('left',left)
# print('mid',mid)
# print('right',right)
# return quick_sort(left) + [mid] + quick_sort(right)
# else:
# return data
# list = [3,8,2,4,0,9,6,1,7,5]
# print(quick_sort(list))
from
random
import
randint
# list = []
# for i in range(100):
# num = randint(1,50)
# list.append(num)
list
=
[
randint
(
1
,
50
)
for
i
in
range
(
100
)]
count
=
[
0
for
i
in
range
(
len
(
list
))]
#对从0到列表长度的数值归0,准备计数
for
val
in
list
:
#遍历列表
count
[
val
]
+=
1
#计数到遍历值的位置计数加1
list
.
clear
()
for
i
,
j
in
enumerate
(
count
):
for
k
in
range
(
j
):
list
.
append
(
i
)
print
(
list
)
\ No newline at end of file
my_Tetris.py
View file @
6a60e499
...
...
@@ -16,15 +16,42 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
background
=
pygame
.
image
.
load
(
'bg.png'
)
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
center
=
[
2
,
8
]
#2行8列
curr_shape
=
[(
0
,
-
1
),(
0
,
0
),(
0
,
1
),(
0
,
2
)]
#当前形状
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
:
if
center
[
1
]
<
15
:
center
[
1
]
=
center
[
1
]
+
1
elif
event
.
key
==
locals
.
K_LEFT
:
if
center
[
1
]
>
1
:
center
[
1
]
=
center
[
1
]
-
1
elif
event
.
key
==
locals
.
K_DOWN
:
if
center
[
0
]
<
25
:
center
[
0
]
=
center
[
0
]
+
1
# 将背景图画上去
???
screen
.
blit
(
background
,(
0
,
0
))
#计算出所有小方块的行、列位置
curr_pos
=
[]
for
cube
in
curr_shape
:
aa
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
curr_pos
.
append
(
aa
)
for
cube
in
curr_pos
:
#将1个格子画出来
pygame
.
draw
.
rect
(
screen
,(
255
,
0
,
0
),
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
0
)
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),
(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
1
)
# 得分
???
# 刷新画面
score_text
=
font
.
render
(
str
(
score
),
True
,(
0
,
0
,
0
))
screen
.
blit
(
score_text
,(
350
,
70
))
pygame
.
display
.
update
()
clock
.
tick
(
FPS
)
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