Commit a6e35c57 by BellCodeEditor

save project

parent d20c3889
Showing with 31 additions and 10 deletions
...@@ -59,7 +59,12 @@ def check(center): ...@@ -59,7 +59,12 @@ def check(center):
if cube[0] < 1 or cube[1] < 1 or cube[0] > grid_num_height \ if cube[0] < 1 or cube[1] < 1 or cube[0] > grid_num_height \
or cube[1] >grid_num_width or save[cube[0]-1][cube[1]-1]!=0: or cube[1] >grid_num_width or save[cube[0]-1][cube[1]-1]!=0:
return False return False
center = [2, 8] # 第2行第8列
next_shape = random.choice(shape_list)
next_index = random.randint(0, len(next_shape)-1) # 随机形状索引
next_current_shape = next_shape[next_index]
current_shape=next_shape[next_index]
next_color = random.choice(cube_colors)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -92,22 +97,30 @@ while True: ...@@ -92,22 +97,30 @@ while True:
index = old_index index = old_index
current_shape = shape[index] current_shape = shape[index]
if gameover==False: if gameover==False:
if states == False: # 随机选取一种颜色
states = True
center = [2, 8] # 第2行第8列
shape = random.choice(shape_list)
index = random.randint(0, len(shape)-1) # 随机形状索引
current_shape = shape[index]
color = random.choice(cube_colors) # 随机选取一种颜色
count += 1 count += 1
if count % FPS == 0: # 降落速度的算式 if count % FPS == 0: # 降落速度的算式
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
states = False states = False
shape=next_shape
#color=next_color
index=next_index
current_shape=shape[index]
for cube in current_pos: for cube in current_pos:
save[cube[0]-1][cube[1]-1]=color save[cube[0]-1][cube[1]-1]=color
if states == False:
states = True
center = [2, 8]
shape=next_shape
color=next_color
index=next_index
current_shape=shape[index] # 第2行第8列
next_shape = random.choice(shape_list)
next_index = random.randint(0, len(next_shape)-1) # 随机形状索引
next_current_shape = next_shape[next_index]
next_color = random.choice(cube_colors)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置 # 计算出所有小方块的行、列位置
...@@ -115,7 +128,14 @@ while True: ...@@ -115,7 +128,14 @@ while True:
for cube in current_shape: for cube in current_shape:
pos = (cube[0] + center[0], cube[1] + center[1]) pos = (cube[0] + center[0], cube[1] + center[1])
current_pos.append(pos) current_pos.append(pos)
next_current_pos = []
for cube in next_current_shape:
pos = (cube[0] + 6, cube[1] +20 )
next_current_pos.append(pos)
# 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块 # 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块
for cube in next_current_pos:
pygame.draw.rect(screen, next_color,(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)
for cube in current_pos: for cube in current_pos:
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)
...@@ -143,9 +163,10 @@ while True: ...@@ -143,9 +163,10 @@ while True:
else: else:
score+=1 score+=1
save=save_2 save=save_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, (400,20))
text_gameover=font_gameover.render('游戏结束,按任意键重新开始',True,(0,0,0)) text_gameover=font_gameover.render('游戏结束,按任意键重新开始',True,(0,0,0))
if save[1][7]!=0: if save[1][7]!=0:
gameover=True gameover=True
......
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