Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lesson_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Player player = new Player("Иван", 8);
- player.ShowInfo();
- Console.ReadLine();
- }
- }
- public class Player
- {
- private string _name;
- private int _hp;
- private int _maxHp = 10;
- private int _minHp = 0;
- public string Healthbar
- {
- get
- {
- var lostHp = _maxHp - _hp;
- return new string('#', _hp) + new string('_', lostHp);
- }
- }
- public Player(string name, int hp)
- {
- _name = name;
- if (hp >= _maxHp)
- {
- hp = _maxHp;
- }
- if (hp <= _minHp)
- {
- hp = _minHp;
- }
- _hp = hp;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Name: {_name}.\nHP: {Healthbar}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement