Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using System.Windows.Input;
  8. namespace Digger
  9. {
  10. class Terrain : ICreature
  11. {
  12. public CreatureCommand Act(int x, int y)
  13. {
  14. var nothing = new CreatureCommand();
  15. return nothing;
  16. }
  17.  
  18. public bool DeadInConflict(ICreature conflictedObject)
  19. {
  20. return true;
  21. }
  22.  
  23. public int GetDrawingPriority()
  24. {
  25. return 0;
  26. }
  27.  
  28. public string GetImageFileName()
  29. {
  30. return "Terrain.png";
  31. }
  32. }
  33.  
  34. class Player : ICreature
  35. {
  36. public CreatureCommand Act(int x, int y)
  37. {
  38. var command = new CreatureCommand();
  39. switch (Game.KeyPressed)
  40. {
  41. case Keys.Up: command.DeltaY--; break;
  42. case Keys.Down: command.DeltaY++; break;
  43. case Keys.Left: command.DeltaX--; break;
  44. case Keys.Right: command.DeltaX++; break;
  45. }
  46. var newX = x + command.DeltaX;
  47. var newY = y + command.DeltaY;
  48. if (newX < 0 || newX >= Game.MapWidth || newY < 0 || newY >= Game.MapHeight
  49. || Game.Map[newX, newY] is Sack)
  50. return new CreatureCommand();
  51. return command;
  52. }
  53.  
  54. public bool DeadInConflict(ICreature conflictedObject)
  55. {
  56. if (conflictedObject is Sack)
  57. {
  58. Sack sack = (Sack)conflictedObject;
  59. return sack.AmountBlocks > 0;
  60. }
  61. if (conflictedObject is Monster)
  62. return true;
  63. else
  64. return false;
  65. }
  66.  
  67. public int GetDrawingPriority()
  68. {
  69. return 0;
  70. }
  71.  
  72. public string GetImageFileName()
  73. {
  74. return "Digger.png";
  75. }
  76. }
  77.  
  78. class Monster : ICreature
  79. {
  80. public int[] SearchPlayer()
  81. {
  82. for (int x = 0; x < Game.MapHeight; x++)
  83. for (int y = 0; y < Game.MapWidth; y++)
  84. if (Game.Map[x, y] is Player)
  85. return new int[2] { x, y };
  86. return null;
  87. }
  88.  
  89. public CreatureCommand Act(int x, int y)
  90. {
  91. var PlayerLocation = SearchPlayer();
  92.  
  93. var monster = new CreatureCommand();
  94. if (PlayerLocation == null)
  95. return new CreatureCommand();
  96.  
  97. var command = new CreatureCommand();
  98. var deltaX = PlayerLocation[0] == x ? 0 : (PlayerLocation[0] - x) / Math.Abs(PlayerLocation[0] - x);
  99. var deltaY = PlayerLocation[1] == y ? 0 : (PlayerLocation[1] - y) / Math.Abs(PlayerLocation[1] - y);
  100. var newX = x + deltaX;
  101. var newY = y + deltaY;
  102. if (Game.Map[newX, y] is null || Game.Map[newX, y] is Player || Game.Map[newX, y] is Gold)
  103. command.DeltaX += deltaX;
  104. else if (Game.Map[x, newY] is null || Game.Map[x, newY] is Player || Game.Map[x, newY] is Gold)
  105. command.DeltaY += deltaY;
  106. return command;
  107.  
  108. }
  109.  
  110. public bool DeadInConflict(ICreature conflictedObject)
  111. => conflictedObject is Sack || conflictedObject is Monster;
  112.  
  113. public int GetDrawingPriority()
  114. {
  115. return 0;
  116. }
  117.  
  118. public string GetImageFileName()
  119. {
  120. return "Monster.png";
  121. }
  122.  
  123. }
  124.  
  125. class Sack : ICreature
  126. {
  127. public int AmountBlocks = 0;
  128.  
  129. public CreatureCommand Act(int x, int y)
  130. {
  131. var command = new CreatureCommand();
  132. if (y++ < Game.MapHeight - 1 && (Game.Map[x, y] is null || AmountBlocks > 0
  133. && (Game.Map[x, y] is Monster || Game.Map[x, y] is Player)))
  134. {
  135. AmountBlocks++;
  136. command.DeltaY++;
  137. }
  138. else
  139. {
  140. if (AmountBlocks > 1)
  141. command.TransformTo = new Gold();
  142. AmountBlocks = 0;
  143. }
  144. return command;
  145. }
  146.  
  147. public bool DeadInConflict(ICreature conflictedObject)
  148. {
  149. if (conflictedObject is Player)
  150. if (AmountBlocks > 0)
  151. conflictedObject.DeadInConflict(this);
  152.  
  153. return false;
  154. }
  155.  
  156. public int GetDrawingPriority()
  157. {
  158. return 1;
  159. }
  160.  
  161. public string GetImageFileName()
  162. {
  163. return "Sack.png";
  164. }
  165. }
  166.  
  167. class Gold : ICreature
  168. {
  169. public CreatureCommand Act(int x, int y)
  170. {
  171. return new CreatureCommand();
  172. }
  173.  
  174. public bool DeadInConflict(ICreature conflictedObject)
  175. {
  176. if (conflictedObject is Player)
  177. {
  178. Game.Scores += 10;
  179. return true;
  180. }
  181. if (conflictedObject is Monster)
  182. return true;
  183.  
  184. else
  185. return false;
  186. }
  187.  
  188. public int GetDrawingPriority()
  189. {
  190. return 0;
  191. }
  192.  
  193. public string GetImageFileName()
  194. {
  195. return "Gold.png";
  196. }
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement