Commit 54bc2474 by BellCodeEditor

save project

parent 19bc610f
Showing with 21 additions and 21 deletions
......@@ -47,7 +47,7 @@ cube_colors = [
(255, 204, 0), (204, 0, 51),(255, 0, 51), (0, 102, 153),
(153, 0, 51), (204, 255, 102), (255, 153, 0)]
num_list=[]
num_list = []
for i in range(25):
num_list.append([0]*15)
......@@ -58,7 +58,7 @@ def check(center):
if cube[0] < 1 or cube[1] < 1 or cube[0] > grid_num_height \
or cube[1] >grid_num_width:
return False
if num_list[cube[0]-1][cube[1]-1]!=0:
if num_list[cube[0]-1][cube[1]-1] != 0:
return False
while True:
......@@ -105,7 +105,7 @@ while True:
center[0] = center[0] - 1
states = False
for cube in current_pos:
num_list[(cube[0]-1)][cube[1]-1] =color
num_list[(cube[0]-1)][cube[1]-1] = color
# 将背景图画上去
screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置
......@@ -120,30 +120,30 @@ while True:
pygame.draw.rect(screen, (255, 255, 255),
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 1)
for i,p in zip(range(1,26),num_list):
for j , colors in zip (range(1,16),p):
if colors !=0:
pygame.draw.rect(screen,color,
(j*20-20,i*20-20,20,20),0)
pygame.draw.rect(screen,(255,255,255),
(j*20-20,i*20-20,20,20),1)
for i, p in zip(range(1,26), num_list): #把两个列表组合成元组
for j , colors in zip(range(1,16),p):
if colors != 0:
pygame.draw.rect(screen, color,
(j * 20-20, i * 20-20, 20, 20), 0)
pygame.draw.rect(screen, (255, 255, 255),
(j * 20-20, i * 20-20, 20, 20), 1)
new_list= []
new_list = []
for i in range(25):
new_list.append([0]*15)
p_index = 24
p_index = 24 #索引(0-24) 代表25行
for i in range(24,-1,-1):
is_full = True
is_full = True #创建新的变量用来记录是否被填满
for j in range(grid_num_width):
if num_list[i][j]==0:
is_full =False
if num_list[i][j] == 0:
is_full = False
if is_full== False:
new_list [p_index]=num_list[i]
p_index-= 1
else:
score+=1
num_list = new_list
if is_full == False:#当没被填满 就进行替换
new_list[p_index] = num_list[i]
p_index -= 1 # 从下往上换行替换
else: #被替换满了,成绩加1
score += 1
num_list = new_list #用旧的替换掉新的
# 得分
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