Commit 49447391 by BellCodeEditor

save project

parent 9af1f7b8
Showing with 19 additions and 3 deletions
......@@ -9,6 +9,7 @@ grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量
FPS = 30
# 创建窗口
screen = pygame.display.set_mode((460, 500))
pygame.display.set_caption("俄罗斯方块")
......@@ -44,8 +45,16 @@ cube_colors=[(204,153,153),(102,102,153),(153,0,102),
(153,0,51),(204,255,102),(255,153,0)]
random_cube=random.choice(shape_list)
count=random.randint(0,len(random_cube)-1)
random_color=random.choice(cube_colors)
random_facing=random.choice(random_cube)
random_facing=random_cube[count]
def check(main_pos):
for cube in random_facing:
cube= (cube[0]+main_pos[0],cube[1]+main_pos[1])
if cube[0]<1 or cube[1]<1 or cube[0]>grid_num_height or cube[1]>grid_num_width:
return False
while True:
for event in pygame.event.get():
......@@ -53,11 +62,18 @@ while True:
exit()
if event.type == locals.KEYDOWN:
if event.key==locals.K_LEFT:
if main_pos[1]>1:
main_pos[1]=main_pos[1]-1
if check(main_pos)==False:
main_pos[1]+=1
# if main_pos[1]>1:
# main_pos[1]=main_pos[1]-1
if event.key==locals.K_RIGHT:
if main_pos[1]<15:
#if main_pos[1]<15:
main_pos[1]=main_pos[1]+1
if check(main_pos)==False:
main_pos[1]-=1
if event.key==locals.K_DOWN:
if main_pos[0]<25:
main_pos[0]=main_pos[0]+1
......
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