/
dsska
/
lichnoe
Обзор
Документация
Войти
/
dsska
/
lichnoe
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Army/RandomArmyCreation.cs
45 строк
1 KB
dsska
upload files
02 мар 2026, 00:41
Верифицирован
02 мар 2026, 00:41
0efefd0
Код
Авторство
О чём код?
using Core.Models; using Core.Domain; using Core.Interfaces; namespace Core.Services { public class RandomArmyFactory : IArmyFactory { private readonly Random _random = new Random(); public Army CreateArmy(int budget) { var units = new List<Unit>(); int currentCost = 0; while (true) { var unit = CreateRandomUnit(); if (currentCost + unit.Cost > budget) break; units.Add(unit); currentCost += unit.Cost; } Console.WriteLine($"Создана случайная армия. Потрачено: {currentCost}/{budget}"); return new Army(units, budget); } private Unit CreateRandomUnit() { int type = _random.Next(0, 3); return type switch { 0 => new HeavyInfantry(), 1 => new LightInfantry(), 2 => new Archer(), _ => new LightInfantry() }; } } }