Advertisement
dxeqtr

Untitled

Jan 15th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace GameCreatures.Models
  5. {
  6. public class Commander
  7. {
  8. private readonly List<Creature> army;
  9.  
  10. string name;
  11.  
  12. public Commander()
  13. {
  14.  
  15. }
  16. public Commander(string name, List<Creature> army)
  17. {
  18.  
  19. if (army == null)
  20. {
  21. throw new ArgumentNullException();
  22. }
  23. if (name == null)
  24. {
  25. throw new ArgumentNullException();
  26. }
  27. this.name = name;
  28. this.army = army;
  29. }
  30.  
  31. public string Name
  32. {
  33. get
  34. {
  35. return this.name;
  36. }
  37.  
  38. }
  39.  
  40. public int ArmySize
  41. {
  42. get
  43. {
  44. return this.army.Count;
  45. }
  46. }
  47.  
  48. public List<Creature> Army
  49. {
  50. get
  51. {
  52. return this.army;
  53. }
  54. }
  55.  
  56. public void AttackAtPosition(Commander enemy, int attackerIndex, int targetIndex)
  57. {
  58. this.army[attackerIndex].Attack(enemy.army[targetIndex]);
  59.  
  60. if (enemy.army[targetIndex].HealthPoints == 0)
  61. {
  62. enemy.army.RemoveAt(targetIndex);
  63. }
  64.  
  65.  
  66.  
  67. }
  68.  
  69. public void AutoAttack(Commander enemy)
  70. {
  71. var creatureAttacker = this.army[0];
  72. var attackedCreature = enemy.army[0];
  73.  
  74. int minHp = int.MaxValue;
  75.  
  76. foreach (var attacker in this.army)
  77. {
  78. var creature = attacker.FindBestTarget(enemy.army);
  79.  
  80. int currentMinHp = creature.HealthPoints - attacker.CalculateActualDamage(creature);
  81.  
  82. if (currentMinHp < 0)
  83. {
  84. currentMinHp = 0;
  85. }
  86.  
  87. if (currentMinHp < minHp)
  88. {
  89. minHp = currentMinHp;
  90.  
  91. creatureAttacker = attacker;
  92.  
  93. attackedCreature = creature;
  94. }
  95.  
  96. if (currentMinHp == minHp)
  97. {
  98. if (creature.Damage > attackedCreature.Damage)
  99. {
  100. attackedCreature = creature;
  101.  
  102. creatureAttacker = attacker;
  103. }
  104. }
  105. }
  106.  
  107. creatureAttacker.Attack(attackedCreature);
  108.  
  109. if (attackedCreature.HealthPoints == 0)
  110. {
  111. enemy.army.Remove(attackedCreature);
  112. }
  113. }
  114. }
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement