Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IDamageStrategy
- {
- int CalculateFinalDamage(int damage);
- }
- public class Character
- {
- public int Health { get; set; }
- private IDamageStrategy _damageStrategy;
- public Character(IDamageStrategy damageStrategy)
- {
- _damageStrategy = damageStrategy;
- }
- public void TakeDamage(int damage)
- {
- int finalDamage = _damageStrategy.CalculateFinalDamage(damage);
- Health -= finalDamage;
- }
- }
- public class WarriorDamageStrategy : IDamageStrategy
- {
- public int Armor { get; set; }
- public int CalculateFinalDamage(int damage)
- {
- // Учитываем броню при расчете урона
- int finalDamage = damage - Armor;
- return finalDamage > 0 ? finalDamage : 0;
- }
- }
- public class RogueDamageStrategy : IDamageStrategy
- {
- public int Agility { get; set; }
- public int CalculateFinalDamage(int damage)
- {
- // Учитываем гибкость при расчете урона
- int finalDamage = damage - (Agility / 2);
- return finalDamage > 0 ? finalDamage : 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement