Advertisement
KoMeDiAnT

Ground and Digger

Nov 27th, 2016
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 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.Media;
  8.  
  9. namespace Digger
  10. {
  11.     //Напишите здесь классы Player, Terrain и другие.
  12.     class Terrain : ICreature
  13.     {
  14.         public CreatureCommand Act(int x, int y)
  15.         {
  16.             return new CreatureCommand()
  17.             {
  18.                 DeltaX = 0,
  19.                 DeltaY = 0,
  20.                 TransformTo = this
  21.             };
  22.         }
  23.  
  24.         public bool DeadInConflict(ICreature conflictedObject)
  25.         {
  26.             return true;
  27.         }
  28.  
  29.         public int GetDrawingPriority()
  30.         {
  31.             return 3;
  32.         }
  33.  
  34.         public string GetImageFileName()
  35.         {
  36.             return "Terrain.png";
  37.         }
  38.     }
  39.    
  40.     class Player : ICreature
  41.     {
  42.         public string GetImageFileName()
  43.         {
  44.             return "Digger.png";
  45.         }
  46.  
  47.         public int GetDrawingPriority()
  48.         {
  49.             return 1;
  50.         }
  51.  
  52.         public CreatureCommand Act(int x, int y)
  53.         {
  54.             var move = new CreatureCommand();
  55.             switch (Game.KeyPressed)
  56.             {
  57.                 case Keys.Up:
  58.                     if (y >= 0)
  59.                         move.DeltaY--;
  60.                     break;
  61.                 case Keys.Down:
  62.                     if (y <= Game.MapHeight)
  63.                         move.DeltaY++;
  64.                     break;
  65.                 case Keys.Right:
  66.                     if (x <= Game.MapWidth)
  67.                         move.DeltaX++;
  68.                     break;
  69.                 case Keys.Left:
  70.                     if (x >= 0)
  71.                         move.DeltaX--;
  72.                     break;
  73.             }
  74.             if (x + move.DeltaX >= Game.MapWidth || x + move.DeltaX < 0) move.DeltaX = 0;
  75.             if (y + move.DeltaY >= Game.MapHeight || y + move.DeltaY < 0) move.DeltaY = 0;
  76.             return move;
  77.         }
  78.  
  79.         public bool DeadInConflict(ICreature conflictedObject)
  80.         {
  81.             return false;
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement