SaNik74

Work with properties

May 4th, 2023 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         Player player1 = new Player(10, 15);
  6.         Draw drawe = new Draw();
  7.  
  8.         drawe.PutPlayerOnMap(player1.PositionX, player1.PositionY);
  9.     }
  10. }
  11.  
  12. class Player
  13. {
  14.     private int _positionX;
  15.     private int _positionY;
  16.  
  17.     public Player (int x, int y)
  18.     {
  19.         PositionX = x;
  20.         PositionY = y;
  21.     }
  22.  
  23.     public int PositionX
  24.     {
  25.         get
  26.         {
  27.             return _positionX;
  28.         }
  29.         private set
  30.         {
  31.             _positionX = value;
  32.         }
  33.     }
  34.  
  35.     public int PositionY
  36.     {
  37.         get
  38.         {
  39.             return _positionY;
  40.         }
  41.         private set
  42.         {
  43.             _positionY = value;
  44.         }
  45.     }
  46. }
  47.  
  48. class Draw
  49. {
  50.     public void PutPlayerOnMap(int x, int y, char playerSymbol = '@')
  51.     {
  52.         Console.SetCursorPosition(x, y);
  53.         Console.Write(playerSymbol);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment