RedFlys

Home work - draw player

Nov 12th, 2021 (edited)
626
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.  
  7. namespace Home_Work
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Player player = new Player(10, 5, '@');
  14.             Renderer renderer = new Renderer();
  15.  
  16.             renderer.DrawPlayer(player.PositionX, player.PositionY, player.Symbol);
  17.  
  18.             Console.ReadKey();
  19.         }
  20.     }
  21.  
  22.     class Player
  23.     {
  24.         private int _positionX;
  25.         private int _positionY;
  26.         private char _symbol;
  27.  
  28.         public Player(int positionX, int positionY, char symbol)
  29.         {
  30.             SetCorrectPosition(positionX, positionY);
  31.             _symbol = symbol;
  32.         }
  33.  
  34.         public int PositionX => _positionX;
  35.         public int PositionY => _positionY;
  36.         public char Symbol => _symbol;
  37.  
  38.         private void SetCorrectPosition(int positionX, int positionY)
  39.         {
  40.             _positionX = GetPositiveNumber(positionX);
  41.             _positionY = GetPositiveNumber(positionY);
  42.         }
  43.  
  44.         private int GetPositiveNumber(int number)
  45.         {
  46.             if (number >= 0)
  47.             {
  48.                 return number;
  49.             }
  50.             else
  51.             {
  52.                 return 0;
  53.             }
  54.         }
  55.     }
  56.  
  57.     class Renderer
  58.     {
  59.         public void DrawPlayer(int positionX, int positionY, char symbol)
  60.         {
  61.             Console.SetCursorPosition(positionX, positionY);
  62.             Console.WriteLine(symbol);
  63.         }
  64.     }
  65. }
Add Comment
Please, Sign In to add comment