/
evsyukov.s
/
test
Обзор
Документация
Войти
/
evsyukov.s
/
test
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/DicePoker.Core/Models/DiceHand.cs
40 строк
1 KB
ligay.a
Рефакторинг моделей данных
20 ноя 2025, 10:46
20 ноя 2025, 10:46
7b6f7b7
Код
Авторство
О чём код?
namespace DicePoker.Core.Models; public sealed class DiceHand { public IReadOnlyList<Die> Dice => _dice; private readonly List<Die> _dice; public DiceHand(int diceCount = 5) { if (diceCount <= 0) throw new ArgumentOutOfRangeException(nameof(diceCount)); _dice = Enumerable.Range(0, diceCount).Select(_ => new Die()).ToList(); } /// <summary> /// Создает руку с заданными значениями костей (для восстановления состояния) /// </summary> public DiceHand(int[] values) { if (values == null || values.Length == 0) throw new ArgumentException("Values cannot be null or empty", nameof(values)); _dice = values.Select(v => new Die(v)).ToList(); } public int[] Values() => _dice.Select(d => d.Value).ToArray(); public void RollAll() { foreach (var die in _dice) die.Roll(); } public void RerollIndices(IEnumerable<int> indices) { var indexSet = indices.ToHashSet(); for (var i = 0; i < _dice.Count; i++) { if (indexSet.Contains(i)) _dice[i].Roll(); } } }