Пример #1
0
        public override void Play(Table table)
        {
            string actionSelected = ChooseOneAction(table);

            Console.WriteLine("Action selected: " + actionSelected); // Test

            SelectedCard = SelectYourCard(actionSelected, table);

            Console.WriteLine("Selected card: " + this.SelectedCard.Name); // Test

            switch (actionSelected)
            {
            case Keyboard.ONE:
                ThrowTheCardToTheTable(this.SelectedCard, table);
                Console.WriteLine("ThrowTheCardToTheTable");     // Test
                break;

            case Keyboard.TWO:
                TakeCardFromTheTable(this.SelectedCard, table);
                Console.WriteLine("TakeCardFromTheTable");     // Test
                break;

            case Keyboard.THREE:
                CreateSingleBuildedCards(this.SelectedCard, table);
                break;

            case Keyboard.FOUR:
                CreateMultipleBuildedCards(this.SelectedCard, table);
                break;
            }

            ConsoleOutput.ShowTableCards(table);
        }
Пример #2
0
        public virtual void ThrowTheCardToTheTable(Card selectedCard, Table table)
        {
            table.Cards.Add(selectedCard);

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

            ConsoleOutput.ShowTableCards(table);

            if (Cards.Any())
            {
                ConsoleOutput.ShowPlayerCards(this);
            }
        }
Пример #3
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);
        }
Пример #4
0
        public virtual void CreateMultipleBuildedCards(Card selectedCard, Table table)
        {
            Rank buildingRankCard = SelectBuildingRank(selectedCard);

            Table cardsSelectedFromTheTable = SelectCardsFromTheTable(table);

            List <Rank> ranksFromTheTable = new List <Rank>
            {
                selectedCard.Rank
            };

            bool THERE_ARE_CARDS         = cardsSelectedFromTheTable.Cards != null;
            bool THERE_ARE_BUILDED_CARDS = cardsSelectedFromTheTable.BuildedCards != null;

            if (THERE_ARE_CARDS)
            {
                cardsSelectedFromTheTable.Cards.ForEach(c => ranksFromTheTable.Add(c.Rank));
            }

            if (THERE_ARE_BUILDED_CARDS)
            {
                cardsSelectedFromTheTable.BuildedCards.ForEach(b => ranksFromTheTable.Add(b.BuildedCardsRank));
            }

            if ((ranksFromTheTable.Sum(r => Convert.ToInt32(r)) % Convert.ToInt32(buildingRankCard) == 0 ||
                 buildingRankCard == Rank.Ace) && ValidateMultipleBuildedCardsWithAce(ranksFromTheTable))
            {
                BuildedCard buildedCard = new BuildedCard
                {
                    BuildedCardsRank = buildingRankCard,
                    IsMultiple       = true,
                    Owner            = this.Name,
                    Name             = CardUtils.CreateRankName(buildingRankCard),
                    BuildedCards     = new List <Card>()
                };
                buildedCard.BuildedCards.Add(selectedCard);

                if (THERE_ARE_CARDS)
                {
                    cardsSelectedFromTheTable.Cards.ForEach(c => buildedCard.BuildedCards.Add(c));
                    cardsSelectedFromTheTable.Cards.ForEach(item => table.Cards
                                                            .RemoveAll(b => b.Rank == item.Rank));
                }

                if (THERE_ARE_BUILDED_CARDS)
                {
                    foreach (List <Card> card in cardsSelectedFromTheTable.BuildedCards.Select(c => c.BuildedCards))
                    {
                        buildedCard.BuildedCards.AddRange(card);
                    }

                    table.BuildedCards.RemoveAll(b => cardsSelectedFromTheTable.BuildedCards.Contains(b));
                }

                if (table.BuildedCards == null)
                {
                    table.BuildedCards = new List <BuildedCard>();
                    table.BuildedCards.Add(buildedCard);
                }
                else
                {
                    table.BuildedCards.Add(buildedCard);
                }

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

                ConsoleOutput.ShowTableCards(table);
            }
            else
            {
                ConsoleOutput.YouJustLostYourCardBecauseItIsInvalid();

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

                ThrowTheCardToTheTable(selectedCard, table);
            }
        }
Пример #5
0
        public virtual void CreateSingleBuildedCards(Card selectedCard, Table table)
        {
            Rank buildingRankCard = SelectBuildingRank(selectedCard);

            var cardsSelectedFromTheTable = SelectCardsFromTheTable(table);

            bool tableBuildedCardsWasModified = false;

            if (cardsSelectedFromTheTable.BuildedCards == null &&
                ((buildingRankCard != Rank.Ace &&
                  cardsSelectedFromTheTable.Cards.Sum(r => Convert.ToInt32(r.Rank))
                  + Convert.ToInt32(selectedCard.Rank) == Convert.ToInt32(buildingRankCard)) ||
                 (buildingRankCard == Rank.Ace &&
                  cardsSelectedFromTheTable.Cards.Sum(r => Convert.ToInt32(r.Rank))
                  + Convert.ToInt32(selectedCard.Rank) == Constants.ACE_MAX_VALUE)))
            {
                Cards.RemoveAll(c => c.Name == selectedCard.Name);

                table.Cards.RemoveAll(c => cardsSelectedFromTheTable.Cards.Contains(c));

                cardsSelectedFromTheTable.Cards.Add(selectedCard);

                BuildedCard buildedCard = new BuildedCard
                {
                    BuildedCards     = cardsSelectedFromTheTable.Cards,
                    BuildedCardsRank = buildingRankCard,
                    Owner            = this.Name,
                    Name             = CardUtils.CreateRankName(buildingRankCard)
                };

                if (table.BuildedCards == null)
                {
                    buildedCard.IsMultiple = false;
                }
                else if (table.BuildedCards.Any(c => c.BuildedCardsRank == buildedCard.BuildedCardsRank))
                {
                    table.BuildedCards.Where(c => c.BuildedCardsRank == buildedCard.BuildedCardsRank)
                    .FirstOrDefault().IsMultiple = true;

                    table.BuildedCards.Where(c => c.BuildedCardsRank == buildedCard.BuildedCardsRank)
                    .FirstOrDefault().BuildedCards
                    .AddRange(buildedCard.BuildedCards);

                    tableBuildedCardsWasModified = true;
                }

                if (table.BuildedCards == null)
                {
                    table.BuildedCards = new List <BuildedCard>
                    {
                        buildedCard
                    };
                }
                else if (table.BuildedCards != null && !tableBuildedCardsWasModified)
                {
                    table.BuildedCards.Add(buildedCard);
                }

                ConsoleOutput.ShowTableCards(table);
            }
            else if (cardsSelectedFromTheTable.BuildedCards != null &&
                     cardsSelectedFromTheTable.Cards == null &&
                     ((buildingRankCard != Rank.Ace &&
                       cardsSelectedFromTheTable.BuildedCards.Sum(r => Convert.ToInt32(r.BuildedCardsRank))
                       + Convert.ToInt32(selectedCard.Rank) == Convert.ToInt32(buildingRankCard)) ||
                      buildingRankCard == Rank.Ace &&
                      cardsSelectedFromTheTable.BuildedCards.Sum(r => Convert.ToInt32(r.BuildedCardsRank))
                      + Convert.ToInt32(selectedCard.Rank) == Convert.ToInt32(Constants.ACE_MAX_VALUE)) && !tableBuildedCardsWasModified)
            {
                cardsSelectedFromTheTable.BuildedCards.ForEach(item => table.BuildedCards
                                                               .RemoveAll(b => b.BuildedCardsRank == item.BuildedCardsRank));
                cardsSelectedFromTheTable.BuildedCards.FirstOrDefault().IsMultiple       = false;
                cardsSelectedFromTheTable.BuildedCards.FirstOrDefault().BuildedCardsRank = buildingRankCard;
                cardsSelectedFromTheTable.BuildedCards.FirstOrDefault().Owner            = this.Name;
                cardsSelectedFromTheTable.BuildedCards.FirstOrDefault().BuildedCards
                .Add(selectedCard);

                table.BuildedCards.Add(cardsSelectedFromTheTable.BuildedCards.FirstOrDefault());

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

                ConsoleOutput.ShowTableCards(table);
            }
            else
            {
                ConsoleOutput.YouJustLostYourCardBecauseItIsInvalid();
                ThrowTheCardToTheTable(selectedCard, table);
            }
        }