Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.32 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace Digger
  5. {
  6.    
  7.     class Player : ICreature
  8.     {
  9.        
  10.         CreatureCommand Move(int x, int y, int dx, int dy)
  11.         {
  12.             var newX = x + dx;
  13.             var newY = y + dy;
  14.             var result = new CreatureCommand();
  15.             if (newX < Game.MapWidth && newX >= 0 &&
  16.                newY < Game.MapHeight && newY >= 0)
  17.                 return new CreatureCommand() { DeltaX = dx, DeltaY = dy };
  18.             return new CreatureCommand();
  19.         }
  20.  
  21.         public CreatureCommand Act(int x, int y)
  22.         {
  23.             switch (Game.KeyPressed)
  24.             {
  25.                 case Keys.Left: return Move(x, y, -1, 0);
  26.                 case Keys.Right: return Move(x, y, 1, 0);
  27.                 case Keys.Up: return Move(x, y, 0, -1);
  28.                 case Keys.Down: return Move(x, y, 0, 1);
  29.             }
  30.             return new CreatureCommand();
  31.         }
  32.  
  33.         public bool DeadInConflict(ICreature enemy)
  34.         {
  35.             return false;
  36.         }
  37.  
  38.         public int GetDrawingPriority()
  39.         {
  40.             return 0;
  41.         }
  42.  
  43.         public string GetImageFileName()
  44.         {
  45.             return "Digger.png";
  46.         }
  47.     }
  48.     class Terrain : ICreature
  49.     {
  50.         public CreatureCommand Act(int x, int y)
  51.         {
  52.             return new CreatureCommand();
  53.         }
  54.  
  55.         public bool DeadInConflict(ICreature enemy)
  56.         {
  57.             return enemy is Player;
  58.         }
  59.  
  60.         public int GetDrawingPriority()
  61.         {
  62.             return 1;
  63.         }
  64.  
  65.         public string GetImageFileName()
  66.         {
  67.             return "Terrain.png";
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. using System.Windows.Forms;
  94.  
  95. namespace Digger
  96. {
  97.    
  98.     class Player : ICreature
  99.     {
  100.        
  101.         CreatureCommand Move(int x, int y, int dx, int dy)
  102.         {
  103.             var newX = x + dx;
  104.             var newY = y + dy;
  105.             var result = new CreatureCommand();
  106.             if (newX < Game.MapWidth && newX >= 0 &&
  107.                newY < Game.MapHeight && newY >= 0 &&
  108.                !(Game.Map[newX,newY] is Sack))
  109.                 return new CreatureCommand() { DeltaX = dx, DeltaY = dy };
  110.             return new CreatureCommand();
  111.         }
  112.  
  113.         public CreatureCommand Act(int x, int y)
  114.         {
  115.             switch (Game.KeyPressed)
  116.             {
  117.                 case Keys.Left: return Move(x, y, -1, 0);
  118.                 case Keys.Right: return Move(x, y, 1, 0);
  119.                 case Keys.Up: return Move(x, y, 0, -1);
  120.                 case Keys.Down: return Move(x, y, 0, 1);
  121.             }
  122.             return new CreatureCommand();
  123.         }
  124.  
  125.         public bool DeadInConflict(ICreature enemy)
  126.         {
  127.             return enemy is Sack;
  128.         }
  129.  
  130.         public int GetDrawingPriority()
  131.         {
  132.             return 0;
  133.         }
  134.  
  135.         public string GetImageFileName()
  136.         {
  137.             return "Digger.png";
  138.         }
  139.     }
  140.     class Terrain : ICreature
  141.     {
  142.         public CreatureCommand Act(int x, int y)
  143.         {
  144.             return new CreatureCommand();
  145.         }
  146.  
  147.         public bool DeadInConflict(ICreature enemy)
  148.         {
  149.             return enemy is Player;
  150.         }
  151.  
  152.         public int GetDrawingPriority()
  153.         {
  154.             return 1;
  155.         }
  156.  
  157.         public string GetImageFileName()
  158.         {
  159.             return "Terrain.png";
  160.         }
  161.     }
  162.     class Sack : ICreature
  163.     {
  164.        
  165.         int falledFor;
  166.         public CreatureCommand Act(int x, int y)
  167.         {
  168.             if (IsTileSolid(x, y + 1) || DidPlayerCatchedIt(x, y))
  169.             {
  170.                 falledFor = 0;
  171.                 return new CreatureCommand();
  172.             }
  173.             if (IsTileSolid(x, y + 2) && falledFor > 0)
  174.                 return new CreatureCommand() { DeltaY = 1, TransformTo = new Gold() };
  175.             falledFor++;
  176.             return new CreatureCommand() { DeltaY = 1 };
  177.         }
  178.  
  179.         public bool DidPlayerCatchedIt(int x, int y)
  180.         {
  181.             return Game.Map[x, y + 1] is Player && falledFor == 0;
  182.         }
  183.  
  184.  
  185.         public bool IsTileSolid(int x, int y)
  186.         {
  187.             if (Game.MapHeight <= y) return true;
  188.             var tile = Game.Map[x, y];
  189.             return tile is Terrain || tile is Gold || tile is Sack;
  190.         }
  191.  
  192.         public bool DeadInConflict(ICreature enemy)
  193.         {
  194.             return false;
  195.             //return enemy is Terrain || enemy is Sack || enemy is Gold;
  196.  
  197.         }
  198.  
  199.         public int GetDrawingPriority()
  200.         {
  201.             return 1;
  202.         }
  203.  
  204.         public string GetImageFileName()
  205.         {
  206.             return "Sack.png";
  207.         }
  208.     }
  209.     class Gold : ICreature
  210.     {
  211.         //int value = 1;
  212.         public CreatureCommand Act(int x, int y)
  213.         {
  214.             return new CreatureCommand();
  215.         }
  216.  
  217.         public bool DeadInConflict(ICreature enemy)
  218.         {
  219.             if (enemy is Player)
  220.             {
  221.                 Game.Scores += 10;
  222.                 return true;
  223.             }
  224.             return enemy is Gold;
  225.         }
  226.  
  227.         public int GetDrawingPriority()
  228.         {
  229.             return 1;
  230.         }
  231.  
  232.         public string GetImageFileName()
  233.         {
  234.             return "Gold.png";
  235.         }
  236.     }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement