Beispiel #1
0
	def test_tile_returns_the_tile_at_the_units_position(self):
		tmap = TileMap(TileGrid(Size(10, 10)))
		u = DummyUnit()
		tmap.place_unit(u, Point(110, 110))
		tile = tmap.tile_grid.get_tile(Point(5, 5))
		tile.tile_id = "target tile"
		self.assertEqual(u.tile.tile_id, "target tile")
Beispiel #2
0
	def test_move_raises_an_exception_if_the_move_would_take_the_unit_out_of_bounds(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		u = DummyUnit()
		tmap.place_unit(u, Point(5, 5))
		with self.assertRaises(UnitException) as error_context:
			u.move(Vector(-5, -10))
		self.assertIn("out of bounds", error_context.exception.message)
Beispiel #3
0
	def test_move_raises_an_exception_if_the_move_would_take_the_unit_into_non_traversable_terrain(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		u = DummyUnit()
		tmap.place_unit(u, Point(5, 5))
		tmap.get_tile(Point(15, 5)).set_terrain(Water)
		with self.assertRaises(UnitException) as error_context:
			u.move(Vector(10, 0))
		self.assertIn("unit cannot traverse", error_context.exception.message)
	def test_place_unit_raises_an_exception_when_a_unit_is_placed_out_of_bounds(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		serf = Peasant()
		with self.assertRaises(TileMapException) as error_context:
			tmap.place_unit(serf, Point(200, 200))
		self.assertEqual(
			error_context.exception.message,
			'Units must be placed in bounds',
			)
	def test_get_units_returns_all_units_on_the_map(self):
		tmap = TileMap(TileGrid(Size(10, 10)))
		serf1 = Peasant()
		serf2 = Peasant()
		serf3 = Peasant()
		tmap.place_unit(serf1, Point(0, 0))
		tmap.place_unit(serf2, Point(100, 100))
		tmap.place_unit(serf3, Point(180, 180))
		units = tmap.get_units()
		self.assertEqual(3, len(units))
		self.assertIn(serf1, units)
		self.assertIn(serf2, units)
		self.assertIn(serf3, units)
Beispiel #6
0
	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_place_unit_puts_a_unit_into_the_unit_registry_and_sets_the_units_position(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		serf = Peasant()
		tmap.place_unit(serf, Point(100, 100))
		self.assertIn(serf.unit_id, tmap.unit_registry)
		self.assertEqual(serf.pt, Point(100, 100))
	def test_get_unit_at_position_returns_None_if_there_is_no_unit_near_the_given_point(self):  # noqa
		tmap = TileMap(TileGrid(Size(10, 10)))
		serf = Peasant()
		tmap.place_unit(serf, Point(100, 100))
		self.assertIsNone(tmap.get_unit_at_position(Point(50, 50)))
	def test_get_unit_at_position_finds_a_unit_near_to_the_given_point(self):
		tmap = TileMap(TileGrid(Size(10, 10)))
		serf = Peasant()
		tmap.place_unit(serf, Point(100, 100))
		self.assertIs(serf, tmap.get_unit_at_position(Point(95, 95)))
Beispiel #10
0
	def test_move_moves_a_unit_along_a_movement_vector(self):
		tmap = TileMap(TileGrid(Size(10, 10)))
		u = DummyUnit()
		tmap.place_unit(u, Point(55, 75))
		u.move(Vector(-5, 10))
		self.assertEqual(u.pt, Point(50, 85))