nassss

Untitled

Jan 20th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace GameCreatures.Models
  6. {
  7. public class Commander
  8. {
  9. private readonly List<Creature> army;
  10. private string name;
  11.  
  12.  
  13. public Commander(string name, List<Creature> army)
  14. {
  15. this.Name = name;
  16. this.army = army;
  17. if (army == null)
  18. {
  19. throw new ArgumentNullException("Please provide a value!");
  20. }
  21. }
  22.  
  23. public string Name
  24. {
  25. get
  26. {
  27. return this.name;
  28. }
  29. set
  30. {
  31. if (value == null)
  32. {
  33. throw new ArgumentNullException("Please provida a name!");
  34. }
  35. else
  36. {
  37. this.name = value;
  38. }
  39. }
  40. }
  41.  
  42. public int ArmySize
  43. {
  44. get
  45. {
  46. return this.army.Count();
  47. }
  48.  
  49. }
  50.  
  51. public void AttackAtPosition(Commander enemy, int attackerIndex, int targetIndex)
  52. {
  53. this.army[attackerIndex].Attack(enemy.army[targetIndex]);
  54. if (enemy.army[targetIndex].HealthPoints <= 0)
  55. {
  56. enemy.army.RemoveAt(targetIndex);
  57. }
  58. }
  59.  
  60. public void AutoAttack(Commander enemy)
  61. {
  62. List<Creature> attachers = new List<Creature>();
  63.  
  64. if (enemy.army.Count != 1)
  65. {
  66.  
  67. attachers = this.army.OrderByDescending(a => a.CalculateActualDamage(a.FindBestTarget(enemy.army))).ToList();
  68. attachers[0].AutoAttack(enemy.army);
  69. }
  70. else
  71. {
  72. attachers = this.army.OrderByDescending(a => a.CalculateActualDamage(enemy.army[0])).ToList();
  73. attachers[0].Attack(enemy.army[0]);
  74. if (enemy.army[0].HealthPoints <= 0)
  75. {
  76. enemy.army.Remove(enemy.army[0]);
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment