/// <summary> /// Calculates the battle between <paramref name="yourCreatures"/> and <paramref name="opponentsCreatures"/> and /// returns the the result as a <see cref="BattleResult"/>. /// </summary> public static BattleResult CalculateBattle(List<Creature> yourCreatures, List<Creature> opponentsCreatures) { if (opponentsCreatures.Count > yourCreatures.Count) throw new ArgumentException("You do not have enough creatures!"); BattleResult battleResult = new BattleResult(); for (int duelIndex = 0; duelIndex < opponentsCreatures.Count; duelIndex++) { Creature opponent = new Creature(opponentsCreatures[duelIndex]); Creature you = new Creature(yourCreatures[duelIndex]); DuelResult duel = new DuelResult(); AddEnchantmentEffects(you, opponent); AddEnchantmentEffects(opponent, you); AddItemEffectsBeforeBattle(you, opponent, yourCreatures, opponentsCreatures); AddItemEffectsBeforeBattle(opponent, you, opponentsCreatures, yourCreatures); while (you.Health > 0 && opponent.Health > 0) { int opponentDamage = GetDamage(opponent, you); int yourDamage = GetDamage(you, opponent); you.Health -= opponentDamage; opponent.Health -= yourDamage; AddItemEffectsBeforeTurn(you, opponent); AddItemEffectsBeforeTurn(opponent, you); if (you.Health < 0) you.Health = 0; if (opponent.Health < 0) opponent.Health = 0; duel.Result += String.Format( "Your {0} did {1} damage -> opponent's {2} has {3} health left." + Environment.NewLine + "Opponent's {2} did {4} damage -> your {0} has {5} health left." + Environment.NewLine, you.Name, yourDamage, opponent.Name, opponent.Health, opponentDamage, you.Health); } if (you.Health == 0 && opponent.Health == 0) { string outCome = String.Format("Your {0} killed your opponent's {1} but died in the process.", you.Name, opponent.Name); duel.Result += outCome; duel.ShortResult = outCome; duel.Outcome = DuelOutcome.Dip; } else if (you.Health > 0) { string outCome = String.Format("Your {0} killed your opponent's {1}.", you.Name, opponent.Name); duel.Result += outCome; duel.ShortResult = outCome; duel.Outcome = DuelOutcome.Won; } else { string outCome = String.Format("Your {0} got killed by your opponent's {1}.", you.Name, opponent.Name); duel.Result += outCome; duel.ShortResult = outCome; duel.Outcome = DuelOutcome.Lost; } battleResult.Add(duel); } return battleResult; }