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


Python Shape.new方法代码示例

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


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

示例1: Tetris

# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import new [as 别名]

#.........这里部分代码省略.........
                pygame.display.update()
            pygame.time.wait(80)
        # remove filled lines
        [self.board.pop(l) for l in sorted(filled, reverse=True)]
        # fill with blank lines
        [self.board.insert(0, [None] * self.W) for l in filled]
        self.get_score(len(filled))

    def get_score(self, num):
        self.killed += num
        self.score += num * num * 10 * self.level
        self.level = 1 + self.killed // 10
        self.time = self.SPACE * 0.9 ** (self.level - 1)

    def add_to_board(self):
        for x in xrange(self.shape.SHAPEW):
            for y in xrange(self.shape.SHAPEH):
                if self.shape.shape[y][x]:
                    self.board[self.shape.y+y][self.shape.x+x] = Tile(
                            self.shape.color,self.shape._image[self.shape.index])

    def create_board_image(self):
        self.board_image.fill((0, 0, 0))
        for x in xrange(self.H):
            for y in xrange(self.W):
                if self.board[x][y]:
                    rect = pygame.Rect(y * self.TILEW, x * self.TILEW,
                            self.TILEW, self.TILEW)
                    self.board_image.blit(self.board[x][y].image, rect)

    def next(self):
        if self.shape.at_bottom():
            play_sound('drop')
            self.check_line()
            self.shape.new()
            self.display_info()
        else:
            self.shape.move(0, 1)

    def draw(self):
        self.screen.blit(self.board_image, self.START)
        self.shape.draw(self.screen)
        if self.pause:
            util.myprint(self.screen, "PAUSE",
                    (self.START[0]+50, self.START[1]+200), "m")

    def display_info(self):
        self._display_next()
        self._display_score()

    def _display_score(self):
        try:
            self._score_board
        except AttributeError:
            self._score_board = (
                    self.START[0] + self.WIDTH + 30,
                    self.START[1] + 100,
                    200, 260)
            self._score_level = (
                    self._score_board[0] + 10,
                    self._score_board[1] + 10)
            self._score_level_v = (
                    self._score_board[0] + 30,
                    self._score_board[1] + 50)
            self._score_killed = (
                    self._score_board[0] + 10,
                    self._score_board[1] + 90)
            self._score_killed_v = (
                    self._score_board[0] + 30,
                    self._score_board[1] + 130)
            self._score_score = (
                    self._score_board[0] + 10,
                    self._score_board[1] + 170)
            self._score_score_v = (
                    self._score_board[0] + 30,
                    self._score_board[1] + 210)
        self.screen.fill((0, 0, 0), self._score_board)
        util.myprint(self.screen, 'LEVEL',  self._score_level, 'm')
        util.myprint(self.screen, self.level,  self._score_level_v, 'm')
        util.myprint(self.screen, 'LINES',  self._score_killed, 'm')
        util.myprint(self.screen, self.killed,  self._score_killed_v, 'm')
        util.myprint(self.screen, 'SCORE',  self._score_score, 'm')
        util.myprint(self.screen, self.score,  self._score_score_v, 'm')

    def _display_next(self):
        try:
            self._next_board
        except AttributeError:
            self._next_board = (
                    self.START[0] + self.WIDTH + 30,
                    self.START[1],
                    200, 80)
            self._next_board_v = (
                    self.START[0] + self.WIDTH + 30 + 100 - self.TILEW * 2,
                    self.START[1] + 40 - self.TILEW * 2)
        self.screen.fill((0, 0, 0), self._next_board)
        self.screen.blit(self.shape.image_next, self._next_board_v)

    def game_over(self):
        self.stat = "menu"
开发者ID:sherlockkenan,项目名称:Tetris,代码行数:104,代码来源:tetris.py


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