Beispiel #1
0
        /// <summary>
        /// Simulates one round of the game.
        /// </summary>
        /// <param name="player1"></param>
        /// <param name="player2"></param>
        /// <param name="deck"></param>
        public void SimulateRound(Player player1, Player player2, CardHandler deck)
        {
            UserInterface ui = new UserInterface();
            Card          player1Card;
            Card          player2Card;
            string        attribute;
            string        winnerName;

            if (player1.wonBefore == true)
            {
                ui.PrintStartingPlayer(player1);
                ui.PrintGameStatus(player1, player2);
                while (true)
                {
                    try
                    {
                        player1Card = deck.GetCardByName(player1.hand, ui.AskCardFromHand(player1));
                        attribute   = ui.AskAttribute();
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }
                while (true)
                {
                    try
                    {
                        player2Card = deck.GetCardByName(player2.hand, ui.AskCardFromHand(player2, player1Card, attribute));
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }
                //Puts the played cards in the table object
                Table round = new Table(player1Card, player2Card);
                winnerName = round.GetRoundWinner(player1, player2, attribute).name;
                deck.RoundEndDeal(player1Card, player1);
                deck.RoundEndDeal(player2Card, player2);
            }
            else
            {
                ui.PrintStartingPlayer(player2);
                ui.PrintGameStatus(player1, player2);
                while (true)
                {
                    try
                    {
                        player2Card = deck.GetCardByName(player2.hand, ui.AskCardFromHand(player2));
                        attribute   = ui.AskAttribute();
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }
                while (true)
                {
                    try
                    {
                        player1Card = deck.GetCardByName(player1.hand, ui.AskCardFromHand(player1, player2Card, attribute));
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }
                Table round = new Table(player1Card, player2Card);
                winnerName = round.GetRoundWinner(player1, player2, attribute).name;
                deck.RoundEndDeal(player1Card, player1);
                deck.RoundEndDeal(player2Card, player2);
            }
            if (winnerName == player1.name)
            {
                player1.wonBefore = true;
                player1.wonHands++;
                player2.wonBefore = false;
            }
            else
            {
                player2.wonBefore = true;
                player2.wonHands++;
                player1.wonBefore = false;
            }

            ui.PrintWinner(winnerName);
        }
Beispiel #2
0
        /****
        *  AI starts here
        ****/
        /// <summary>
        /// Plays one round against the computer.
        /// </summary>
        /// <param name="player1"></param>
        /// <param name="ai"></param>
        /// <param name="deck"></param>
        public void SimulateRoundWithAI(Player player1, AI ai, CardHandler deck)
        {
            //This is for debug purposes
            Console.WriteLine("DEBUG: AI handje: \n");
            foreach (Card card in ai.hand)
            {
                Console.WriteLine(card);
            }
            Console.ReadKey();
            //until this point

            UserInterface ui = new UserInterface();
            Card          player1Card;
            Card          aiCard;
            string        attribute;
            string        winnerName;

            //Gets the player who won the last round so that player will start the round.
            if (player1.wonBefore == true)
            {
                ui.PrintStartingPlayer(player1);
                ui.PrintGameStatus(player1, ai);

                while (true)
                {
                    try
                    {
                        player1Card = deck.GetCardByName(player1.hand, ui.AskCardFromHand(player1));
                        attribute   = ui.AskAttribute();
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }

                aiCard = ai.ChooseTheRightCardForAI(player1Card, attribute);
                ui.PrintAIChosenCard(aiCard);

                Table round = new Table(player1Card, aiCard);
                winnerName = round.GetRoundWinner(player1, ai, attribute).name;
                deck.RoundEndDeal(player1Card, player1);
                deck.RoundEndDeal(aiCard, ai);
            }
            else
            {
                ui.PrintStartingPlayer(ai);
                ui.PrintGameStatus(player1, ai);

                aiCard    = ai.ChooseCardToPlay();
                attribute = ai.ReturnBestAttribute(aiCard);

                while (true)
                {
                    try
                    {
                        player1Card = deck.GetCardByName(player1.hand, ui.AskCardFromHand(player1, aiCard, attribute));
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("\nWrong input, please try again...\n");
                        Thread.Sleep(1500);
                        continue;
                    }
                }
                Table round = new Table(player1Card, aiCard);
                winnerName = round.GetRoundWinner(player1, ai, attribute).name;
                deck.RoundEndDeal(player1Card, player1);
                deck.RoundEndDeal(aiCard, ai);
            }

            if (winnerName == player1.name)
            {
                player1.wonBefore = true;
                player1.wonHands++;
                ai.wonBefore = false;
            }
            else
            {
                ai.wonBefore = true;
                ai.wonHands++;
                player1.wonBefore = false;
            }

            ui.PrintWinner(winnerName);
        }