Commit 9f90b7b3 by BellCodeEditor

save project

parent 16e606f6
Showing with 36 additions and 3 deletions
import pygame
import random
from pygame import locals
pygame.init() # 初始化
......@@ -7,8 +8,7 @@ grid_size = 20 # 格子大小
grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量
FPS = 30
position = [2,7]
current_pos = [(0,-1),(0,0),(0,1),(-1,0)]
......@@ -21,6 +21,39 @@ background = pygame.image.load('bg.png')
font = pygame.font.Font('STKAITI.TTF', 60) # 字体
# 俄罗斯方块所有形状
O = [[(0, 0), (0, 1), (1, 0), (1, 1)]]
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)],
[(-1, 0), (0, 0), (0, -1), (1, -1)]]
S = [[(-1, 0), (0, 0), (0, 1), (1, 1)],
[(1, -1), (1, 0), (0, 0), (0, 1)]]
T = [[(0, -1), (0, 0), (0, 1), (-1, 0)],
[(-1, 0), (0, 0), (1, 0), (0, 1)],
[(0, -1), (0, 0), (0, 1), (1, 0)],
[(-1, 0), (0, 0), (1, 0), (0, -1)]]
J = [[(-1, 0), (0, 0), (1, 0), (1, -1)],
[(0, -1), (0, 0), (0, 1), (-1, -1)],
[(-1, 0), (0, 0), (1, 0), (-1, 1)],
[(0, -1), (0, 0), (0, 1), (1, 1)]]
L = [[(-1, 0), (0, 0), (1, 0), (1, 1)],
[(0, -1), (0, 0), (0, 1), (1, -1)],
[(-1, 0), (0, 0), (1, 0), (-1, -1)],
[(0, -1), (0, 0), (0, 1), (-1, 1)]]
shape_list = [I, J, L, O, S, T, Z] # 7种类型俄罗斯方块
# 一些RGB颜色
cube_colors = [
(204, 153, 153), (102, 102, 153),(153, 0, 102),
(255, 204, 0), (204, 0, 51),(255, 0, 51), (0, 102, 153),
(153, 0, 51), (204, 255, 102), (255, 153, 0)]
position = [2,8]
shape = random.choice(shape_list)
color = random.choice(cube_colors)
direction = random.randint(0,len(shape) - 1)
current_pos = shape[direction]
while True:
......@@ -53,7 +86,7 @@ while True:
# 将背景图画上去
screen.blit(background,(0,0))
for mypos in cube:
pygame.draw.rect(screen,(0,0,250),
pygame.draw.rect(screen,color,
((mypos[1] - 1) * grid_size,(mypos[0] - 1) * grid_size,grid_size,grid_size),0)
pygame.draw.rect(screen,(255,255,255),
((mypos[1] - 1) * grid_size,(mypos[0] - 1) * grid_size,grid_size,grid_size),1)
......
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