Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System.Windows.Forms;
  2.  
  3. namespace Digger
  4. {
  5. public class Terrain : ICreature
  6. {
  7. public static int DrawingPriority = 1;
  8.  
  9. string ICreature.GetImageFileName()
  10. {
  11. return "Terrain.png";
  12. }
  13.  
  14. int ICreature.GetDrawingPriority()
  15. {
  16. return DrawingPriority;
  17. }
  18.  
  19. CreatureCommand ICreature.Act(int x, int y)
  20. {
  21. return new CreatureCommand();
  22. }
  23.  
  24. bool ICreature.DeadInConflict(ICreature conflictedObject)
  25. {
  26. return false;
  27. }
  28. }
  29.  
  30. public class Player : ICreature
  31. {
  32. public static int DrawingPriority = 0;
  33.  
  34. CreatureCommand ICreature.Act(int x, int y)
  35. {
  36. var move = GetMove();
  37. move.TransformTo = this;
  38.  
  39. var isInMapMove = IsInMap(x + move.DeltaX, y + move.DeltaY);
  40.  
  41. return isInMapMove ? move : new CreatureCommand();
  42. }
  43.  
  44. private static CreatureCommand GetMove()
  45. {
  46. var key = Game.KeyPressed;
  47.  
  48. switch (key)
  49. {
  50. case Keys.Left:
  51. return new CreatureCommand {DeltaX = -1};
  52. case Keys.Right:
  53. return new CreatureCommand {DeltaX = 1};
  54. case Keys.Up:
  55. return new CreatureCommand {DeltaY = -1};
  56. case Keys.Down:
  57. return new CreatureCommand {DeltaY = 1};
  58. default:
  59. return new CreatureCommand();
  60. }
  61. }
  62.  
  63. private static bool IsInMap(int x, int y)
  64. {
  65. return x < Game.MapWidth && x >= 0 && y < Game.MapHeight && y >= 0;
  66. }
  67.  
  68. bool ICreature.DeadInConflict(ICreature conflictedObject)
  69. {
  70. return false;
  71. }
  72.  
  73. string ICreature.GetImageFileName()
  74. {
  75. return "Digger.png";
  76. }
  77.  
  78. int ICreature.GetDrawingPriority()
  79. {
  80. return DrawingPriority;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement