From 9f90b7b367cf347b1c9017882b3e5b654282fa14 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sat, 27 Nov 2021 09:07:18 +0800 Subject: [PATCH] save project --- my_Tetris.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/my_Tetris.py b/my_Tetris.py index 78f38ae..dc73544 100644 --- a/my_Tetris.py +++ b/my_Tetris.py @@ -1,4 +1,5 @@ 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) -- libgit2 0.25.0