Advertisement
Suslick

Untitled

Aug 6th, 2024 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lesson_1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Player player = new Player("Иван", 8);
  10.             player.ShowInfo();
  11.  
  12.             Console.ReadLine();
  13.         }
  14.     }
  15.  
  16.     public class Player
  17.     {
  18.         private string _name;
  19.         private int _hp;
  20.         private int _maxHp = 10;
  21.         private int _minHp = 0;
  22.         public string Healthbar
  23.         {
  24.             get
  25.             {
  26.                 var lostHp = _maxHp - _hp;
  27.                 return new string('#', _hp) + new string('_', lostHp);
  28.             }
  29.         }
  30.  
  31.         public Player(string name, int hp)
  32.         {
  33.             _name = name;
  34.  
  35.             if (hp >= _maxHp)
  36.             {
  37.                 hp = _maxHp;
  38.             }
  39.             if (hp <= _minHp)
  40.             {
  41.                 hp = _minHp;
  42.             }
  43.  
  44.             _hp = hp;
  45.         }
  46.  
  47.         public void ShowInfo()
  48.         {
  49.             Console.WriteLine($"Name: {_name}.\nHP: {Healthbar}");
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement