当前位置: 首页>>代码示例>>Python>>正文


Python Block.rotate方法代码示例

本文整理汇总了Python中block.Block.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Block.rotate方法的具体用法?Python Block.rotate怎么用?Python Block.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在block.Block的用法示例。


在下文中一共展示了Block.rotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_blocks

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import rotate [as 别名]
    def test_add_blocks(self):
        self.test_init_field()

        for i, b_data in enumerate(self.raw_data):
            b = Block(b_data["type"], b_data["conns"], b_data["name"], b_data["groups"])

            b.rotate(b_data["rot"])
            b.mirror(set_to=b_data["mir"])

            self.field.add_block(b, b_data["pos"])

        self.assertEqual(len(self.field), len(self.raw_data))
开发者ID:ChristianOAuth,项目名称:schemmaker,代码行数:14,代码来源:regression.py

示例2: spawn_block

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import rotate [as 别名]
    def spawn_block(self):
        """
        Creates a new block with random starting position/random orientation.
        """
        block = Block()
        #block.position = (random.randint(0,GRID_WIDTH-1),block.position[1]) #uncomment here and comment below for randomly positioned blocks
        block.position = (GRID_WIDTH/2,block.position[1]) #spawn in middle of field
        for i in range(random.randint(0,3)): #random orientation
            block.rotate(True)

        self.block_count += 1
        return block
开发者ID:Andrew-Lucero,项目名称:tetris,代码行数:14,代码来源:tetris.py

示例3: BlockUnitTest

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import rotate [as 别名]
class BlockUnitTest(unittest.TestCase):
    def setUp(self):
        self.blk = None
        self.pin_posi = [(1, 0), (0, 1), (1, 2), (2, 1)]
        self.pin_dirs = [  0   ,   1   ,   2   ,   3   ]

    def test_construct_block(self):
        self.blk = Block("nmos", ["n1", "n2", "n3"], "N1", (0, 1), (2, 2), None)


    def test_rotate_ccw(self):
        self.test_construct_block()

        get_pins = self.blk.get_pins_from_direction
        get_dir = self.blk.get_pin_direction

        for d in self.pin_dirs:
            pins = get_pins(self.pin_dirs[d])
            self.assertEqual(len(pins), 1)
            pin = pins[0]
            self.assertEqual(get_dir(pin), self.pin_dirs[d])
            self.assertEqual(pin.pos, self.pin_posi[d])
            self.blk.rotate(1)
开发者ID:ChristianOAuth,项目名称:schemmaker,代码行数:25,代码来源:block_test.py

示例4: __init__

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import rotate [as 别名]

#.........这里部分代码省略.........
            rel_x = -1
            for val in cell:
                rel_x +=1
                x = self.block_x + rel_x
                y = self.block_y + rel_y
                if val > 0:
                    if y >= 15 or y < 0:
                        return True
                    if x < 0 or x > 9:
                        return True
                    else:
                        if self.gameboard[y+1][x] > 0:
                            return True
        return False

    def did_horiz_collide(self,tetro=None):
        if tetro is None:
            tetro = self.block.get_pic()
        left,right = False,False
        rel_y = -1
        for cell in tetro:
            rel_y += 1
            rel_x = -1
            for val in cell:
                rel_x +=1
                x = self.block_x + rel_x
                y = self.block_y + rel_y

                if val > 0:
                    if x <= 0:
                        left = True
                    elif self.gameboard[y][x-1] > 0:
                        left = True

                    if x >= 9:
                        right = True
                    elif self.gameboard[y][x+1] > 0:
                        right = True

        return [left,right]

    #Lowers all of the lines to replace a destroyed line.
    def drop_board(self,max_row):
        if max_row == 0:
            return
        for row in range(max_row,0,-1):
            for col in range(0,BOARD_CELL_WIDTH):
                self.gameboard[row][col] = self.gameboard[row-1][col]
        #Clear the first row
        self.destroy_line(0)

    #Overwrites a line with 0's
    def destroy_line(self,row):
        for col in range(0, BOARD_CELL_WIDTH):
            self.gameboard[row][col] = 0
        self.drop_board(row)

    #Handles checks for whether a line is full and clearing it if it is
    def clear_line(self):
        destroyed = 0
        for row in range(0,BOARD_CELL_HEIGHT):
            for col in range(0,BOARD_CELL_WIDTH):
                if self.get_pos(col,row) == 0:
                    break
                if col == BOARD_CELL_WIDTH - 1:
                    self.destroy_line(row)
                    destroyed +=1
        self.scoreboard.lines_up(destroyed)

    def add_to_board(self):
        rel_y = -1
        block = self.block.get_pic()
        for cell in block:
            rel_y += 1
            rel_x = -1
            for val in cell:
                rel_x +=1
                x = self.block_x + rel_x
                y = self.block_y + rel_y

                if val > 0:
                    self.gameboard[y][x] = val

        #if a line is complete, destory it.
        self.clear_line()

    def print_gameboard(self):
        for line in self.gameboard:
            print(line)

    def do_rotate(self,direction):
        next_tetro = self.block.get_next_pic(direction)
        left,right = self.did_horiz_collide(next_tetro)
        vert = self.did_vert_collide(next_tetro)

        if left is False and right is False and vert is False:
            self.block.rotate(direction)

    def get_pos(self, x, y):
        return self.gameboard[y][x]
开发者ID:BKreisel,项目名称:SkyBlox,代码行数:104,代码来源:gameboard.py


注:本文中的block.Block.rotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。