Пример #1
0
        public void PlayCard(int playerId, int[] cardIds)
        {
            if (_currentPhase != GamePhase.PlayersTurn)
            {
                throw new InvalidOperationException("Not allowed during Czar turn");
            }

            bool success = Players.TryGetValue(playerId, out var player);

            if (!success)
            {
                throw new ArgumentException("Player with provided ID is not present in the game");
            }

            if (_cardsOnTheTable.ContainsKey(playerId))
            {
                throw new ArgumentException("Player with provided ID already played this turn");
            }

            if (CurrentCzar.Id == playerId)
            {
                throw new ArgumentException("Czar can not play white cards");
            }

            List <int> cardIndices = new List <int>();

            foreach (int cardId in cardIds)
            {
                bool present = false;

                for (int i = 0; i < player.Hand.Count; i++)
                {
                    if (player.Hand[i].Id == cardId)
                    {
                        cardIndices.Add(i);
                        present = true;
                        break;
                    }
                }
                if (!present)
                {
                    throw new ArgumentException($"Card with ID {cardId} is not present in players hand");
                }
            }

            Card[] playedCards = new Card[cardIndices.Count];
            for (int i = 0; i < playedCards.Length; i++)
            {
                playedCards[i] = player.Hand[cardIndices[i]];
                player.Hand[cardIndices[i]] = WhiteCards.DrawCard();
            }

            _cardsOnTheTable.Add(playerId, playedCards);
        }
Пример #2
0
 public void Start()
 {
     _currentPhase    = GamePhase.PlayersTurn;
     CurrentBlack     = BlackCards.DrawCard();
     _cardsOnTheTable = new Dictionary <int, Card[]>();
     _playerIds       = new List <int>();
     foreach (var player in Players)
     {
         _playerIds.Add(player.Key);
     }
     _currentCzarIndex = 0;
     CurrentCzar       = Players[_playerIds[_currentCzarIndex]];
     foreach (var player in Players.Values)
     {
         for (int i = 0; i < 10; i++)
         {
             player.Hand.Add(WhiteCards.DrawCard());
         }
     }
 }