Example #1
0
class ResourceTestCase(unittest.TestCase):
    def setUp(self):
        self.creature = Creature(name="creature_1", player="player_1", level=1, position=Point(0, 0))
        self.resource = Resource(name="resource_1", gold_amount=100, gold_flux=10)

    def test_gather_success(self):
        gather_result = self.creature.gather(self.resource)

        self.assertEqual(GatherResult.SUCCESS, gather_result)
        self.assertGreater(self.creature.gold_carried, 0)

    def test_gather_full(self):
        self.creature.gold_carried = self.creature.max_gold_carried

        gather_result = self.creature.gather(self.resource)

        self.assertEqual(GatherResult.FULL, gather_result)
        self.assertEqual(self.creature.gold_carried, self.creature.max_gold_carried)

    def test_gather_capped(self):
        self.creature.gold_carried = self.creature.max_gold_carried - self.resource.gold_flux
        gather_result = self.creature.gather(self.resource)

        self.assertEqual(GatherResult.CAPPED, gather_result)
        self.assertEqual(self.creature.gold_carried, self.creature.max_gold_carried)

    def test_gather_depleted(self):
        self.resource.gold_amount = 0

        gather_result = self.creature.gather(self.resource)

        self.assertEqual(GatherResult.DEPLETED, gather_result)
        self.assertEqual(0, self.creature.gold_carried)
Example #2
0
    def test_move_creature_out_of_bounds(self):
        c = Creature(name='creature', player='red', position=Point(0, 0))
        self.world.insert_creature(c)

        self.assertFalse(self.world.move_creature(c, -1, 1))
        self.assertEqual(Point(0, 0), c.position)
        self.assertEqual(c, self.world.get_entity_at(0, 0))
Example #3
0
    def test_move_creature(self):
        c = Creature(name='creature', player='red', position=Point(0, 0))
        self.world.insert_creature(c)

        self.assertTrue(self.world.move_creature(c, 1, 1))
        self.assertEqual(Point(1, 1), c.position)
        self.assertEqual(c, self.world.get_entity_at(1, 1))
Example #4
0
    def test_insert_creature(self):
        c = Creature(name='creature', player='red', position=Point(0, 0))
        count = len(self.world.creatures)

        self.world.insert_creature(c)

        self.assertGreater(len(self.world.creatures), count)
        self.assertEqual(c, self.world.get_entity_at(c.position.x,
                                                     c.position.y))
        self.assertEqual(c, self.world.creatures[c.id])
Example #5
0
class CombatTestCase(unittest.TestCase):
    def setUp(self):
        self.attacker = Creature(name="attacker", player="player_1", level=1, position=Point(0, 0))
        self.defender = Creature(name="defender", player="player_2", level=1, position=Point(1, 0))

    def test_attack_hit(self):
        self.attacker.accuracy = 1.0
        self.defender.dodge = 0.0

        attack_result = self.attacker.attack(self.defender)

        self.assertEqual(AttackResult.HIT, attack_result)
        self.assertTrue(self.defender.life < self.defender.max_life)

    def test_attack_missed(self):
        self.attacker.accuracy = 0.0

        attack_result = self.attacker.attack(self.defender)

        self.assertEqual(AttackResult.MISS, attack_result)
        self.assertTrue(self.defender.life == self.defender.max_life)
Example #6
0
def generate_level(character: Character):
    # Build the tiles
    level = Level(
        name="The Beginning",
        depth=1,
        tiles="""
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
""",
        character=character,
    )
    level.save()

    # Add the character to this level
    character.current_level = level
    character.x = 5
    character.y = 5
    character.save()

    # Create a creature
    ctype = random.choice([c for c in CreatureType.objects.all()])
    c = Creature(
        current_level=level,
        x=0, y=0,
        type=ctype,
        current_hp=ctype.base_hp
    )
    c.save()

    return level
Example #7
0
 def setUp(self):
     self.creature = Creature(name="creature_1", player="player_1", level=1, position=Point(0, 0))
     self.resource = Resource(name="resource_1", gold_amount=100, gold_flux=10)
Example #8
0
 def setUp(self):
     self.attacker = Creature(name="attacker", player="player_1", level=1, position=Point(0, 0))
     self.defender = Creature(name="defender", player="player_2", level=1, position=Point(1, 0))