用户:
044查看:0 回复:0 评论:0 创建时间:2022-07-05T22:30:32
【作品展示】

【作品介绍】
???
【作品源代码】
((0, 0), (0, 1), (1, 0), (0, -1)),
((0, 0), (1, 0), (-1, 0), (1, -1)),
((0, 0), (1, 0), (-1, 0), (1, 1)))
background = [[0 for i in range(10)] for j in range(24)]
background[0] = [1 for i in range(10)]import pygame
import sys
import random
import time
def new_draw():
screen.fill(brown)
for i in range(1, 21):
for j in range(10):
bolck = background[i][j]
if bolck:
pygame.draw.rect(
screen, black, (j * 25 + 1, 500 - i * 25 + 1, 23, 23))
x, y = centre
for i, j in active:
i += x
j += y
pygame.draw.rect(
screen, black, (j * 25 + 1, 500 - i * 25 + 1, 23, 23))
pygame.display.update()
def move_LR(n):
x, y = centre
y += n
for i, j in active:
i += x
j += y
if j < 0 or j > 9 or background[i][j]:
break
else:
centre.clear()
centre.extend([x, y])
def rotate():
x, y = centre
l = [(-j, i) for i, j in active]
for i, j in l:
i += x
j += y
if j < 0 or j > 9 or background[i][j]:
break
else:
active.clear()
active.extend(l)
def move_down():
x, y = centre
x -= 1
for i, j in active:
i += x
j += y
if background[i][j]:
break
else:
centre.clear()
centre.extend([x, y])
return
x, y = centre
for i, j in active:
background[x + i][y + j] = 1
l = []
for i in range(1, 20):
if 0 not in background[i]:
l.append(i)
l.sort(reverse=True)
for i in l:
background.pop(i)
background.append([0 for j in range(10)])
score[0] += len(l)
pygame.display.set_caption("分数:%d" % (score[0]))
active.clear()
active.extend(list(random.choice(all_block)))
centre.clear()
centre.extend([20, 4])
x, y = centre
for i, j in active:
i += x
j += y
if background[i][j]:
break
else:
return
alive.append(1)
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((250, 500))
pygame.display.set_caption("俄罗斯方块")
fclock = pygame.time.Clock()
all_block = (((0, 0), (0, -1), (0, 1), (0, 2)),
((0, 0), (0, 1), (-1, 0), (-1, 1)),
((0, 0), (0, -1), (-1, 0), (-1, 1)),
((0, 0), (0, 1), (-1, -1), (-1, 0)),
active = list(random.choice(all_block))
centre = [20, 4]
score = [0]
black = 0, 0, 0
brown = 255, 255, 255
blue = 0, 0, 255
times = 0
alive = [ ]
press = False
while True:
for event in pygame.event.get():
if event.type == pygame.quit:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
move_LR(-1)
elif event.key == pygame.K_RIGHT:
move_LR(1)
elif event.key == pygame.K_UP:
rotate()
press = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_DOWN:
press = False
if press:
elif event.key == pygame.K_DOWN:
times += 10
if times >= 50:
move_down()
times = 0
else:
times += 1
if alive:
pygame.display.set_caption("分数:%d" % (score[0]))
time.sleep(3)
break
new_draw()
fclock.tick(100)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn