Advertisement
SharpHurt

Untitled

Apr 7th, 2021
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Digger
  8. {
  9.     public class Terrain : ICreature
  10.     {
  11.         public CreatureCommand Act(int x, int y)
  12.         {
  13.             return new CreatureCommand() { DeltaX = 0, DeltaY = 0 };
  14.         }
  15.  
  16.         public bool DeadInConflict(ICreature conflictedObject)
  17.         {
  18.             return true;
  19.         }
  20.  
  21.         public int GetDrawingPriority()
  22.         {
  23.             return 2;
  24.         }
  25.  
  26.         public string GetImageFileName()
  27.         {
  28.             return "Terrain.png";
  29.         }
  30.     }
  31.  
  32.     public class Player : ICreature
  33.     {
  34.         public static int X, Y = 0;
  35.         public static int LetX, LetY = 0;
  36.         public CreatureCommand Act(int x, int y)
  37.         {
  38.             X = x;
  39.             Y = y;
  40.             switch (Game.KeyPressed)
  41.             {
  42.                 case System.Windows.Forms.Keys.Left:
  43.                 LetY = 0;
  44.                 LetX = -1;
  45.                 break;
  46.  
  47.                 case System.Windows.Forms.Keys.Up:
  48.                 LetY = -1;
  49.                 LetX = 0;
  50.                 break;
  51.  
  52.                 case System.Windows.Forms.Keys.Right:
  53.                 LetY = 0;
  54.                 LetX = 1;
  55.                 break;
  56.  
  57.                 case System.Windows.Forms.Keys.Down:
  58.                 LetY = 1;
  59.                 LetX = 0;
  60.                 break;
  61.  
  62.                 default:
  63.                 Stay();
  64.                 break;
  65.             }
  66.             if (!(x + LetX >= 0 && x + LetX < Game.MapWidth &&
  67.             y + LetY >= 0 && y + LetY < Game.MapHeight))
  68.                 Stay();
  69.             if (Game.Map[x + LetX, y + LetY] != null)
  70.             {
  71.                 if (Game.Map[x + LetX, y + LetY].ToString() == "Digger.Sack")
  72.                     Stay();
  73.             }
  74.             return new CreatureCommand() { DeltaX = LetX, DeltaY = LetY };
  75.         }
  76.  
  77.         public bool DeadInConflict(ICreature conflictedObject)
  78.         {
  79.             var neighbor = conflictedObject.ToString();
  80.             if (neighbor == "Digger.Gold")
  81.                 Game.Scores += 10;
  82.             if (neighbor == "Digger.Sack" ||
  83.             neighbor == "Digger.Monster")
  84.             {
  85.                 return true;
  86.             }
  87.             return false;
  88.         }
  89.  
  90.         public int GetDrawingPriority()
  91.         {
  92.             return 1;
  93.         }
  94.  
  95.         public string GetImageFileName()
  96.         {
  97.             return "Digger.png";
  98.         }
  99.  
  100.         private static void Stay()
  101.         {
  102.             LetX = 0;
  103.             LetY = 0;
  104.         }
  105.     }
  106.  
  107.     public class Sack : ICreature
  108.     {
  109.         private int counter = 0;
  110.         public static bool DeadlyForPlayer = false;
  111.  
  112.         public CreatureCommand Act(int x, int y)
  113.         {
  114.             if (y < Game.MapHeight - 1)
  115.             {
  116.                 var map = Game.Map[x, y + 1];
  117.                 if (map == null ||
  118.                     (counter > 0 && (map.ToString() == "Digger.Player" ||
  119.                     map.ToString() == "Digger.Monster")))
  120.                 {
  121.                     counter++;
  122.                     return Fall();
  123.                 }
  124.             }
  125.  
  126.             if (counter > 1)
  127.             {
  128.                 counter = 0;
  129.                 return new CreatureCommand() { DeltaX = 0, DeltaY = 0, TransformTo = new Gold() };
  130.             }
  131.             counter = 0;
  132.             return DoNothing();
  133.         }
  134.  
  135.         public bool DeadInConflict(ICreature conflictedObject)
  136.         {
  137.             return false;
  138.         }
  139.  
  140.         public int GetDrawingPriority()
  141.         {
  142.             return 5;
  143.         }
  144.  
  145.         public string GetImageFileName()
  146.         {
  147.             return "Sack.png";
  148.         }
  149.  
  150.         private CreatureCommand Fall()
  151.         {
  152.             return new CreatureCommand() { DeltaX = 0, DeltaY = 1 };
  153.         }
  154.  
  155.         private CreatureCommand DoNothing()
  156.         {
  157.             return new CreatureCommand() { DeltaX = 0, DeltaY = 0 };
  158.         }
  159.     }
  160.  
  161.     public class Gold : ICreature
  162.     {
  163.         public CreatureCommand Act(int x, int y)
  164.         {
  165.             return new CreatureCommand() { DeltaX = 0, DeltaY = 0 };
  166.         }
  167.  
  168.         public bool DeadInConflict(ICreature conflictedObject)
  169.         {
  170.             var neighbor = conflictedObject.ToString();
  171.             return neighbor == "Digger.Player" || neighbor == "Digger.Monster";
  172.         }
  173.  
  174.         public int GetDrawingPriority()
  175.         {
  176.             return 3;
  177.         }
  178.  
  179.         public string GetImageFileName()
  180.         {
  181.             return "Gold.png";
  182.         }
  183.     }
  184.  
  185.     public class Monster : ICreature
  186.     {
  187.         public CreatureCommand Act(int x, int y)
  188.         {
  189.             int dx = 0;
  190.             int dy = 0;
  191.  
  192.             if (IsPlayerAlive())
  193.             {
  194.                 if (Player.X == x)
  195.                 {
  196.                     if (Player.Y < y) dy = -1;
  197.                     else if (Player.Y > y) dy = 1;
  198.                 }
  199.  
  200.                 else if (Player.Y == y)
  201.                 {
  202.                     if (Player.X < x) dx = -1;
  203.                     else if (Player.X > x) dx = 1;
  204.                 }
  205.                 else
  206.                 {
  207.                     if (Player.X < x) dx = -1;
  208.                     else if (Player.X > x) dx = 1;
  209.                 }
  210.             }
  211.             else return Stay();
  212.  
  213.             if (!(x + dx >= 0 && x + dx < Game.MapWidth &&
  214.             y + dy >= 0 && y + dy < Game.MapHeight))
  215.                 return Stay();
  216.  
  217.             var map = Game.Map[x + dx, y + dy];
  218.             if (map != null)
  219.                 if (map.ToString() == "Digger.Terrain" ||
  220.                     map.ToString() == "Digger.Sack" ||
  221.                     map.ToString() == "Digger.Monster")
  222.                     return Stay();
  223.             return new CreatureCommand() { DeltaX = dx, DeltaY = dy };
  224.         }
  225.  
  226.         public bool
  227.  
  228.         DeadInConflict(ICreature conflictedObject)
  229.         {
  230.             var neighbor = conflictedObject.ToString();
  231.             return neighbor == "Digger.Sack" ||
  232.             neighbor == "Digger.Monster";
  233.         }
  234.  
  235.         public int GetDrawingPriority()
  236.         {
  237.             return 0;
  238.         }
  239.  
  240.         public string GetImageFileName()
  241.         {
  242.             return "Monster.png";
  243.         }
  244.  
  245.         static private CreatureCommand Stay()
  246.         {
  247.             return new CreatureCommand() { DeltaX = 0, DeltaY = 0 };
  248.         }
  249.  
  250.         static private bool IsPlayerAlive()
  251.         {
  252.             for (int i = 0; i < Game.MapWidth; i++)
  253.             for (int j = 0; j < Game.MapHeight; j++)
  254.             {
  255.                 var map = Game.Map[i, j];
  256.                 if (map != null)
  257.                 {
  258.                     if (map.ToString() == "Digger.Player")
  259.                     {
  260.                         Player.X = i;
  261.                         Player.Y = j;
  262.                         return true;
  263.                     }
  264.                 }
  265.             }
  266.             return false;
  267.         }
  268.     }
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement