def test_build_unit_returns_None_if_there_are_not_enough_resources_to_produce_that_unit(self):  # noqa
		building = Building()
		serf_factory = Factory()
		serf_factory.add_resource_requirement(Cabbage, 10)
		serf_factory.product = Peasant
		building.add_unit_factory(serf_factory)
		self.assertIsNone(building.build_unit(Peasant))
	def test_add_building_factory_adds_a_factory_to_the_units_building_factories(self):  # noqa
		factory = Factory()
		factory.add_resource_requirement(DummyResource, 2)
		factory.set_product(DummyBuilding)
		u = DummyUnit()
		u.add_building_factory(factory)
		self.assertIs(u.building_factories[DummyBuilding.name], factory)
Exemple #3
0
	def __init__(self):
		super().__init__()
		dock_factory = Factory()
		dock_factory.add_resource_requirement(Wood, 15)
		dock_factory.set_product(Dock)
		self.add_building_factory(dock_factory)
		self.add_harvestable_resource(Fish)

		self.traversable_terrain_types.add(TerrainType.water)
	def test_construct_building_returns_a_new_instance_of_the_requested_building_if_the_unit_can_construct_it(self):  # noqa
		u = DummyUnit()
		factory = Factory()
		factory.add_resource_requirement(DummyResource, 2)
		factory.set_product(DummyBuilding)
		u.add_building_factory(factory)
		u.receive_cargo(DummyResource, 2)
		self.assertIsInstance(
			u.construct_building(DummyBuilding),
			DummyBuilding,
			)
	def test_build_unit_consumes_resources_to_produce_a_new_unit(self):
		building = Building()

		building.container.add_resource_slot(Cabbage, 10)
		building.receive_cargo(Cabbage, 10)

		serf_factory = Factory()
		serf_factory.add_resource_requirement(Cabbage, 10)
		serf_factory.product = Peasant
		building.add_unit_factory(serf_factory)

		serf = building.build_unit(Peasant)
		self.assertIsInstance(serf, Peasant)
	def test_can_construct_building_returns_true_if_and_only_if_the_unit_is_carrying_the_resources_and_has_a_factory_that_can_produce_the_requested_building_and_the_unit_is_placed_on_the_map(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		u = DummyUnit()
		tmap.place_unit(u, Point(0, 0))
		self.assertFalse(u.can_construct_building(DummyBuilding))

		factory = Factory()
		factory.add_resource_requirement(DummyResource, 2)
		factory.set_product(DummyBuilding)
		u.add_building_factory(factory)
		self.assertFalse(u.can_construct_building(DummyBuilding))

		u.receive_cargo(DummyResource, 2)
		self.assertTrue(u.can_construct_building(DummyBuilding))
	def test_add_building_factory_raises_an_exception_if_a_factory_producting_that_kind_of_building_has_already_been_added(self):  # noqa
		factory1 = Factory()
		factory1.add_resource_requirement(DummyResource, 2)
		factory1.set_product(DummyBuilding)
		factory2 = Factory()
		factory2.add_resource_requirement(DummyResource, 1)
		factory2.set_product(DummyBuilding)
		u = DummyUnit()

		u.add_building_factory(factory1)
		with self.assertRaises(UnitException) as error_context:
			u.add_building_factory(factory2)
		self.assertEqual(
			error_context.exception.message,
			"A factory for that building has already been added",
			)
Exemple #8
0
	def __init__(self):
		super().__init__()
		cabbage_farm_factory = Factory()
		cabbage_farm_factory.add_resource_requirement(Wood, 10)
		cabbage_farm_factory.set_product(CabbageFarm)
		self.add_building_factory(cabbage_farm_factory)
		self.add_harvestable_resource(Wood)
		self.add_carryable_resource(Wood)
		self.add_carryable_resource(Lumber)

		iron_mine_factory = Factory()
		iron_mine_factory.add_resource_requirement(Lumber, 10)
		iron_mine_factory.set_product(IronMine)
		self.add_building_factory(iron_mine_factory)

		self.traversable_terrain_types.add(TerrainType.land)
	def test_digest_consumes_required_resources_and_produces_a_new_instance_of_the_product_of_the_factory(self):  # noqa
		tray = SlottedCargoContainer()
		tray.add_resource_slot(Fish,    10)
		tray.add_resource_slot(Wood,    10)
		tray.add_resource_slot(Cabbage, 10)
		tray.load_cargo(Fish,    3)
		tray.load_cargo(Wood,    5)
		tray.load_cargo(Cabbage, 4)

		factory = Factory()
		factory.add_resource_requirement(Fish, 3)
		factory.add_resource_requirement(Wood, 2)
		factory.set_product(Cabbage)
		result = factory.digest(tray)

		self.assertEqual(tray.cargo_slots[Fish.name]['load'],    0)
		self.assertEqual(tray.cargo_slots[Wood.name]['load'],    3)
		self.assertIsInstance(result, Cabbage)