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


Python Vehicle.detach方法代碼示例

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


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

示例1: BaseVehicleTests

# 需要導入模塊: from vehicle import Vehicle [as 別名]
# 或者: from vehicle.Vehicle import detach [as 別名]
class BaseVehicleTests(unittest.TestCase):

    def setUp(self):
        self.sprites = tmx.layers.SpriteLayer()
        self.items = tmx.layers.SpriteLayer()
        self.v = Vehicle((10, 10), self.items, self.sprites)
        self.n = NormalVehicle((10, 10), self.items, self.sprites)
        self.component = VehicleComponent('motions')

    def test_defaults(self):
        self.assertIsInstance(self.vehicle.DEFAULTS, dict)

    def test_component_could_be_attach(self):
        self.assertIsNone(self.v._slots['motions'].get(0, None))
        self.v.attach(VehicleComponent('motions'), 0)
        self.assertIsNotNone(self.v._slots['motions'].get(0, None))

    def test_try_to_attach_on_existing_slot(self):
        attached_component = self.v.attach(self.component, 0)
        second_component = VehicleComponent('motions')
        self.v.attach(second_component, 0)
        self.assertIs(self.v._slots[self.component.group][0], attached_component)
        self.assertIsNot(self.v._slots['motions'][0], second_component)

    def test_try_to_attach_on_existing_slot_using_overwrite(self):
        attached_component = self.v.attach(self.component, 0)
        second_component = VehicleComponent('motions')
        self.v.attach(second_component, 0, overwrite=True)
        self.assertIsNot(self.v._slots[self.component.group][0], attached_component)
        self.assertIs(self.v._slots['motions'][0], second_component)

    def test_detach(self):
        self.v.attach(self.component, 0)
        self.v.detach(self.component, 0)
        self.assertIsNone(self.v._slots['motions'].get(0, None))

    def test_recalculation(self):
        self.assertEqual(self.v.weight, 0)
        self.v.attach(self.component, 0)
        self.assertGreater(self.v.weight, 0)

    def test_component_detach(self):
        self.vehicle.attach(self.component, 'front')
        self.assertEqual(len(self.vehicle._slots[self.component.group]), 1)
        self.vehicle.detach(self.component, 'front')
        self.assertEqual(len(self.vehicle._slots[self.component.group]), 0)
開發者ID:gogoantov,項目名稱:asuras,代碼行數:48,代碼來源:vehicle.py


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