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


Python Piece.setBoard方法代码示例

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


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

示例1: __init__

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import setBoard [as 别名]

#.........这里部分代码省略.........
        return False
    
    def isRotatable(self):
        if (time.clock() - self.time['rotated']) > self.interval['rotate']:
            return True
        if (time.clock() - self.time['stopped_rotating'])< PtModel.INTERVAL['rotate']:
            return True
        return False
    
    def movePiece(self, direction):
        if direction == 'up':
            self.p.drop()
        else:
            self.p.move(direction)
        self.time['moved'] = time.clock()
        if self.interval['move'] > 0.1:
            self.interval['move'] *= 0.9
#        self.flag['moving'] = True

    def rotatePiece(self, radius):
        self.p.rotate(radius)
        self.time['rotated'] = time.clock()
        if(self.interval['rotate']>0.1):
            self.interval['rotate'] *= 0.9
#        self.flag['rotating'] = True

    def fallPiece(self):
        if time.clock() - self.time['fell'] > self.interval['gravity']:
            self.time['fell'] = time.clock()
            self.p.move('down')
            self.time['moved'] = time.clock()
    
    def isAlive(self):
        for i in self.board.getShape()[3]:
            if i!=0 and i!=8: return False
        return True
    
    def updateBoard(self):
        p_shape = self.p.getShape()
        p_type = self.p.getType()
        self.board.update(p_shape, p_type, self.p.getX(), self.p.getY())

    def updatePiece(self):
        self.p = copy.deepcopy(self.p_next)
        self.p.setBoard(self.board)
        self.p_next = Piece(self.board)
        self.view.renderNext(self.p_next.getShape(), self.p_next.getType())

    def update(self):
        if self.isWaiting():
            return False
        self.updateBoard()
        self.erase()
        self.updatePiece()
        return True
            
    def erase(self):
        self.score += PtModel.SCORE[self.board.erase()]

    def isWaiting(self):
        if self.p.isGround():
            if time.clock() - self.time['moved'] < self.interval['gravity']:
                return True
            if time.clock() - self.time['rotated'] < self.interval['gravity']:
                return True
            return False
        return True
    
    def gameOver(self):
        pass
    
    def tick(self):
        pygame.time.Clock().tick(15)

    # boardとpieceを統合して現在の画面の状態を得る
    def getCurrentBoard(self):
        b_shape = copy.deepcopy(self.board.getShape())
        p_shape = self.p.getShape()
        p_type = self.p.getType()
        offset_x = self.p.getX()
        offset_y = self.p.getY()
        for i in range(len(p_shape)):
            for j in range(len(p_shape[i])):
                if p_shape[i][j]:
                    b_shape[i + offset_y][j + offset_x] = p_type
        return b_shape

    def draw(self):
        self.view.renderBoard(self.getCurrentBoard())
        self.view.renderScore(self.score)
        pygame.display.update()
    
    def loop(self):
        self.tick()
        self.update()
        if self.isAlive() == False:
            self.gameOver()
        self.getKey()
        self.fallPiece()
        self.draw()
开发者ID:fand,项目名称:pytetris,代码行数:104,代码来源:model.py


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