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


Python Block.get_pic方法代码示例

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


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

示例1: __init__

# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import get_pic [as 别名]
class Gameboard:
    def __init__(self, first_tetro,scoreboard):
        self.block_x = 4
        self.block_y = 0
        self.block = Block(first_tetro)

        self.scoreboard = scoreboard

        self.gameboard = []
        for i in range (0,BOARD_CELL_HEIGHT):
            new = []
            for j in range (0,BOARD_CELL_WIDTH):
                new.append(0)
            self.gameboard.append(new)

    def move_block(self, dir):

        if(dir == LEFT and self.did_horiz_collide()[0] is not True):
            self.block_x -= 1

        if(dir == RIGHT and self.did_horiz_collide()[1] is not True ):
            self.block_x += 1

    def new_block(self,new_tetro):
        self.block = Block(new_tetro)
        self.block_x =4
        self.block_y =0

    def block_fall(self):
        #self.print_gameboard()
        #print(self.did_vert_collide())
        if not self.did_vert_collide():
            self.block_y += 1
            return True
        else:
            self.add_to_board()
            return False

    def did_vert_collide(self,tetro=None):
        if tetro is None:
            tetro = self.block.get_pic()
        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 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)
#.........这里部分代码省略.........
开发者ID:BKreisel,项目名称:SkyBlox,代码行数:103,代码来源:gameboard.py


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