Commit 4acc5da7 by BellCodeEditor

save project

parent d40eaaab
Showing with 15 additions and 7 deletions
...@@ -6,7 +6,7 @@ pygame.init() # 初始化 ...@@ -6,7 +6,7 @@ pygame.init() # 初始化
fs = 0 fs = 0
gzdx = 20 # 格子大小 gzdx = 20 # 格子大小
gznumh = 15 # 横向格子数量 gznumh = 15 # 横向格子数量
gznum_g = 25 # 纵向格子数量 gznumg = 25 # 纵向格子数量
FPS = 30 FPS = 30
# 创建窗口 # 创建窗口
...@@ -51,20 +51,28 @@ shape=random.choice(shape_list) ...@@ -51,20 +51,28 @@ shape=random.choice(shape_list)
sxzy=random.randint(0,len(shape)-1) sxzy=random.randint(0,len(shape)-1)
current_shape = shape[sxzy] current_shape = shape[sxzy]
def check(hl):
for cube in current_shape:
cube = (cube[0] + hl[0], cube[1] + hl[1])
if cube[0] < 1 or cube[1] < 1 or cube[0] > gznumg or cube[1] >gznumh:
return False
while True: while 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()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT: # 向右 if event.key == locals.K_RIGHT: # 向右
if hl[1] < 15: hl[1]+=1
hl[1] += 1 if check(hl) == False:
hl[1]-=1
elif event.key == locals.K_LEFT: # 向左 elif event.key == locals.K_LEFT: # 向左
if hl[1] > 1: hl[1]-=1
hl[1] -= 1 if check(hl) == False:
hl[1]+=1
elif event.key == locals.K_DOWN: # 向下 elif event.key == locals.K_DOWN: # 向下
if hl[0] < 25: hl[0]+=1
hl[0] += 1 if check(hl) == False:
hl[0]-=1
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
......
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