示例#1
0
 private void DrawCards()
 {
     while (OnTable.Count < 5)
     {
         OnTable.Add(OnDeck.Pop());
     }
 }
示例#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;
        }
示例#3
0
        public void TakeCamels(User player)
        {
            var  data       = GetPlayerData(player, true);
            bool tookCamels = false;

            foreach (var card in OnTable.Where(c => c == Card.Camel).ToList())
            {
                OnTable.Remove(card);
                data.GiveCard(card);
                tookCamels = true;
            }

            if (!tookCamels)
            {
                throw new InvalidOperationException("No camels on the table");
            }

            DrawCards();

            EnemyTurn = !EnemyTurn;
        }
示例#4
0
        public void TakeCard(User player, Card selectedCard)
        {
            var data = GetPlayerData(player, true);

            if (selectedCard == Card.Camel)
            {
                throw new InvalidOperationException("Use TakeCamels instead");
            }

            if (data.Hand.Count() >= 7)
            {
                throw new InvalidOperationException("Current player already have 7 cards at hand");
            }

            if (!OnTable.Contains(selectedCard))
            {
                throw new InvalidOperationException("Selected card is not on the table");
            }

            OnTable.Remove(selectedCard);
            data.GiveCard(selectedCard);
            DrawCards();
            EnemyTurn = !EnemyTurn;
        }