/
expens1ve
/
project_war
Обзор
Документация
Войти
/
expens1ve
/
project_war
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
Persistence
Models/Unit.cs
39 строк
1 KB
Vadim
fix comment
26 фев 2026, 14:27
26 фев 2026, 14:27
52318d5
Код
Авторство
О чём код?
using project_war.Models.Interfaces; namespace project_war.Models { /// <summary> /// Базовый абстрактный класс боевой единицы. Содержит общие свойства и простую логику получения урона. /// </summary> public abstract class Unit : IUnit { public int Health { get; set; } public int AttackDamage { get; } public int Defense { get; } public int Cost { get; } protected Unit(int health, int attackDamage, int defense, int cost) { Health = health; AttackDamage = attackDamage; Defense = defense; Cost = cost; } public void Hit(IUnit target) { if (target == null || Health <= 0 || target.Health <= 0) return; target.TakeDamage(AttackDamage); } public void TakeDamage(int damage) { if (damage <= 0) return; int actualDamage = Math.Max(0, damage - Defense); Health = Math.Max(0, Health - actualDamage); } } }