-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
37 lines (32 loc) · 1009 Bytes
/
Player.cs
File metadata and controls
37 lines (32 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace Reflection
{
public class Player
{
private int _health;
private int _maxHealth;
public string Name { get; private set; }
public int Level { get; private set; }
public Player(string name, int maxHealth)
{
Name = name;
_maxHealth = maxHealth;
_health = maxHealth;
Level = 1;
}
private void TakeDamage(int damage)
{
_health -= damage;
Console.WriteLine($"{Name} получил {damage} урона! HP: {_health}/{_maxHealth}");
}
public void Heal(int amount)
{
_health = Math.Min(_health + amount, _maxHealth);
Console.WriteLine($"{Name} восстановил {amount} HP. HP: {_health}/{_maxHealth}");
}
private int GetHealthPercent()
{
return (int)((double)_health / _maxHealth * 100);
}
}
}