Commit 227303cb by BellCodeEditor

save project

parent 7f2c9dce
Showing with 27 additions and 8 deletions
......@@ -4,8 +4,7 @@ from pygame import locals
xy = [2,8]
# class FK():
# def __init__(self):
pygame.init() # 初始化
score = 0
......@@ -61,6 +60,12 @@ index = random.randint(0,len(shape)-1)
current_shape = shape[index]
color = random.choice(shape_colors)
def check(xy): #检测方块是否超出网格自定义函数
for i in current_shape:
i = (i[0] + xy[0],i[1]+xy[1])
if i[0] < 1 or i[1] < 1 or i[0] > grid_num_width or i[1] > grid_num_width:
return False
while True:
......@@ -72,14 +77,28 @@ while True:
exit()
if event.key == locals.K_RIGHT:
if xy[1] < 15:
xy[1] += 1
xy[1] += 1
if check(xy) == False:
xy[1] -= 1
elif event.key == locals.K_LEFT:
if xy[1] > 1:
xy[1] += -1
xy[1] -= 1
if check(xy) == False:
xy[1] += 1
elif event.key == locals.K_DOWN:
if xy[0] < 25:
xy[0] += 1
xy[0] += 1
if check(xy) == False:
xy[0] += -1
elif event.key == locals.KEY_UP:
old_index = index
index += 1
if index >= len(shape):
index = 0
current_shape = shape[index]
if check(xy) == False:
# 将背景图画上去
......
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