Advertisement
mikhailemv

Практика «Земля и Диггер»

Dec 26th, 2022
1,404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 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.  
  8. namespace Digger
  9. {
  10.     public enum DrawPriority
  11.     {
  12.         Player = 1,
  13.         Terrain = 2
  14.     };
  15.  
  16.     public class Terrain : ICreature
  17.     {
  18.         public CreatureCommand Act(int x, int y)
  19.         {
  20.             return new CreatureCommand();
  21.         }
  22.  
  23.         public bool DeadInConflict(ICreature conflictedObject)
  24.         {
  25.             return true;
  26.         }
  27.  
  28.         public int GetDrawingPriority()
  29.         {
  30.             return (int)DrawPriority.Terrain;
  31.         }
  32.  
  33.         public string GetImageFileName()
  34.         {
  35.             return "Terrain.png";
  36.         }
  37.     }
  38.  
  39.     public class Player : ICreature
  40.     {
  41.         public CreatureCommand Act(int x, int y)
  42.         {
  43.             var deltaX = 0;
  44.             var deltaY = 0;
  45.          
  46.             if (Game.KeyPressed == Keys.Up)
  47.                 deltaY -= 1;
  48.             if (Game.KeyPressed == Keys.Down)
  49.                 deltaY += 1;
  50.             if (Game.KeyPressed == Keys.Right)
  51.                 deltaX += 1;
  52.             if (Game.KeyPressed == Keys.Left)
  53.                 deltaX -= 1;
  54.  
  55.             var newX = x + deltaX;
  56.             var newY = y + deltaY;
  57.  
  58.             if (newX >= Game.MapWidth || newX < 0)
  59.                 deltaX = 0;
  60.             if (newY >= Game.MapHeight || newY < 0)
  61.                 deltaY = 0;
  62.  
  63.             return new CreatureCommand
  64.             {
  65.                 DeltaX = deltaX,
  66.                 DeltaY = deltaY
  67.             };
  68.         }
  69.  
  70.         public bool DeadInConflict(ICreature conflictedObject)
  71.         {
  72.             return false;
  73.         }
  74.  
  75.         public int GetDrawingPriority()
  76.         {
  77.             return (int)DrawPriority.Player;
  78.         }
  79.  
  80.         public string GetImageFileName()
  81.         {
  82.             return "Digger.png";
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement