示例#1
0
        public bool Throw(int numberCard)
        {
            Game.counter++;
            if (Hand.Count > numberCard)
            {
                var card = Hand[numberCard];

                if (!(card is null))
                {
                    if (Game.counter % 2 != 0)
                    {
                        var cardPair = new CardPair();
                        cardPair.TryAdd(card);
                        Game.CardsPairsOnTable.Add(cardPair);
                        Hand.RemoveAt(numberCard);
                        return(true);
                    }
                    else if (Game.counter % 2 == 0)
                    {
                        var result = Game.CardsPairsOnTable.Last().TryAdd(card);
                        if (!result)
                        {
                            Game.counter--; return(false);
                        }
                        Hand.RemoveAt(numberCard);
                        return(true);
                    }
                }
            }
            throw new ArgumentException($"Player 1 {Name} doesn`t have a ({Hand[numberCard]})");
        }