Commit eb192432 by BellCodeEditor

save project

parent 1dd7b9f7
Showing with 9 additions and 5 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
from random import randint
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 score = 0
grid_size = 20 # 格子大小 grid_size = 20 # 格子大小
...@@ -36,7 +37,8 @@ L = [[(-1, 0), (0, 0), (1, 0), (1, 1)], ...@@ -36,7 +37,8 @@ L = [[(-1, 0), (0, 0), (1, 0), (1, 1)],
[(0, -1), (0, 0), (0, 1), (1, -1)], [(0, -1), (0, 0), (0, 1), (1, -1)],
[(-1, 0), (0, 0), (1, 0), (-1, -1)], [(-1, 0), (0, 0), (1, 0), (-1, -1)],
[(0, -1), (0, 0), (0, 1), (-1, 1)]] [(0, -1), (0, 0), (0, 1), (-1, 1)]]
shape_list = [I, J, L, O, S, T, Z] # 7种类型俄罗斯方块 CZ = [(-1,-2),(-1,-1),(-1,0),(-1,1),(-1,2),(0,-2),(0,-1),(0,0),(0,1),(0,2),(1,0),(2,0),(3,0)]
shape_list = [I, J, L, O, S, T, Z, CZ] # 7种类型俄罗斯方块
# 一些RGB颜色 # 一些RGB颜色
cube_colors = [ cube_colors = [
...@@ -48,6 +50,8 @@ center = [2, 8] # 第2行第8列 ...@@ -48,6 +50,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)]
while True: while True:
ELSFK_color = cube_colors[random.randint(0,len(cube_colors)-1)]
ELSFK_screen = shape_list[random.randint(0,len(shape_list)-1)]
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
...@@ -71,9 +75,9 @@ while True: ...@@ -71,9 +75,9 @@ while True:
current_pos.append(pos) current_pos.append(pos)
# 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块 # 取出所有小方块的行、列位置,计算坐标,绘制俄罗斯方块
for cube in current_pos: for cube in current_pos:
pygame.draw.rect(screen, color, pygame.draw.rect(shape_list[random.randint(0,len(shape_list)-1)], cube_colors[random.randint(0,len(cube_colors)-1)],
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 0) (cube[1]*20-20, cube[0]*20-20, 20, 20), 0)
pygame.draw.rect(screen, (255, 255, 255), pygame.draw.rect(shape_list[random.randint(0,len(shape_list)-1)], (255, 255, 255),
(cube[1] * 20-20, cube[0] * 20-20, 20, 20), 1) (cube[1] * 20-20, cube[0] * 20-20, 20, 20), 1)
# 得分 # 得分
text_surface = font.render(str(score), True, (0, 0, 0)) text_surface = font.render(str(score), True, (0, 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