Commit af441d31 by BellCodeEditor

save project

parent df6ce778
Showing with 21 additions and 9 deletions
...@@ -13,6 +13,7 @@ screen = pygame.display.set_mode((460, 500)) ...@@ -13,6 +13,7 @@ screen = pygame.display.set_mode((460, 500))
pygame.display.set_caption("俄罗斯方块") pygame.display.set_caption("俄罗斯方块")
clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材 # 载入素材
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
font = pygame.font.Font('STKAITI.TTF', 60) # 字体 font = pygame.font.Font('STKAITI.TTF', 60) # 字体
...@@ -44,17 +45,23 @@ cube_colors = [ ...@@ -44,17 +45,23 @@ cube_colors = [
(255, 204, 0), (204, 0, 51),(255, 0, 51), (0, 102, 153), (255, 204, 0), (204, 0, 51),(255, 0, 51), (0, 102, 153),
(153, 0, 51), (204, 255, 102), (255, 153, 0)] (153, 0, 51), (204, 255, 102), (255, 153, 0)]
center = [2, 8] # 第2行第8列 F = 0
current_x = r.choice(shape_list) a = False
ID = r.randint(0,len(current_x)-1)
current_shape = current_x[ID]
color = r.choice(cube_colors)
def check(cent): def check(cent):
for i in current_shape: for i in current_shape:
i = (i[0] + cent[0],i[1] + cent[1]) i = (i[0] + cent[0],i[1] + cent[1])
if i[0] <= 1 or i[1] < 1 or i[0] > grid_num_height or i[1] >grid_num_width: if i[0] <= 1 or i[1] < 1 or i[0] > grid_num_height or i[1] >grid_num_width:
return False return False
while True: while True:
if a == False:
center = [2, 8] # 第2行第8列
current_x = r.choice(shape_list)
ID = r.randint(0,len(current_x)-1)
current_shape = current_x[ID]
color = r.choice(cube_colors)
a = True
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
...@@ -76,11 +83,16 @@ while True: ...@@ -76,11 +83,16 @@ while True:
ID += 1 ID += 1
if ID >= len(current_x): if ID >= len(current_x):
ID = 0 ID = 0
current_shape = current_x[ID] current_shape = current_x[ID]
if check(center) == False: if check(center) == False:
ID = o_ID ID = o_ID
current_shape = current_x[o_ID] current_shape = current_x[o_ID]
current_shape = current_x[ID] a = a + 1
if a%30 == 1:
center[0] += 1
if check(center) == False:
center[0] -= 1
a = False
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 计算出所有小方块的行、列位置 # 计算出所有小方块的行、列位置
...@@ -89,7 +101,6 @@ while True: ...@@ -89,7 +101,6 @@ while True:
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)
# 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块 # 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块
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)
...@@ -100,4 +111,4 @@ while True: ...@@ -100,4 +111,4 @@ while True:
screen.blit(text_surface, (350,70)) screen.blit(text_surface, (350,70))
# 刷新画面 # 刷新画面
pygame.display.update() 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