Advertisement
holllowknight

ДЗ: Свойства

Apr 1st, 2020 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace classes3
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Renderer renderer = new Renderer();
  15.             Player player = new Player(0, 0);
  16.             player.Move(2, 5);
  17.             renderer.DrawPlayer(player, 'H');
  18.         }
  19.     }
  20.  
  21.     class Player
  22.     {
  23.         public Player(int positionX, int positionY)
  24.         {
  25.             PositionX = positionX;
  26.             PositionY = positionY;
  27.         }
  28.  
  29.         public int PositionX { get; private set; }
  30.         public int PositionY { get; private set; }
  31.  
  32.         public void Move(int offsetX, int offsetY)
  33.         {
  34.             PositionX += offsetX;
  35.             PositionY += offsetY;
  36.  
  37.             if (PositionX > Console.WindowWidth)
  38.                 PositionX = Console.WindowWidth;
  39.  
  40.             if (PositionY > Console.WindowHeight)
  41.                 PositionY = Console.WindowHeight;
  42.         }
  43.     }
  44.  
  45.     class Renderer
  46.     {
  47.         public void DrawPlayer(Player player, char character, ConsoleColor playerColor = ConsoleColor.Green)
  48.         {
  49.             Console.CursorVisible = false;
  50.             Console.SetCursorPosition(player.PositionX, player.PositionY);
  51.             ConsoleColor defaultColor = Console.ForegroundColor;
  52.             Console.ForegroundColor = playerColor;
  53.             Console.Write(character);
  54.             Console.ForegroundColor = defaultColor;
  55.             Console.ReadKey();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement