Advertisement
viktarb

Работа со свойствами

Oct 6th, 2022 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | Money | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Renderer renderer = new Renderer();
  9.         Player player1 = new Player(4, 5);
  10.         Player player2 = new Player(3, 6, '9');
  11.         renderer.DrawPlayer(player1.PositionX , player1.PositionY, player1.Symbol);
  12.         renderer.DrawPlayer(player2.PositionX, player2.PositionY, player2.Symbol);
  13.     }
  14. }
  15.  
  16. class Player
  17. {
  18.     public int PositionX { get; private set; }
  19.     public int PositionY { get; private set; }
  20.     public char Symbol { get; private set; }
  21.  
  22.     public Player(int positionX = 0, int positionY = 0, char symbol = '@')
  23.     {
  24.         PositionX = positionX;
  25.         PositionY = positionY;
  26.         Symbol = symbol;
  27.     }
  28. }
  29.  
  30. class Renderer
  31. {
  32.     public void DrawPlayer(int positionY, int positionX, char symbol)
  33.     {
  34.         Console.SetCursorPosition(positionY, positionX);
  35.         Console.WriteLine(symbol);
  36.     }
  37. }
Tags: C#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement