Advertisement
SharpHurt

Untitled

Apr 7th, 2021
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. namespace Digger
  2. {
  3.     public class Terrain : ICreature
  4.     {
  5.         public CreatureCommand Act(int x, int y) => new CreatureCommand {DeltaX = 0, DeltaY = 0};
  6.  
  7.         public bool DeadInConflict(ICreature conflictedObject) => true;
  8.  
  9.         public int GetDrawingPriority() => 2;
  10.  
  11.         public string GetImageFileName() => "Terrain.png";
  12.     }
  13.  
  14.     public class Player : ICreature
  15.     {
  16.         public CreatureCommand Act(int x, int y)
  17.         {
  18.             switch (Game.KeyPressed)
  19.             {
  20.                 case System.Windows.Forms.Keys.Left:
  21.                     if (IsStepPossible(x - 1, y))
  22.                         return new CreatureCommand {DeltaX = -1, DeltaY = 0};
  23.                     break;
  24.  
  25.                 case System.Windows.Forms.Keys.Up:
  26.                     if (IsStepPossible(x, y - 1))
  27.                         return new CreatureCommand {DeltaX = 0, DeltaY = -1};
  28.                     break;
  29.  
  30.                 case System.Windows.Forms.Keys.Right:
  31.                     if (IsStepPossible(x + 1, y))
  32.                         return new CreatureCommand {DeltaX = 1, DeltaY = 0};
  33.                     break;
  34.  
  35.                 case System.Windows.Forms.Keys.Down:
  36.                     if (IsStepPossible(x, y + 1))
  37.                         return new CreatureCommand {DeltaX = 0, DeltaY = 1};
  38.                     break;
  39.             }
  40.  
  41.             return new CreatureCommand();
  42.         }
  43.  
  44.         public bool DeadInConflict(ICreature conflictedObject)
  45.         {
  46.             if (conflictedObject is Gold)
  47.             {
  48.                 Game.Scores += 10;
  49.                 return false;
  50.             }
  51.  
  52.             return conflictedObject is Sack;
  53.         }
  54.  
  55.         public int GetDrawingPriority() => 1;
  56.  
  57.         public string GetImageFileName() => "Digger.png";
  58.  
  59.         private bool IsStepPossible(int x, int y)
  60.         {
  61.             if (!(x >= 0 && x < Game.MapWidth && y >= 0 && y < Game.MapHeight))
  62.                 return false;
  63.  
  64.             return Game.Map[x, y] == null || !(Game.Map[x, y] is Sack);
  65.         }
  66.     }
  67.  
  68.     public class Sack : ICreature
  69.     {
  70.         private int counter;
  71.  
  72.         public CreatureCommand Act(int x, int y)
  73.         {
  74.             if (y < Game.MapHeight - 1)
  75.             {
  76.                 var map = Game.Map[x, y + 1];
  77.  
  78.                 if (map == null || counter > 0 && map is Player)
  79.                 {
  80.                     counter++;
  81.                     return new CreatureCommand {DeltaX = 0, DeltaY = 1};
  82.                 }
  83.             }
  84.  
  85.             if (counter > 1)
  86.                 return new CreatureCommand {DeltaX = 0, DeltaY = 0, TransformTo = new Gold()};
  87.  
  88.             counter = 0;
  89.             return new CreatureCommand {DeltaX = 0, DeltaY = 0};
  90.         }
  91.  
  92.         public bool DeadInConflict(ICreature conflictedObject) => false;
  93.  
  94.         public int GetDrawingPriority() => 5;
  95.  
  96.         public string GetImageFileName() => "Sack.png";
  97.     }
  98.  
  99.     public class Gold : ICreature
  100.     {
  101.         public CreatureCommand Act(int x, int y) => new CreatureCommand {DeltaX = 0, DeltaY = 0};
  102.  
  103.         public bool DeadInConflict(ICreature conflictedObject) => conflictedObject is Player;
  104.  
  105.         public int GetDrawingPriority() => 3;
  106.  
  107.         public string GetImageFileName() => "Gold.png";
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement