Commit 9dd5067d by BellCodeEditor

save project

parent 099c6925
Showing with 25 additions and 18 deletions
......@@ -48,15 +48,19 @@ cube_colors = [
(153, 0, 51), (204, 255, 102), (255, 153, 0)]
def check(center):
for cubem in current_shape:
cubem = (cubem[0] + center[0], cubem[1] + center[1])
for cube in current_shape:
cube = (cube[0] + center[0], cube[1] + center[1])
# 当前的小方块超出网格的行、列,就返回False
if cubem[0] < 1 or cubem[1] < 1 or cubem[0] > grid_num_height \
or cubem[1] >grid_num_width:
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[cubem[0]-1][cubem[1]-1]!=0:
if num_list[cube[0]-1][cube[1]-1] != 0:
return False
num_list=[[0]*15]*25
# 格子基础数字设为0
num_list = []
for i in range(25):
num_list.append([0] * 15)
while True:
for event in pygame.event.get():
......@@ -87,7 +91,7 @@ while True:
if check(center) == False:
index = old_index
current_shape = shape[index]
# 生成新俄罗斯方块
if states == False:
states = True
center = [2, 8] # 第2行第8列
......@@ -100,10 +104,9 @@ while True:
center[0] = center[0] + 1
if check(center) == False:
center[0] = center[0] - 1
states = False
for i in current_pos:
num_list[i[0]-1][i[1]-1]=color
states = False
for cube in current_pos:
num_list[cube[0]-1][cube[1]-1] = color
# 将背景图画上去
screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置
......@@ -117,15 +120,18 @@ 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)
for i,row in zip(range(1,26),num_list):
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),0)
pygame.draw.rect(screen,(255,255,255),(j*20-20,i*20-20,20,20),1)
# 画出降落后的方块
for i, row in zip(range(1,26), num_list):# i代表的是什么呢? (行)
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))
pygame.draw.rect(screen, (255, 255, 255),
(j * 20-20, i * 20-20, 20, 20), 1)
# 得分
text_surface = font.render(str(score), True, (0, 0, 0))
screen.blit(text_surface, (350,70))
# 刷新画面
pygame.display.update()
clock.tick(FPS)
clock.tick(FPS)
\ No newline at end of file
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