本文整理汇总了Python中tile.Tile.merged_from方法的典型用法代码示例。如果您正苦于以下问题:Python Tile.merged_from方法的具体用法?Python Tile.merged_from怎么用?Python Tile.merged_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tile.Tile
的用法示例。
在下文中一共展示了Tile.merged_from方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from tile import Tile [as 别名]
# 或者: from tile.Tile import merged_from [as 别名]
def move(self, direction):
if self.over:
return
vector = GameManager.get_vector(direction)
traversals = self.build_traversals(vector)
moved = False
self.prepare_tiles()
for x in traversals['x']:
for y in traversals['y']:
cell = Vector(x, y)
tile = self.grid.cell_content(cell)
if tile:
positions = self.find_farther_position(cell, vector)
next_tile = self.grid.cell_content(positions['next'])
if (next_tile and next_tile.value == tile.value and
not next_tile.merged_from):
merged = Tile(positions['next'], tile.value * 2)
merged.merged_from = [tile, next_tile]
self.logger.add_log('+ merge {} and {}'.format(tile, next_tile))
self.grid.insert_tile(merged)
self.grid.remove_tile(tile)
tile.update_pos(positions['next'])
self.score += merged.value
if merged.value == 2048:
self.won = True
else:
self.move_tile(tile, positions['farthest'])
if cell != tile.pos:
moved = True
if moved:
self.add_random_tile()
if not self.move_available():
self.over = True