예제 #1
0
        public virtual bool TakeCardFromTheTable(Card selectedCard, Table table)
        {
            bool buildedCardOwner = false;

            Table cardsSelectedFromTheTable = SelectCardsFromTheTable(table);

            // TODO: when I have a builded card on the table, I cant create another builded card if
            // I do not have any card to take the first builded card
            if (!ValidateTakenCards(cardsSelectedFromTheTable, selectedCard) &&
                table.BuildedCards != null &&
                table.BuildedCards.Any(b => b.Owner == this.Name))
            {
                ConsoleOutput.IfYouDontHaveMoreMoveYouMustCaptureYourBuildingCard();

                buildedCardOwner = true;
            }
            else if (!ValidateTakenCards(cardsSelectedFromTheTable, selectedCard))
            {
                ConsoleOutput.YouJustLostYourCardBecauseItIsInvalid();
                ThrowTheCardToTheTable(selectedCard, table);
            }
            else
            {
                if (cardsSelectedFromTheTable.Cards != null)
                {
                    table.Cards.RemoveAll(c => cardsSelectedFromTheTable.Cards.Contains(c));

                    CapturedCards.AddRange(cardsSelectedFromTheTable.Cards);
                }

                if (cardsSelectedFromTheTable.BuildedCards != null)
                {
                    table.BuildedCards.RemoveAll(c => cardsSelectedFromTheTable.BuildedCards.Contains(c));

                    CapturedCards.AddRange(cardsSelectedFromTheTable.BuildedCards
                                           .SelectMany(b => b.BuildedCards)
                                           .Distinct());
                }

                Cards.RemoveAll(c => c.Name == selectedCard.Name);

                CapturedCards.Add(selectedCard);

                ConsoleOutput.ShowTableCards(table);
                ConsoleOutput.ShowCapturedCards(this);
            }

            return(buildedCardOwner);
        }
예제 #2
0
파일: Computer.cs 프로젝트: jjuanbj/Casino
        public override bool TakeCardFromTheTable(Card selectedCard, Table table)
        {
            List <Card> cardList = new List <Card>();

            cardList.Add(selectedCard);

            // Check why EligibleCards can be size 0
            var selectedCardsFromTable = EligibleCards.Count == 0 ? cardList : EligibleCards.Where(e => e.Key.Name.Equals(selectedCard.Name))
                                         .FirstOrDefault().Value
                                         .ToList();

            selectedCardsFromTable.ForEach(c => CapturedCards.Add(c));

            selectedCardsFromTable.ForEach(c => table.Cards.Remove(c));

            Cards.RemoveAll(c => c.Name == selectedCard.Name);

            CapturedCards.Add(selectedCard);

            EligibleCards = new Dictionary <Card, List <Card> >();

            return(false);
        }