public GameStateHolder GetState(int playerId) { return(new GameStateHolder { Trump = _game.Trump.ToString(), GameState = _game.State.ToString(), DeckCount = _game.Deck.Count, IsAttack = _game.IsAttack, IsInitialAttack = _game.IsInitialAttack, DefenderId = _game.Players[_game.DefenderIndex].Id, AttackerId = _game.Players[_game.InitialAttacker].Id, Role = _game.GetPlayerRole(playerId), Players = _players, Hand = _game.Players.First(p => p.Id == playerId).Hand.Select(c => new NamedCard(c)), CardsForTurn = _game.GetCardsForTurn(playerId).Select(c => new NamedCard(c)), Attacks = _game.Attacks.Select(a => (new NamedCard(a.Attacker), new NamedCard(a.Defender))) });
static void MainLoop() { while (true) { Console.WriteLine("========================================================"); SortHands(); PrintHands(); PrintAttacks(); Console.WriteLine($"\nTrump: ---{game.Trump}---"); Console.WriteLine($"Deck: {game.Deck.Count}"); Console.WriteLine($"Defender: Player{game.DefenderIndex}\n"); if (previousDefender != game.DefenderIndex) { Console.WriteLine("--- NEW DEFENDER ---"); Console.WriteLine("--- NEW DEFENDER ---"); Console.WriteLine("--- NEW DEFENDER ---"); previousDefender = game.DefenderIndex; } int playerId; PlayerRole role; do { playerId = ReadInt("Select player", game.Players.Count); role = game.GetPlayerRole(playerId); }while (role == PlayerRole.None); Player player = game.Players[playerId]; Console.WriteLine($"\nRole: {role}"); Console.WriteLine($"Your hand:"); PrintHand(playerId); int cardIndex = ReadInt("Card index", player.Hand.Count); Card card = player.Hand[cardIndex]; IReadOnlyList <Card> unbeaten = game.Attacks.Unbeaten(); if (role == PlayerRole.Attacker || unbeaten.Count < 2) { Try(() => game.Turn(playerId, card)); } else { Console.WriteLine("Unbeaten cards:"); for (int i = 0; i < unbeaten.Count; i++) { Console.WriteLine($"{i}. {unbeaten[i]}"); } int targetIndex = ReadInt($"Select target", unbeaten.Count); Card target = unbeaten[targetIndex]; Try(() => game.Turn(playerId, card, target)); } Console.WriteLine(); } }