Пример #1
0
        private Card SelectYourCard()
        {
            ConsoleOutput.SelectOneCardByIndexNumber(this);

            string cardNumber = "";

            Card card = null;

            while (string.IsNullOrEmpty(cardNumber))
            {
                cardNumber = Console.ReadLine().Trim();

                if (!string.IsNullOrEmpty(cardNumber) &&
                    cardNumber.All(char.IsDigit) &&
                    Enumerable.Range((int)General.Zero, Cards.Count).Contains(int.Parse(cardNumber)))
                {
                    ConsoleOutput.YouSelected(Cards, cardNumber);

                    card = new Card(Cards.ElementAt(int.Parse(cardNumber)).Rank, Cards.ElementAt(int.Parse(cardNumber)).Suit);
                }
                else
                {
                    ConsoleOutput.TypeValidCardNumber();

                    cardNumber = "";

                    continue;
                }
            }
            return(card);
        }
Пример #2
0
        private Rank SelectBuildingRank(Card selectedCard)
        {
            ConsoleOutput.SelectYourBuildingRank(this, selectedCard);

            string cardNumber = "";

            Card buildingRankCard = null;

            int cardsCount = this.Cards.Count - 1;

            while (string.IsNullOrEmpty(cardNumber))
            {
                cardNumber = Console.ReadLine().Trim();

                if (!string.IsNullOrEmpty(cardNumber) &&
                    cardNumber.All(char.IsDigit) &&
                    Enumerable.Range((int)General.Zero, cardsCount).Contains(int.Parse(cardNumber)))
                {
                    List <Card> playerCardsWithoutSelectedCard = new List <Card>(Cards.Where(c => c.Name != selectedCard.Name));

                    buildingRankCard = new Card(playerCardsWithoutSelectedCard.ElementAt(int.Parse(cardNumber)).Rank,
                                                playerCardsWithoutSelectedCard.ElementAt(int.Parse(cardNumber)).Suit);

                    if (Cards.Any(c => c.Name == buildingRankCard.Name))
                    {
                        ConsoleOutput.YouSelected(playerCardsWithoutSelectedCard.ToList(), cardNumber);
                    }
                }
                else
                {
                    ConsoleOutput.TypeValidCardNumber();

                    cardNumber = "";

                    continue;
                }
            }

            return(buildingRankCard.Rank);
        }
Пример #3
0
        private Table SelectCardsFromTheTable(Table table)
        {
            int cardsOnTheTable = ConsoleOutput.WhichCardWouldYouLikeToTakeFromTheTable(table);

            ConsoleOutput.PressFWhenFinished();

            string cardRank = "";

            Table cardsSelectedFromTheTable = new Table
            {
                Cards        = new List <Card>(),
                BuildedCards = new List <BuildedCard>()
            };

            while (cardRank != Keyboard.UPPERCASE_F && cardRank != Keyboard.LOWERCASE_F)
            {
                cardRank = Console.ReadLine().Trim();

                if (string.IsNullOrEmpty(cardRank))
                {
                    ConsoleOutput.TypeValidCardNumber();

                    continue;
                }
                else if (cardRank != Keyboard.UPPERCASE_F &&
                         cardRank != Keyboard.LOWERCASE_F &&
                         cardRank.All(char.IsDigit) &&
                         Enumerable.Range((int)General.Zero, cardsOnTheTable).Contains(int.Parse(cardRank)))
                {
                    bool isBuildedCard = ConsoleOutput.YouSelected(table, cardRank);

                    if (!isBuildedCard)
                    {
                        cardsSelectedFromTheTable.Cards.Add(table.Cards.ElementAt(int.Parse(cardRank)));
                    }
                    else
                    {
                        int buildedCardsSelected = int.Parse(cardRank) - table.Cards.Count;

                        cardsSelectedFromTheTable.BuildedCards.Add(table.BuildedCards.ElementAt(buildedCardsSelected));
                    }
                }
                else if (cardRank == Keyboard.UPPERCASE_F || cardRank == Keyboard.LOWERCASE_F)
                {
                    break;
                }
                else
                {
                    ConsoleOutput.TypeValidCardNumber();

                    cardRank = "";

                    continue;
                }
            }

            if (!cardsSelectedFromTheTable.Cards.Any())
            {
                cardsSelectedFromTheTable.Cards = null;
            }

            if (!cardsSelectedFromTheTable.BuildedCards.Any())
            {
                cardsSelectedFromTheTable.BuildedCards = null;
            }

            return(cardsSelectedFromTheTable);
        }