Commit 064c7eed by BellCodeEditor

auto save

parent 944cad6e
Showing with 21 additions and 2 deletions
......@@ -8,6 +8,8 @@ grid_size = 20 # 格子大小
grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量
FPS = 30
count=0
states=False
# 创建窗口
screen = pygame.display.set_mode((460, 500))
......@@ -58,8 +60,15 @@ def comon(center):
k = (i[0]+center[0],i[1]+center[1])
if k[1]>=16 or k[1]<=0 or k[0]>=26 or k[0]<=0:
return False
states=True
while True:
if states==False:
current_shape1=random.choice(shape_list)
index=random.randint(0,len(current_shape1)-1)
current_shape=current_shape1[index]
color=random.choice(cube_colors)
states=True
comon(center)
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -95,7 +104,14 @@ while True:
index=old_index
current_shape=current_shape1[index]
count+=1
if count%FPS==0:
if center[0] < 25:
center[0] += 1
if comon(center)==False:
center[0]-=1
if center[0]>=grid_num_height:
states=False
......@@ -103,6 +119,8 @@ while True:
screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置
current_pos = []
for cube in current_shape:
pos = (cube[0] + center[0], cube[1] + center[1])
......@@ -113,6 +131,7 @@ while True:
(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)
# 得分
text_surface = font.render(str(score), True, (0, 0, 0))
screen.blit(text_surface, (350,70))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment