Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace GameCreatures.Models
- {
- public class Commander
- {
- private readonly List<Creature> army;
- private string name;
- public Commander(string name, List<Creature> army)
- {
- this.Name = name;
- this.army = army;
- if (army == null)
- {
- throw new ArgumentNullException("Please provide a value!");
- }
- }
- public string Name
- {
- get
- {
- return this.name;
- }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException("Please provida a name!");
- }
- else
- {
- this.name = value;
- }
- }
- }
- public int ArmySize
- {
- get
- {
- return this.army.Count();
- }
- }
- 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)
- {
- List<Creature> attachers = new List<Creature>();
- if (enemy.army.Count != 1)
- {
- attachers = this.army.OrderByDescending(a => a.CalculateActualDamage(a.FindBestTarget(enemy.army))).ToList();
- attachers[0].AutoAttack(enemy.army);
- }
- else
- {
- attachers = this.army.OrderByDescending(a => a.CalculateActualDamage(enemy.army[0])).ToList();
- attachers[0].Attack(enemy.army[0]);
- if (enemy.army[0].HealthPoints <= 0)
- {
- enemy.army.Remove(enemy.army[0]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment