Commit 486b6d47 by BellCodeEditor

save project

parent 1dd7b9f7
Showing with 14 additions and 7 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 score = 0
grid_size = 20 # 格子大小 grid_size = 20 # 格子大小
...@@ -18,8 +18,7 @@ font = pygame.font.Font('STKAITI.TTF', 60) # 字体 ...@@ -18,8 +18,7 @@ font = pygame.font.Font('STKAITI.TTF', 60) # 字体
# 俄罗斯方块所有形状 # 俄罗斯方块所有形状
O = [[(0, 0), (0, 1), (1, 0), (1, 1)]] O = [[(0, 0), (0, 1), (1, 0), (1, 1)]]
I = [[(0, -1), (0, 0), (0, 1), (0, 2)], I = [(0, -1), (0, 0), (0, 1), (0, 2)]
[(-1, 0), (0, 0), (1, 0), (2, 0)]]
Z = [[(0, -1), (0, 0), (1, 0), (1, 1)], Z = [[(0, -1), (0, 0), (1, 0), (1, 1)],
[(-1, 0), (0, 0), (0, -1), (1, -1)]] [(-1, 0), (0, 0), (0, -1), (1, -1)]]
S = [[(-1, 0), (0, 0), (0, 1), (1, 1)], S = [[(-1, 0), (0, 0), (0, 1), (1, 1)],
...@@ -46,22 +45,30 @@ cube_colors = [ ...@@ -46,22 +45,30 @@ cube_colors = [
center = [2, 8] # 第2行第8列 center = [2, 8] # 第2行第8列
current_shape = [(0, -1), (0, 0), (0, 1), (-1, 0)] current_shape = [(0, -1), (0, 0), (0, 1), (-1, 0)]
co = random.randint(0,9)
color = cube_colors[co]
sh = random.choice(shape_list)
hs = random.randint(0,len(sh)-1)
current_shape = sh[hs]
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 center[1] < 15: if center[1] < 14:
center[1] += 1 center[1] += 1
elif event.key == locals.K_LEFT: # 向左 elif event.key == locals.K_LEFT: # 向左
if center[1] > 1: if center[1] > 1:
center[1] -= 1 center[1] -= 1
elif event.key == locals.K_DOWN: # 向下 elif event.key == locals.K_DOWN: # 向下
if center[0] < 25: for cube in current_shape:
if 2 in cube:
if center[0] < 23:
center[0] += 1
else:
if center[0] < 24:
center[0] += 1 center[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