Пример #1
0
 def test_get_winning_faction(self):
     f1 = Faction('Goblins', [Goblin(), Goblin()])
     f2 = Faction('Orcs', [Orc(), Orc()])
     a = Arena([f1, f2])
     f1.get_entities()[0].state = EntityState.DEAD
     f1.get_entities()[1].state = EntityState.DEAD
     self.assertEqual(a.get_winning_faction(), f2)
Пример #2
0
 def test_get_opposing_factions(self):
     f1 = Faction('Goblins', [Goblin()])
     f2 = Faction('Orcs', [Orc()])
     f3 = Faction('More Bad Orcs', [Orc()])
     a = Arena([f1, f2, f3])
     opposing = a.get_opposing_factions(f1)
     self.assertNotIn(f1, opposing)
Пример #3
0
 def test_is_over(self):
     f1 = Faction('Goblins', [Goblin(), Goblin()])
     f2 = Faction('Orcs', [Orc(), Orc()])
     a = Arena([f1, f2])
     f1.get_entities()[0].state = EntityState.DEAD
     f1.get_entities()[1].state = EntityState.DEAD
     self.assertTrue(a.is_over())
Пример #4
0
 def test_death(self):
     s = Scimitar()
     o = Orc()
     with patch('game_engine.dice._random_int') as mock_roll:
         mock_roll.return_value = 100  # rolling 100 on a d6?  Anyway this will kill the orc
         s.roll_damage(o)
         self.assertTrue(o.get_cur_hp() < 1)
         self.assertEqual(o.get_state(), EntityState.DEAD)
Пример #5
0
 def test_roll_damage(self):
     s = Scimitar()
     o = Orc()
     with patch('game_engine.dice._random_int') as mock_roll:
         mock_roll.return_value = 3  # means 5 damage
         s.roll_damage(o)
         self.assertEqual(o.get_cur_hp(), o.get_hp() - 5)
         self.assertEqual(o.get_state(), EntityState.NORMAL)
Пример #6
0
 def test_critical_hit(self):
     s = Scimitar()
     o = Orc()
     # dice rolls for a critical hit and then max damage of 18
     set_values([20, 8, 8])
     with patch('game_engine.dice._random_int', side_effect=value):
         hit = s.roll_to_hit(o)
         s.roll_damage(o, hit)
         self.assertEqual(o.cur_hp, o.get_hp() - 18)
Пример #7
0
 def test_all_factions_dead(self):
     f1 = Faction('Goblins', [Goblin(), Goblin()])
     f2 = Faction('Orcs', [Orc(), Orc()])
     a = Arena([f1, f2])
     f1.get_entities()[0].state = EntityState.DEAD
     f1.get_entities()[1].state = EntityState.DEAD
     f2.get_entities()[0].state = EntityState.DEAD
     f2.get_entities()[1].state = EntityState.DEAD
     self.assertIsNone(a.get_winning_faction())
Пример #8
0
 def test_is_not_over(self):
     f1 = Faction('Goblins', [Goblin(), Goblin()])
     f2 = Faction('Orcs', [Orc(), Orc()])
     f3 = Faction('More Bad Orcs', [Orc(), Orc()])
     a = Arena([f1, f2, f3])
     # kill the first faction and then one from the other two
     f1.get_entities()[0].state = EntityState.DEAD
     f1.get_entities()[1].state = EntityState.DEAD
     f2.get_entities()[0].state = EntityState.DEAD
     f3.get_entities()[1].state = EntityState.DEAD
     self.assertFalse(a.is_over())
Пример #9
0
 def test_random_target(self):
     g = Goblin()
     o1 = Orc()
     o2 = Orc()
     o3 = Orc()
     goblins = Faction('Goblins', [g])
     orcs = Faction('Orcs', [o1, o2, o3])
     arena = Arena([goblins, orcs])
     # this is only for testing, need to set the arena on the goblin
     # normally this would happen via the take_turn method
     g.arena = arena
     g.select_target(TargetStrategy.RANDOM)
     self.assertTrue(g.target is not None)
     self.assertIn(g.target, [o1, o2, o3])
Пример #10
0
 def test_roll_to_hit_critical(self):
     s = Scimitar()
     o = Orc()
     with patch('game_engine.dice._random_int') as mock_roll:
         mock_roll.return_value = 20
         roll = s.roll_to_hit(o)
         self.assertEqual(roll, HitType.CRITICAL_HIT)
Пример #11
0
 def test_roll_to_hit(self):
     s = Scimitar()
     o = Orc()
     with patch('game_engine.dice._random_int') as mock_roll:
         mock_roll.return_value = 3
         roll = s.roll_to_hit(o)
         self.assertEqual(roll, HitType.MISS)
Пример #12
0
 def test_initiative(self):
     f1 = Faction('Goblins', [Goblin()])
     f2 = Faction('Orcs', [Orc()])
     a = Arena([f1, f2])
     with patch('game_engine.dice._random_int') as mock_roll:
         mock_roll.return_value = 10
         a.determine_initiative_order()
         self.assertIsInstance(a.get_init_order()[0], Goblin)
         self.assertIsInstance(a.get_init_order()[1], Orc)
Пример #13
0
 def test_goblin_vs_orc(self):
     # this means hp rolls, initiative rolls, to hit roll and damage rolls until one dead
     set_values([3, 3, 4, 4, 20, 10, 10, 3, 10, 8])
     with patch('game_engine.dice._random_int', side_effect=value):
         f1 = Faction('Goblins', [Goblin()])
         f2 = Faction('Orcs', [Orc()])
         game = Game([f1, f2])
         winner = game.play()
         self.assertEqual(winner.get_name(), 'Orcs')
Пример #14
0
 def test_create_arena(self):
     f1 = Faction('Goblins', [Goblin()])
     f2 = Faction('Orcs', [Orc()])
     a = Arena([f1, f2])
     self.assertIsNotNone(a)
Пример #15
0
 def test_miss_damage(self):
     s = Scimitar()
     o = Orc()
     s.roll_damage(o, HitType.MISS)
     self.assertEqual(o.get_cur_hp(), o.get_hp())
Пример #16
0
 def test_create_orc(self):
     o = Orc()
     self.assertIsNotNone(o)
Пример #17
0
 def test_no_winning_faction_yet(self):
     f1 = Faction('Goblins', [Goblin(), Goblin()])
     f2 = Faction('Orcs', [Orc(), Orc()])
     a = Arena([f1, f2])
     self.assertIsNone(a.get_winning_faction())
Пример #18
0
 def test_goblin_attack_orc(self):
     attacker = Goblin()
     target = Orc()
     set_values([13])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attacker.get_actions()[0], None), HitType.HIT)