Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace GameCreatures.Models
- {
- public class Commander
- {
- private readonly List<Creature> army;
- string name;
- public Commander()
- {
- }
- public Commander(string name, List<Creature> army)
- {
- if (army == null)
- {
- throw new ArgumentNullException();
- }
- if (name == null)
- {
- throw new ArgumentNullException();
- }
- this.name = name;
- this.army = army;
- }
- public string Name
- {
- get
- {
- return this.name;
- }
- }
- public int ArmySize
- {
- get
- {
- return this.army.Count;
- }
- }
- public List<Creature> Army
- {
- get
- {
- return this.army;
- }
- }
- public void AttackAtPosition(Commander enemy, int attackerIndex, int targetIndex)
- {
- this.army[attackerIndex].Attack(enemy.army[targetIndex]);
- if (enemy.army[targetIndex].HealthPoints == 0)
- {
- enemy.army.RemoveAt(targetIndex);
- }
- }
- public void AutoAttack(Commander enemy)
- {
- var creatureAttacker = this.army[0];
- var attackedCreature = enemy.army[0];
- int minHp = int.MaxValue;
- foreach (var attacker in this.army)
- {
- var creature = attacker.FindBestTarget(enemy.army);
- int currentMinHp = creature.HealthPoints - attacker.CalculateActualDamage(creature);
- if (currentMinHp < 0)
- {
- currentMinHp = 0;
- }
- if (currentMinHp < minHp)
- {
- minHp = currentMinHp;
- creatureAttacker = attacker;
- attackedCreature = creature;
- }
- if (currentMinHp == minHp)
- {
- if (creature.Damage > attackedCreature.Damage)
- {
- attackedCreature = creature;
- creatureAttacker = attacker;
- }
- }
- }
- creatureAttacker.Attack(attackedCreature);
- if (attackedCreature.HealthPoints == 0)
- {
- enemy.army.Remove(attackedCreature);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement