public void XTest_pack_attack() { Player player = new Player("player"); Pack pack = new Pack("pack", 6); pack.Attack(player); Assert.True(player.HP == 4); pack.Attack(player); Assert.True(player.HP == 0); }
public void MStest_kill_player() { Player pl = new Player(); Pack pa = new Pack("pid", 200); pa.Attack(pl); Assert.IsTrue(pl.HP == 0); //failure would leave pl.HP at -100 }
public void MStest_attack_player() { Player pl = new Player(); Pack pa = new Pack("pid", 3); pa.Attack(pl); Assert.IsTrue(pl.HP == pl.HPbase - 3); }
public void MSTest_pack_attack_stop() { Pack pack = new Pack("M'Baku", 110); Player player = new Player(); pack.Attack(player); Assert.AreEqual(player.HP, 0); }
public void NTest_attack_playerDies() { Dungeon dungeon = new Dungeon(3, 4); Player player = new Player(); player.HP = 1; Pack pack = new Pack("1", 4, dungeon); pack.Attack(player); Assert.AreEqual(player.HP, 0); }
public void MSTest_pack_attack() { Pack pack = new Pack("Destroyer", 20); Player player = new Player(); uint attr = pack.members[0].AttackRating; attr *= 20; pack.Attack(player); Assert.AreEqual(player.HP, (player.HPbase - attr)); }
public void NTest_attack_playerAlive() { Dungeon dungeon = new Dungeon(3, 4); Player player = new Player(); Pack pack = new Pack("1", 1, dungeon); uint monsterAttackRating = pack.members.First().AttackRating; player.HP = (int)(monsterAttackRating + 5); pack.Attack(player); Assert.AreNotEqual(player.HP, 0); }
/* 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) { if (packs.Count == 0 || player == null) { return; } // calculate flee probability Pack pack = packs[0]; int currentHP = pack.currentTotalHP(); float probability = (1f - currentHP / pack.startingHP) / 2f; float percentage = probability * 100; float randomNr = RandomGenerator.rnd.Next(0, 101); // pack attempts to flee if (randomNr <= percentage) { // move to first node which is not overpopulated foreach (Node n in neighbors) { // calculate max capacity uint capacity = pack.dungeon.M * (pack.dungeon.level(n) + 1); // calculate current population in node int population = 0; foreach (Pack p in n.packs) { population += p.members.Count; } // move to node if pack fits in it and pack remains in its own zone (level) if (population + pack.members.Count <= capacity && pack.dungeon.level(pack.location) == pack.dungeon.level(n)) { pack.move(n); break; } } } // pack attacks player else { pack.Attack(player); } }
/* 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; }
/* 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, int seed, bool withSeed) //now runs a single enemy turn { if (withSeed) { RandomGenerator.initializeWithSeed(seed); } rnd = RandomGenerator.rnd; /*Possibly to do: * - Attack after failed flee attempt? (currently present)*/ //throw new NotImplementedException(); //still missing node contest check Pack attackPack = packs[rnd.Next(packs.Count - 1)]; double fleeCheck = rnd.NextDouble(); double packHP = attackPack.CurrentHP(); double fleeTreshold = (1 - (packHP / attackPack.startingHP)) / 2; if (fleeCheck <= fleeTreshold) { Logger.log("A pack tries to flee"); foreach (Node n in attackPack.location.neighbors) { attackPack.move(n); if (n.packs.Contains(attackPack)) { Logger.log("A pack flees!"); packs.Remove(attackPack); if (contested(player)) { attackPack = packs[rnd.Next(packs.Count - 1)]; } break; } } } if (contested(player)) { attackPack.Attack(player); } }
/* 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. */ /* * Command List: * 1- Move to next node,flee * 2- Use Magic Crystal * 3- Use Healing Potion * 4- Attack */ public int fight(Player player, int state) { int command = -1; if (state == 0) { //ensure player is not accelerated player.accelerated = false; Logger.log("Press 1 to flee"); if (player.containsMagicCrystal())//if player bag contains item type of magic crystal { Logger.log("Press 2 to use Magic Crystal"); } if (player.containsHealingPotion()) //only show option if player has the potion { Logger.log("Press 3 to use Healing Potion"); } Logger.log("Press 4 to attack"); command = player.getNextCommand().commandId; if (command == 1) { //if presses 1 try to flee //if possible game.state = 5 //if not game.state = 0 if (player.flee()) { Logger.log("Player fleed, not contested anymore"); return(5); //next state 5 } else { Logger.log("Player could not flee, still contested"); return(0); } } else if (command == 2) //player wants to use magic crystal { if (!player.containsMagicCrystal()) //if player has no magic crystal { Logger.log("Player has no magic crystal, press a valid command"); return(0); } //player uses magic crystal foreach (Item i in player.bag) { if (i.GetType() == typeof(Crystal)) //find magic crystal in player's bag { player.use(i); Logger.log("Player used crystal"); break; //break the for loop } Logger.log("Could not be able to execute this"); } return(2); //pass to 2nd state } else if (command == 3) //player wants to use healing potion { if (!player.containsHealingPotion()) //if player has no healing potion { Logger.log("Player has no healing potion, press a valid command"); return(0); } foreach (Item i in player.bag) //else find healing potion in player's bag { if (i.GetType() == typeof(HealingPotion)) { player.use(i); //use that potion Logger.log("Player used potion"); break; //break the for loop } } //player uses healing potion return(1); } else if (command == 4) //player chooses to attack { //player attacks Logger.log("Player is attacking"); //player attacks only one pack in the node bool removePack = player.AttackBool(player.location.packs.First().members.First()); //attackBool function returns true if that pack is killed and should be removed from the node if (removePack) { player.location.packs.Remove(player.location.packs.First()); //if every monster died in the pack //it gets removed from the node } if (player.location.packs.Count > 0) //if the node is still constested { return(3); //go to state 3 } else { //if the node is not contested anymore return(6); //go to state 6 } } } else if (state == 1) //if combat is at state 1 { //player is not accelerated and //there is no other option than player attack Logger.log("Player is not accelerated, player is attacking a monster in a pack"); bool removePack = player.AttackBool(player.location.packs.First().members.FirstOrDefault()); //player attacks one monster in one pack //call attack function and check if attacked pack should be removed if (removePack) { player.location.packs.Remove(player.location.packs.First()); } if (player.location.packs.Count > 0) //still contested { return(3); //go to state 3 } else { return(6); //node is not contested anymore } } else if (state == 2) //if combat is at state 2 { //player is accelerated and //there is no other option than player attack Logger.log("Player is accelerated, player is attacking all monsters in a pack"); bool removePack = player.AttackBool(player.location.packs.First().members.FirstOrDefault()); //accelerated check is inside the function //call attack function and check if attacked pack should be removed if (removePack) //if all monsters in the pack die { player.location.packs.Remove(player.location.packs.First()); //remove that pack from the location } if (player.location.packs.Count > 0) { return(3); //still contested } else { return(6); //not contested anymore } } else if (state == 3) //if the combat is at state 3 { Logger.log("Pack flees or attacks"); Pack pack = player.location.packs.First(); if (pack.getAction() == 1) //pack attacks { Logger.log("Pack attacks"); pack.Attack(player); //pack attacks to player return(0); } else if (pack.getAction() == 2) { //pack flees if (pack.flee()) //if pack can flee { Logger.log("Pack flees"); if (player.location.packs.Count > 0) //if the node is still contested { return(4); //go to state 4 } else { return(6); //node is not contested anymore } } else { //if pack can not flee it attacks Logger.log("Pack tried to flee, not possible. Pack attacks"); pack.Attack(player); return(0); } } //if flee probability> attack //pack flees //if still contested //game.state= 4 //if not contested //game.state = 6 //else pack attacks //game.state=0 } else if (state == 4) //if combat state is 4 { Logger.log("Pack attacks"); player.location.packs.First().Attack(player); //first pack in the node attacks player //TO-DO randomly decide the pack return(0); //if player is still alive checked in main while } /*else if (state == 5) //if combat state is 5 * { * Logger.log("Player successfully fleed, not contested anymore"); * return -1; * //return -1; //exit * } * else if (state == 6) * { * Logger.log("Node is not contested anymore"); * return -1; * //return -1; //exit * * }*/ else { //it does not call the function with state 5 or 6 //since the node is not contested anymore, it does not enter while loop again //this part is not executed only put for guarantee. Logger.log("Combat ends"); } return(-1); }