/
evsyukov.s
/
test
Обзор
Документация
Войти
/
evsyukov.s
/
test
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/DicePoker.Core/Game/GameSnapshot.cs
49 строк
1 KB
ligay.a
Расширен функционал генератора подсказок
05 дек 2025, 11:59
05 дек 2025, 11:59
e0893a4
Код
Авторство
О чём код?
using System.Text.Json; using DicePoker.Core.Models; namespace DicePoker.Core.Game; public sealed class GameSnapshot { public string Player1Name { get; init; } = ""; public int Player1Score { get; init; } public string Player2Name { get; init; } = ""; public int Player2Score { get; init; } public int CurrentPlayerIndex { get; init; } public int[] Dice { get; init; } = Array.Empty<int>(); public int RerollsLeft { get; init; } public int TurnNumber { get; init; } public int SecondsPerMove { get; init; } public List<string> History { get; init; } = new(); public static GameSnapshot FromState(GameState state) { return new GameSnapshot { Player1Name = state.Player1.Name, Player1Score = state.Player1.Score, Player2Name = state.Player2.Name, Player2Score = state.Player2.Score, CurrentPlayerIndex = state.CurrentPlayerIndex, Dice = state.Hand.Values(), RerollsLeft = state.RerollsLeft, TurnNumber = state.TurnNumber, SecondsPerMove = state.SecondsPerMove, History = state.History.ToList() }; } public GameState ToState() { var p1 = new Player(Player1Name); var p2 = new Player(Player2Name); if (Player1Score != 0) p1.AddScore(Player1Score); if (Player2Score != 0) p2.AddScore(Player2Score); var hand = Dice.Length > 0 ? new Models.DiceHand(Dice) : new Models.DiceHand(); return new GameState(p1, p2, CurrentPlayerIndex, hand, RerollsLeft, TurnNumber, SecondsPerMove, History); } }