當前位置: 首頁>>代碼示例>>Python>>正文


Python ComponentManager.get_Components方法代碼示例

本文整理匯總了Python中ComponentManager.ComponentManager.get_Components方法的典型用法代碼示例。如果您正苦於以下問題:Python ComponentManager.get_Components方法的具體用法?Python ComponentManager.get_Components怎麽用?Python ComponentManager.get_Components使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ComponentManager.ComponentManager的用法示例。


在下文中一共展示了ComponentManager.get_Components方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: take_turn

# 需要導入模塊: from ComponentManager import ComponentManager [as 別名]
# 或者: from ComponentManager.ComponentManager import get_Components [as 別名]
 def take_turn(self):
     elephantcreature = CM.get_Component('Creature', self.ElephantId)
     elephantcoord = CM.get_Component('Coord', self.ElephantId)
     elephanttile = CM.get_Component('Tile', self.ElephantId)
     playercoord = CM.get_Component('Coord', config.PlayerId)
     disttoplayer = hypot(elephantcoord.X - playercoord.X,
                          elephantcoord.Y - playercoord.Y)
     if disttoplayer < elephantcreature.VisionRange and \
             coordfov(elephantcoord, playercoord):
         if int(disttoplayer) <= 1:
             if not self.resting:
                 Attack_Coord(self.BasicAttackId, self.ElephantId,
                              playercoord)
                 self.resting = True
             else:
                 self.resting = False
                 Message('The ' + elephanttile.TileName +
                         ' rests this turn instead of attacking.',
                         color=Color.yellow)
         else:
             self.resting = False
             direction = MC.Get_Direction_To(elephantcoord, playercoord)
             if not MC.Walk_Direction(self.ElephantId, direction):
                 directions = MC.Get_Alt_Direction_To(direction)
                 if not MC.Walk_Direction(self.ElephantId, directions[0]):
                     MC.Walk_Direction(self.ElephantId, directions[1])
     else:
         tiles = CM.dict_of('Tile')
         elephantids = []
         for key, value in tiles.iteritems():
             if value.TileName == 'Elephant' or \
                     value.TileName == 'Pink Elephant':
                 if key != self.ElephantId:
                     elephantids.append(key)
         elephantcoords = CM.get_Components('Coord', elephantids)
         shortestdist = (False, elephantcreature.VisionRange)
         for key, coord in elephantcoords.iteritems():
             dist = hypot(
                 elephantcoord.X - coord.X, elephantcoord.Y - coord.Y)
             if dist < shortestdist[1] and dist > 1.5:
                 shortestdist = (coord, dist)
         if shortestdist[0]:
             direction = MC.Get_Direction_To(elephantcoord, shortestdist[0])
             if not MC.Walk_Direction(self.ElephantId, direction):
                 directions = MC.Get_Alt_Direction_To(direction)
                 if not MC.Walk_Direction(self.ElephantId, directions[0]):
                     MC.Walk_Direction(self.ElephantId, directions[1])
         else:
             direction = random.choice([D.N, D.S, D.E, D.W,
                                        D.NE, D.NW, D.SE, D.SW])
             MC.Walk_Direction(self.ElephantId, direction)
開發者ID:Akhier,項目名稱:12Down,代碼行數:53,代碼來源:Elephant.py

示例2: take_turn

# 需要導入模塊: from ComponentManager import ComponentManager [as 別名]
# 或者: from ComponentManager.ComponentManager import get_Components [as 別名]
 def take_turn(self):
     dogcreature = CM.get_Component('Creature', self.DogId)
     dogcoord = CM.get_Component('Coord', self.DogId)
     playercoord = CM.get_Component('Coord', config.PlayerId)
     disttoplayer = hypot(dogcoord.X - playercoord.X,
                          dogcoord.Y - playercoord.Y)
     if disttoplayer < dogcreature.VisionRange and \
             coordfov(dogcoord, playercoord):
         if int(disttoplayer) <= 1:
             Attack_Coord(self.BasicAttackId, self.DogId, playercoord)
         else:
             direction = MC.Get_Direction_To(dogcoord, playercoord)
             if not MC.Walk_Direction(self.DogId, direction):
                 directions = MC.Get_Alt_Direction_To(direction)
                 if not MC.Walk_Direction(self.DogId, directions[0]):
                     MC.Walk_Direction(self.DogId, directions[1])
     else:
         tiles = CM.dict_of('Tile')
         dogids = []
         for key, value in tiles.iteritems():
             if value.TileName == 'Dog' or \
                     value.TileName == 'Rabid Dog':
                 if key != self.DogId:
                     dogids.append(key)
         dogcoords = CM.get_Components('Coord', dogids)
         shortestdist = (False, dogcreature.VisionRange)
         for key, coord in dogcoords.iteritems():
             dist = hypot(dogcoord.X - coord.X, dogcoord.Y - coord.Y)
             if dist < shortestdist[1] and dist > 1.5:
                 shortestdist = (coord, dist)
         if shortestdist[0]:
             direction = MC.Get_Direction_To(dogcoord, shortestdist[0])
             if not MC.Walk_Direction(self.DogId, direction):
                 directions = MC.Get_Alt_Direction_To(direction)
                 if not MC.Walk_Direction(self.DogId, directions[0]):
                     MC.Walk_Direction(self.DogId, directions[1])
         else:
             direction = random.choice([D.N, D.S, D.E, D.W,
                                        D.NE, D.NW, D.SE, D.SW])
             MC.Walk_Direction(self.DogId, direction)
開發者ID:Akhier,項目名稱:12Down,代碼行數:42,代碼來源:Dog.py


注:本文中的ComponentManager.ComponentManager.get_Components方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。