public void GetRandomFleeNode() { Game game = new Game(5, 2, 20, 100); Pack pack = new Pack("999", 1, game.dungeon.startNode, game.dungeon); game.dungeon.graph[5].packs.Add(pack); pack.dungeon = game.dungeon; pack.startingHP = 10000; foreach (Monster member in pack.members.ToList()) { member.HP = 1; } Node randomNode = pack.getRandomValidNeighbour(game.dungeon); Assert.IsTrue(pack.location.id != randomNode.id && pack.location.neighbors.Contains(randomNode)); }
/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player, Dungeon dungeon) { //select pack Pack randomPack = packs.GetRandomItem(); //calc pack HP int currentHP = 0; foreach (Monster member in randomPack.members.ToList()) { currentHP += member.HP; } float fleeProbability = (1 - (float)currentHP / (float)randomPack.startingHP) / 2 * 100; //Console.WriteLine(fleeProbability); //%%%%%%%%%%% Pack Turn %%%%%%%%%%% if (fleeProbability > (float)RandomGenerator.rnd.Next(0, 100)) { //the pack flees Node randomNeighbor = randomPack.getRandomValidNeighbour(dungeon); if (randomNeighbor != null) { Console.WriteLine("Pack {0} flees.", randomPack.id); randomPack.move(randomNeighbor, player.location); if (this.packs.Count == 0) { contested = false; return; } randomPack = packs.GetRandomItem(); } } //pack attack randomPack.Attack(player); player.location.contested = player.location.packs.Count > 0 && player.HP > 0; }