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


Python Grid.copy_content_into方法代码示例

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


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

示例1: add_block

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import copy_content_into [as 别名]
 def add_block(self, block, pos = (5, 0), grid = None, settling = False):
     '''places a Block object into a Grid object'''
     if self.block == None:
         print 'adding block', block.shape
     temp = Grid(self.width, self.height)
     if grid == None:
         grid = self.grid
         
     grid.copy_content_into(temp)
     self.block = block
     self.block.pos = pos
     for y in range(pos[1], pos[1] + self.block.size[1]):
         for x in range(pos[0], pos[0] + self.block.size[0]):
             if self.block.grid[y - pos[1]][x - pos[0]] > 0:
                 if settling and temp.content[y][x] == 10:
                     pygame.event.post(pygame.event.Event(GAME_OVER))
                 temp.content[y][x] = self.block.grid[y - pos[1]][x - pos[0]]
     temp.copy_content_into(grid)
开发者ID:john2x,项目名称:tetrys,代码行数:20,代码来源:Map.py

示例2: Map

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import copy_content_into [as 别名]
class Map():
    LEFT = -2
    RIGHT = 2
    DOWN = 1
    UP = -1
    
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.block = None
        
        self.grid = Grid(width, height)
        self.__add_borders(self.grid)
        self.background = Grid(width, height)
        self.grid.copy_content_into(self.background)

    def add_block(self, block, pos = (5, 0), grid = None, settling = False):
        '''places a Block object into a Grid object'''
        if self.block == None:
            print 'adding block', block.shape
        temp = Grid(self.width, self.height)
        if grid == None:
            grid = self.grid
            
        grid.copy_content_into(temp)
        self.block = block
        self.block.pos = pos
        for y in range(pos[1], pos[1] + self.block.size[1]):
            for x in range(pos[0], pos[0] + self.block.size[0]):
                if self.block.grid[y - pos[1]][x - pos[0]] > 0:
                    if settling and temp.content[y][x] == 10:
                        pygame.event.post(pygame.event.Event(GAME_OVER))
                    temp.content[y][x] = self.block.grid[y - pos[1]][x - pos[0]]
        temp.copy_content_into(grid)
        
    def move_current_block(self, direction):
        '''moves Block at direction'''
        ok = 0
        if self.block != None:
            if direction == Map.DOWN:
                #check if move is valid
                ok = self.__check_move(self.block, (self.block.pos[0], self.block.pos[1] + 1))
                if ok == 1:
                    self.background.copy_content_into(self.grid)
                    self.block.pos = (self.block.pos[0], self.block.pos[1] + 1)
                    self.add_block(self.block, self.block.pos, self.grid)
                else:
                    print 'not ok to move (DOWN)'
                    if ok == HIT_BLOCK or ok == HIT_FLOOR:
                        pygame.event.post(pygame.event.Event(ok))
                    
            elif direction == Map.RIGHT:
                ok = self.__check_move(self.block, (self.block.pos[0] + 1, self.block.pos[1]))
                if ok == 1:
                    self.background.copy_content_into(self.grid)
                    self.block.pos = (self.block.pos[0] + 1, self.block.pos[1])
                    self.add_block(self.block, self.block.pos, self.grid)
                else:
                    print 'not ok to move (RIGHT)'
            elif direction == Map.LEFT:
                ok = self.__check_move(self.block, (self.block.pos[0] - 1, self.block.pos[1]))
                if ok == 1:
                    self.background.copy_content_into(self.grid)
                    self.block.pos = (self.block.pos[0] - 1, self.block.pos[1])
                    self.add_block(self.block, self.block.pos, self.grid)
                else:
                    print 'not ok to move (LEFT)'
            elif direction == Map.UP:
                rotation = self.block.rotation
                self.block.rotate()
                ok = self.__check_move(self.block, self.block.pos)
                if ok == 1:
                    print 'rotating'
                    self.background.copy_content_into(self.grid)
                    self.add_block(self.block, self.block.pos, self.grid)
                else:
                    self.block.rotate(rotation)
                    print 'not ok to rotate (ROTATE)'
        else:
            print 'NO BLOCK'
    
    def settle_block(self):
        #@todo: just add the block into background, instead of copying grid into background
        self.add_block(self.block, self.block.pos, self.background, True)
        self.block = None
        #check if a block row is completed
        rows_to_collapse = self.check_grid(self.background)
        
        if len(rows_to_collapse) > 0:
            print rows_to_collapse
            self.collapse_rows(self.background, rows_to_collapse)
            
    def collapse_rows(self, grid, rows):
        j = 0
        for i in rows:
            for y in range(i + j, 3, -1):
                grid.content[y] = grid.get_row(y - 1)
            j += 1
        pygame.event.post(pygame.event.Event(ROW_COLLAPSED))    
    
#.........这里部分代码省略.........
开发者ID:john2x,项目名称:tetrys,代码行数:103,代码来源:Map.py


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