本文整理汇总了Python中tile.Tile.mergedFrom方法的典型用法代码示例。如果您正苦于以下问题:Python Tile.mergedFrom方法的具体用法?Python Tile.mergedFrom怎么用?Python Tile.mergedFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tile.Tile
的用法示例。
在下文中一共展示了Tile.mergedFrom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from tile import Tile [as 别名]
# 或者: from tile.Tile import mergedFrom [as 别名]
def move(self, direction):
if self.won or self.over:
return
cell = None
tile = None
vector = self.vectorMap(direction)
traversals = self.buildTraverals(vector)
moved = False
self.prepareTiles()
for x in traversals['x']:
for y in traversals['y']:
cell = (x,y)
tile = self.grid.cellContent(cell)
if(tile != None):
positions = self.findFarthestPosition(cell,vector)
next = self.grid.cellContent(positions['next'])
if(next != None and next.value == tile.value and next.mergedFrom == None):
merged = Tile(positions['next'], tile.value*2)
merged.mergedFrom = [tile, next]
self.grid.insertTile(merged)
self.grid.removeTile(tile)
tile.updatePosition(positions['next'])
self.score += merged.value
if (merged.value == self.win_score):
sleep(10)
self.won = True
else:
self.moveTile(tile, positions['farthest'])
if (not self.positionsEqual(cell, tile)):
moved = True
if moved:
self.addRandomTile()
if not self.movesAvalable():
self.over = True
self.actuate()