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


Python Block.get_next_pic方法代码示例

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


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

示例1: __init__

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import get_next_pic [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.get_next_pic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。