Commit ea23e728 by BellCodeEditor

save project

parent 4131aa66
Showing with 65 additions and 55 deletions
...@@ -98,60 +98,70 @@ while True: ...@@ -98,60 +98,70 @@ while True:
if check(center) == False: if check(center) == False:
index = old_index index = old_index
current_shape = shape[index] current_shape = shape[index]
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
if count % FPS == 0: # 降落速度的算式
center[0] = center[0] + 1
if check(center) == False:
center[0] = center[0] - 1
states = False
for cube in current_pos:
num_list[cube[0]-1][cube[1]-1] = color
if states == False: # 将背景图画上去
states = True screen.blit(background, (0, 0))
center = [2, 8] # 第2行第8列 # 计算出所有小方块的行、列位置
shape = random.choice(shape_list) current_pos = []
index = random.randint(0, len(shape)-1) # 随机形状索引 for cube in current_shape:
current_shape = shape[index] pos = (cube[0] + center[0], cube[1] + center[1])
color = random.choice(cube_colors) # 随机选取一种颜色 current_pos.append(pos)
count += 1 # 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块
if count % FPS == 0: # 降落速度的算式 for cube in current_pos:
center[0] = center[0] + 1 pygame.draw.rect(screen, color,
if check(center) == False: (cube[1] * 20-20, cube[0] * 20-20, 20, 20), 0)
center[0] = center[0] - 1 pygame.draw.rect(screen, (255, 255, 255),
states = False (cube[1] * 20-20, cube[0] * 20-20, 20, 20), 1)
for cube in current_pos: for i,row in zip(range(1,26),num_list):
num_list[cube[0]-1][cube[1]-1] = color for j,colors in zip(range(1,16),row):
if colors !=0:
# 将背景图画上去 pygame.draw.rect(screen,colors,(j*20-20,i*20-20,20,20))
screen.blit(background, (0, 0)) pygame.draw.rect(screen,(255,255,255),(j*20-20,i*20-20,20,20),1)
# 计算出所有小方块的行、列位置
current_pos = [] new_list= []
for cube in current_shape: for i in range(25):
pos = (cube[0] + center[0], cube[1] + center[1]) new_list.append([0]*15)
current_pos.append(pos) row_index = 24
# 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块 for i in range(24,-1,-1):
for cube in current_pos: is_full = True
pygame.draw.rect(screen, color, for j in range(grid_num_width):
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 0) if num_list[i][j] == 0:
pygame.draw.rect(screen, (255, 255, 255), is_full = False
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 1) if is_full == False:
for i,row in zip(range(1,26),num_list): new_list[row_index]=num_list[i]
for j,colors in zip(range(1,16),row): row_index -= 1
if colors !=0: else:
pygame.draw.rect(screen,colors,(j*20-20,i*20-20,20,20)) score += 1
pygame.draw.rect(screen,(255,255,255),(j*20-20,i*20-20,20,20),1) num_list = new_list
if num_list[1][7]!=0:
new_list= [] gameover = True
for i in range(25):
new_list.append([0]*15) # 得分
row_index = 24 text_surface = font.render(str(score), True, (0, 0, 0))
for i in range(24,-1,-1): screen.blit(text_surface, (350,70))
is_full = True if gameover == True:
for j in range(grid_num_width): text = font_restart.render("游戏失败,按任意键重新开始",True,(0,0,0))
if num_list[i][j] == 0: screen.blit(text,(20,250))
is_full = False score = 0
if is_full == False: new_list = []
new_list[row_index]=num_list[i] for i in range(25):
row_index -= 1 num_list.append([0]*15)
else:
score += 1
num_list = new_list
# 得分
text_surface = font.render(str(score), True, (0, 0, 0))
screen.blit(text_surface, (350,70))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
clock.tick(FPS) clock.tick(FPS)
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