Beispiel #1
0
 private void DrawCards()
 {
     while (OnTable.Count < 5)
     {
         OnTable.Add(OnDeck.Pop());
     }
 }
Beispiel #2
0
        public void TradeCards(User player, List <Card> hand, List <Card> table)
        {
            var data = GetPlayerData(player, true);

            if (hand.Count < table.Count)
            {
                hand.AddRange(Enumerable.Repeat(Card.Camel, Math.Min(table.Count - hand.Count, data.Camels)));
            }

            if (hand.Count() != table.Count())
            {
                throw new InvalidOperationException("Cards must be traded equally");
            }

            if (!hand.Any())
            {
                throw new InvalidOperationException("No cards to trade");
            }

            Dictionary <Card, int> handCardsToTrade  = hand.GroupBy(c => c).ToDictionary(k => k.Key, k => k.Count());
            Dictionary <Card, int> tableCardsToTrade = table.GroupBy(c => c).ToDictionary(k => k.Key, k => k.Count());

            if (handCardsToTrade.Any(c => (c.Key == Card.Camel && data.Camels < c.Value) ||
                                     (c.Key != Card.Camel && data.Hand.Count(h => h == c.Key) < c.Value)))
            {
                throw new InvalidOperationException("Invalid hand cards");
            }

            if (tableCardsToTrade.Any(c => OnTable.Count(t => t == c.Key) < c.Value))
            {
                throw new InvalidOperationException("Invalid table cards");
            }

            if (data.Hand.Count + hand.Count(c => c == Card.Camel) > 7)
            {
                throw new InvalidOperationException("You cannot have more than 7 cards at hand");
            }

            foreach (var card in hand)
            {
                data.TakeCard(card);
                OnTable.Add(card);
            }

            foreach (var card in table)
            {
                OnTable.Remove(card);
                data.GiveCard(card);
            }

            EnemyTurn = !EnemyTurn;
        }