Advertisement
holllowknight

Работа с классами

Apr 14th, 2023 (edited)
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace world
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Player player = new Player("Winrar", 100, 80, 20, 3);
  10.             player.PrintInfo();
  11.             Console.ReadKey();
  12.         }
  13.     }
  14.  
  15.     class Player
  16.     {
  17.         public Player(string name, int health, int mana, int attack, int armor)
  18.         {
  19.             Name = name;
  20.             Health = health;
  21.             Mana = mana;
  22.             Attack = attack;
  23.             Armor = armor;
  24.         }
  25.  
  26.         public string Name { get; private set; }
  27.         public int Health { get; private set; }
  28.         public int Mana { get; private set; }
  29.         public int Attack { get; private set; }
  30.         public int Armor { get; private set; }
  31.  
  32.         public void PrintInfo()
  33.         {
  34.             Console.WriteLine($"Игрок {Name}");
  35.             Console.WriteLine($"Атака: {Attack}  Защита: {Armor}");
  36.             Console.WriteLine($"Здоровье:\t{Health} ");
  37.             Console.WriteLine($"Мана: \t\t{Mana} ");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement