小编use*_*643的帖子

随机俄罗斯方块形状

我正在尝试编写一个python程序,将随机的俄罗斯方块形状绘制到板上.这是我的代码:

def __init__(self, win):
    self.board = Board(win, self.BOARD_WIDTH, self.BOARD_HEIGHT)
    self.win = win
    self.delay = 1000 

    self.current_shape = self.create_new_shape()

    # Draw the current_shape oan the board 
    self.current_shape = Board.draw_shape(the_shape)

def create_new_shape(self):
    ''' Return value: type: Shape

        Create a random new shape that is centered
         at y = 0 and x = int(self.BOARD_WIDTH/2)
        return the shape
    '''

    y = 0
    x = int(self.BOARD_WIDTH/2)
    self.shapes = [O_shape,
                  T_shape,
                  L_shape,
                  J_shape,
                  Z_shape,
                  S_shape,
                  I_shape]

    the_shape = random.choice(self.shapes)
    return the_shape
Run Code Online (Sandbox Code Playgroud)

我的问题在于"self.current_shape = Board.draw_shape(the_shape).它说没有定义the_shape但我认为我在create_new_shape中定义了它.

python tetris

-1
推荐指数
1
解决办法
567
查看次数

尝试在Python中使用元组作为字典键时的键错误(0,0)

我得到了Key Error: (0, 0).在我的代码的这一部分中,我试图在我的网格中创建具有键(x,y)的块的字典.这是我的代码:

self.block_list = {}
for x in range(0, self.width):
    for y in range(0, self.height):
        self.block_list[(x, y)] 
Run Code Online (Sandbox Code Playgroud)

我不明白为什么(0,0)没有包含在字典中.

python

-2
推荐指数
1
解决办法
8872
查看次数

标签 统计

python ×2

tetris ×1