Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. using System;
  2.  
  3. enum Fractions
  4. {
  5. HUMAN,
  6. ELVEN,
  7. ORC,
  8. UNDEAD,
  9. DWARVE,
  10. GOBLIN
  11. }
  12.  
  13. struct Position2D
  14. {
  15. public float x;
  16. public float y;
  17. };
  18.  
  19. class Unit
  20. {
  21. protected const string type = "Unit";
  22. protected Position2D position;
  23. protected static Fractions fraction;
  24. protected double speed;
  25. protected int damage;
  26. protected int currentHp;
  27.  
  28. protected int MaxHp { get; set; }
  29.  
  30. protected double Speed
  31. {
  32. get { return speed; }
  33. set
  34. {
  35. if (value < 0)
  36. speed = 0;
  37. else
  38. speed = value;
  39. }
  40. }
  41.  
  42. protected int Damage
  43. {
  44. get { return damage; }
  45. set
  46. {
  47. if (value < 0)
  48. damage = 0;
  49. else
  50. damage = value;
  51. }
  52. }
  53.  
  54. protected int CurrentHp
  55. {
  56. get { return currentHp; }
  57. set
  58. {
  59. if (value >= MaxHp)
  60. currentHp = MaxHp;
  61. else
  62. currentHp = value;
  63. }
  64. }
  65.  
  66. public virtual void die()
  67. {
  68. Console.WriteLine("Woops...");
  69. }
  70.  
  71. public virtual void attack(Unit unit)
  72. {
  73. Console.WriteLine("Boom...");
  74. }
  75.  
  76. public virtual void move(Position2D pos)
  77. {
  78. this.position = pos;
  79. }
  80.  
  81. public void takeDamage(int dmg)
  82. {
  83. this.CurrentHp -= dmg;
  84. }
  85. public Unit(){
  86. position.x = 0;
  87. position.y = 0;
  88. Damage = 10;
  89. MaxHp = 100;
  90. CurrentHp = MaxHp;
  91. Speed = 1.0;
  92. }
  93. public Unit (int damage, int maxhp, double speed)
  94. {
  95. position.x = 0;
  96. position.y = 0;
  97. Damage = damage;
  98. MaxHp = maxhp;
  99. CurrentHp = MaxHp;
  100. Speed = speed;
  101. }
  102. };
  103.  
  104. class Friendly : Unit
  105. {
  106. protected bool hostile;
  107. protected int confidence;
  108. protected int Confidence
  109. {
  110. get { return confidence; }
  111. set
  112. {
  113. if (value < 30)
  114. {
  115. if (value < 0)
  116. confidence = 0;
  117. hostile = true;
  118. }
  119. else
  120. {
  121. if (value > 100)
  122. confidence = 100;
  123. else
  124. confidence = value;
  125. hostile = false;
  126. }
  127. }
  128. }
  129. };
  130.  
  131. class Enemy : Unit
  132. {
  133. public void say(string msg)
  134. {
  135. Console.WriteLine($"Enemy {type} from fraction {fraction} says: {msg}");
  136. }
  137. };
  138.  
  139. class Swordman : Friendly
  140. {
  141. public override void attack(Unit unit)
  142. {
  143. Console.WriteLine($"{type} wordman from fraction {fraction} damaged in {damage} hp");
  144. unit.takeDamage(damage);
  145. }
  146. static Swordman()
  147. {
  148. fraction = Fractions.HUMAN;
  149. }
  150. public Swordman()
  151. {
  152. this.MaxHp = 300;
  153. this.Damage = 20;
  154. this.CurrentHp = this.MaxHp;
  155. this.position.x = 0;
  156. this.position.y = 0;
  157. this.Confidence = 50;
  158. this.speed = 2.4;
  159. }
  160. public Swordman(int damage, int maxhp, double speed)
  161. {
  162. this.MaxHp = maxhp;
  163. this.Damage = damage;
  164. this.CurrentHp = this.MaxHp;
  165. this.position.x = 0;
  166. this.position.y = 0;
  167. this.Confidence = 50;
  168. this.Speed = speed;
  169. }
  170. };
  171.  
  172. class Skeleton : Enemy
  173. {
  174. public override void attack(Unit unit)
  175. {
  176. Random rnd = new Random();
  177. int dmg = this.Damage;
  178. int chance = rnd.Next(1, 100);
  179. if (chance <= 30)
  180. {
  181. dmg *= 2;
  182. }
  183. Console.WriteLine($"Skeleton from fraction {fraction} damaged your ally in {dmg} hp");
  184. unit.takeDamage(dmg);
  185. }
  186. static Skeleton()
  187. {
  188. fraction = Fractions.UNDEAD;
  189. }
  190. public Skeleton()
  191. {
  192. this.MaxHp = 100;
  193. this.Damage = 12;
  194. this.CurrentHp = this.MaxHp;
  195. this.position.x = 0;
  196. this.position.y = 0;
  197. this.speed = 1.8;
  198. }
  199. };
  200.  
  201. namespace lab1
  202. {
  203. class Program
  204. {
  205. static void Main(string[] args)
  206. {
  207.  
  208. }
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement