Commit 36a97c1e by BellCodeEditor

save project

parent 87d0f2a5
Showing with 15 additions and 2 deletions
...@@ -48,7 +48,8 @@ center = [2, 8] # 第2行第8列 ...@@ -48,7 +48,8 @@ center = [2, 8] # 第2行第8列
color = random.choice(cube_colors) color = random.choice(cube_colors)
shape = random.choice(shape_list) shape = random.choice(shape_list)
current_shape = random.choice(shape) index = random.randint(0,len(shape)-1)
current_shape = shape[index]
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])
...@@ -73,6 +74,18 @@ while True: ...@@ -73,6 +74,18 @@ while True:
center[0] = center[0] + 1 # 向下 center[0] = center[0] + 1 # 向下
if check(center) == False: if check(center) == False:
center[0] = center[0] - 1 center[0] = center[0] - 1
elif event.key == locals.K_UP:
old_index = index
index += 1
if index == len(shape):
index = 0
current_shape = shape[index]
if check(center) == False:
old_index = index
current_shape = shape[index]
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置 # 计算出所有小方块的行、列位置
...@@ -85,7 +98,7 @@ while True: ...@@ -85,7 +98,7 @@ while True:
pygame.draw.rect(screen, color, pygame.draw.rect(screen, color,
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 0) (cube[1] * 20-20, cube[0] * 20-20, 20, 20), 0)
pygame.draw.rect(screen, (255, 255, 255), pygame.draw.rect(screen, (255, 255, 255),
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 3) (cube[1] * 20-20, cube[0] * 20-20, 20, 20), 2)
# 得分 # 得分
text_surface = font.render(str(score), True, (0, 0, 0)) text_surface = font.render(str(score), True, (0, 0, 0))
screen.blit(text_surface, (350,70)) 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