本文整理汇总了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)
示例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))
#.........这里部分代码省略.........