-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFighter.cs
More file actions
31 lines (27 loc) · 1.04 KB
/
Fighter.cs
File metadata and controls
31 lines (27 loc) · 1.04 KB
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
using PatternStrategy.Strategies;
using System;
namespace PatternStrategy
{
public class Fighter
{
public string Name { get; private set; }
public int BaseDamage { get; private set; }
public IDamageStrategy DamageStrategy { get; private set; }
public Fighter(string name, int baseDamage, IDamageStrategy damageStrategy)
{
Name = name;
BaseDamage = baseDamage;
DamageStrategy = damageStrategy ?? throw new ArgumentNullException(nameof(damageStrategy));
}
public void Attack()
{
int damage = DamageStrategy.CalculateDamage(BaseDamage);
string description = DamageStrategy.GetDamageDescription();
Console.WriteLine($"- Атака! {Name} наносит {damage} урона! {description}");
}
public void SetStrategy(IDamageStrategy newStrategy)
{
DamageStrategy = newStrategy ?? throw new ArgumentNullException(nameof(newStrategy));
}
}
}