Пример #1
0
        public static void PlayCard(PlayingCardGame game, int i)
        {
            if (game.playedCards.Count != 0)
            {
                game.DisplayPlayedCards();
            }
            Console.WriteLine($"It's {game.Players[i].Name}s turn. Pick a card to play:\n");
            Console.WriteLine("Press enter to see hand:\n");
            Console.ReadKey(true);
            game.Players[i].PrintPlayersCards();
            bool validIdofCard = false;

            while (!validIdofCard)
            {
                var idOfcardToPlay = InputControl.ControlIntInput(1, 5);

                if (game.Players[i].DealtHand.Any(x => x.Id == idOfcardToPlay))
                {
                    var cardToPlay = game.Players[i].DealtHand.Single(x => x.Id == idOfcardToPlay);
                    if (game.playedCards.Count == 0)
                    {
                        game.playedCards.Add((game.Players[i].Name, cardToPlay));
                        game.Players[i].PlayCard(idOfcardToPlay);
                        validIdofCard = true;
                    }
                    else if (game.playedCards.Count % 2 == 0 || game.playedCards[game.playedCards.Count - 1].Item2.Suit == cardToPlay.Suit || !game.Players[i].DealtHand.Any(x => x.Suit == game.playedCards[game.playedCards.Count - 1].Item2.Suit))
                    {
                        game.playedCards.Add((game.Players[i].Name, cardToPlay));
                        game.Players[i].PlayCard(idOfcardToPlay);
                        validIdofCard = true;
                    }
                    else
                    {
                        Console.WriteLine("Wrong Suit. Chose a valid card.");
                    }
                }
                else
                {
                    Console.WriteLine("Input valid id from remaining card");
                }
            }
            Console.Clear();
        }
Пример #2
0
        public static void ChangeCards(PlayingCardGame game)
        {
            for (int i = 0; i < game.Players.Count; i++)
            {
                Console.WriteLine($"{game.Players[i].Name}, press enter to see your hand: ");
                Console.ReadLine();
                game.Players[i].PrintPlayersCards();
                List <int> idOfCardsToChange = new List <int>();
                Console.WriteLine($"{game.Players[i].Name}: Input nr of cards you like to change:");
                int nrOfCardToChange = InputControl.ControlIntInput(0, 5);

                for (int y = 0; y < nrOfCardToChange; y++)
                {
                    int  idOfCardToChange = 0;
                    bool input            = false;
                    while (!input)
                    {
                        Console.WriteLine("Input id of card you like to change:");

                        try
                        {
                            idOfCardToChange = int.Parse(Console.ReadLine());
                            if (!idOfCardsToChange.Any(x => x == idOfCardToChange))
                            {
                                idOfCardsToChange.Add(idOfCardToChange);
                                input = true;
                            }
                            else
                            {
                                Console.WriteLine("Card doesn't exist!");
                            }
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Invalid Id");
                        }
                    }
                }

                game.Players[i].ChangeCard(idOfCardsToChange, game);
                Console.Clear();
            }
        }