Exemple #1
0
        public void Run()
        {
            DealOutCards();

            Player currentPlayer = DetermineStartingPlayer();

            while (FirstPlayerHasCard())
            {
                GetTable();
                var trick = new Trick();

                CurrentTrickPlay(currentPlayer, trick);
                GameView.TrickCards(trick);

                DetermineTrickWinning(trick, ref currentPlayer);

                Console.ReadLine();

                GetAllDiscardedCards();

                Console.Clear();
            }

            if (Is100PointsReached())
            {
                GetFinalTable();
                EvaluateWinner();
                BeginNewGame();
            }
            else
            {
                GetTable();
                BeginNewRound();
            }
        }
Exemple #2
0
        private void DetermineTrickWinning(Trick trick, ref Player currentPlayer)
        {
            Card trickWinningCard = DetermineTrickWinningCard(trick);

            currentPlayer = DetermineTrickWinningPlayer(trick, currentPlayer, trickWinningCard);

            GameView.TrickWinner(currentPlayer, trickWinningCard);
        }
Exemple #3
0
 private Player DetermineTrickWinningPlayer(Trick trick, Player currentPlayer, Card trickWinningCard)
 {
     foreach (var player in game.Players)
     {
         if (player.Discarded.Contains(trickWinningCard))
         {
             currentPlayer = player;
             player.TakenTricks.Add(trick);
             player.TakenCards();
         }
     }
     return(currentPlayer);
 }
Exemple #4
0
        public static Card DetermineTrickWinningCard(Trick trick)
        {
            var trickWinningCard = trick.FirstCard;

            foreach (var card in trick.Cards)
            {
                if (card.Suit == trickWinningCard.Suit && card.Rank > trickWinningCard.Rank)
                {
                    trickWinningCard = card;
                }
            }
            return(trickWinningCard);
        }
Exemple #5
0
        private static bool UpdateChosenCard(Trick trick, Player player, Player currentPlayer, int number)
        {
            bool askHumanForChoice;
            var  chosenCard = player.SortedHand()[number - 1];

            trick.Cards.Add(chosenCard);
            player.Discard(chosenCard);
            askHumanForChoice = false;
            Console.WriteLine(String.Format("{0} plays {1}", player.Name, chosenCard));
            if (player == currentPlayer)
            {
                trick.FirstCard = chosenCard;
            }
            return(askHumanForChoice);
        }
Exemple #6
0
        public static void ForHuman(Trick trick, Player player, Player currentPlayer)
        {
            var askHumanForChoice = true;

            while (askHumanForChoice)
            {
                Console.WriteLine("\nCHOOSE ONE CARD FROM YOUR HAND, PLEASE\n");
                var chosenNumber = Console.ReadLine();

                if (YouAreFirstPlayer(player, currentPlayer))
                {
                    if (IsInputCorrect(player, chosenNumber, out int number))
                    {
                        askHumanForChoice = UpdateChosenCard(trick, player, currentPlayer, number);
                    }
                    else
                    {
                        Console.WriteLine("Type correct number");
                    }
                }
                else // you are not the first player
                {
                    if (IsCardInMatchingSuitInPlayerHand(trick, player)) // you have card in matching suit
                    {
                        if (IsInputAndSuitCorrect(trick, player, chosenNumber, out int number)) // check input type and card suit
                        {
                            askHumanForChoice = UpdateChosenCard(trick, player, currentPlayer, number);
                        }
                        else
                        {
                            GameView.WrongSuitStatement();
                        }
                    }
                    else // you don't have card in matching suit
                    {
                        if (IsInputCorrect(player, chosenNumber, out int number))
                        {
                            askHumanForChoice = UpdateChosenCard(trick, player, currentPlayer, number);
                        }
                        else
                        {
                            Console.WriteLine("Type correct number");
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void CurrentTrickPlay(Player currentPlayer, Trick trick)
        {
            var playerIndex = game.Players.IndexOf(currentPlayer);

            var playedCardCounter = 0;

            while (playedCardCounter < game.Players.Count)
            {
                if (IsPlayerHuman(playerIndex))
                {
                    PlayingCard.ForHuman(trick, game.Players[playerIndex], currentPlayer);
                }
                else
                {
                    PlayingCard.ForComputer(trick, game.Players[playerIndex], currentPlayer);
                }
                if (playerIndex == game.Players.Count - 1)
                {
                    playerIndex = -1;
                }
                playerIndex++;
                playedCardCounter++;
            }
        }
Exemple #8
0
 public static void TrickCards(Trick trick)
 {
     Console.WriteLine(String.Format("Current trick: {0}", String.Join(" ", trick.Cards)));
 }
Exemple #9
0
 private static bool HaveHigherCardInMatchingSuitNotHeartsOrSpades(Trick trick, Player player, string currentSuit)
 {
     return(HaveMatchingSuit(player, currentSuit) && HighestCardInMatchingSuit(player, currentSuit).Rank > trick.FirstCard.Rank &&
            currentSuit != GameView.Suit("spades") && currentSuit != GameView.Suit("hearts") && (trick.Cards.Select(z => z.ValueInTrick).Sum() < 1));
 }
Exemple #10
0
 private static bool IsInputAndSuitCorrect(Trick trick, Player player, string chosenNumber, out int number)
 {
     return(Int32.TryParse(chosenNumber, out number) && (number <= player.Hand.Count()) && (player.SortedHand()[number - 1].Suit == trick.FirstCard.Suit));
 }
Exemple #11
0
 private static bool IsCardInMatchingSuitInPlayerHand(Trick trick, Player player)
 {
     return(player.Hand.Where(z => z.Suit == trick.FirstCard.Suit).FirstOrDefault() != null);
 }
Exemple #12
0
        public static void ForComputer(Trick trick, Player player, Player currentPlayer)
        {
            Card chosenComputerCard;

            if (player == currentPlayer)        //rozpoczyna lewę
            {
                if (AtLeastOneHeartWasPlayed()) //rozpoczyna lewę i kiery zostały już zagrane w tej rundzie
                {
                    chosenComputerCard = LowestCard(player);
                    trick.FirstCard    = chosenComputerCard;
                }
                else
                {
                    if (AtLeastOneNotHeartInHand(player)) // rozpoczyna lewę, kiery nie zostały jeszcze zagrane i MA na ręce inne kolory niż kier
                    {
                        chosenComputerCard = LowestCardNotHeart(player);
                        trick.FirstCard    = chosenComputerCard;
                    }
                    else // rozpoczyna lewę, kiery nie zostały jeszcze zagrane, ale ma tylko kiery
                    {
                        chosenComputerCard = LowestCard(player);
                        trick.FirstCard    = chosenComputerCard;
                    }
                }
            }
            else // nie rozpoczyna lewy
            {
                trick.FirstCard = GameController.DetermineTrickWinningCard(trick);
                var currentSuit = trick.FirstCard.Suit;

                if (HaveHigherCardInMatchingSuitNotHeartsOrSpades(trick, player, currentSuit)) // nie rozpoczyna lewy i ma wyższą kartę w obowiązującym kolorze, (nie pik i nie kier!)
                {
                    chosenComputerCard = HighestCardInMatchingSuit(player, currentSuit);
                }
                else if (HaveMatchingSuit(player, currentSuit)) //nie rozpoczyna lewy, ma tylko niższe karty w obowiązującym kolorze
                {
                    chosenComputerCard = LowestCardInMatchingSuit(player, currentSuit);
                }
                else // nie rozpoczyna lewy, nie ma kart w obowiązującym kolorze
                {
                    if (HighestValueCardSpade(player) != null) //ma Asa, Króla lub Damę pik
                    {
                        chosenComputerCard = HighestValueCardSpade(player); //zagrywa w kolejności Damę, Króla lub Asa pik
                    }
                    else if (HighestCardHeart(player) != null)              // Ma kiery
                    {
                        chosenComputerCard = HighestCardHeart(player);      // zagrywa najwyższego kiera
                    }
                    else
                    {
                        chosenComputerCard = HighestCard(player); // zagrywa najwyższą kartę
                    }
                }
            }
            trick.Cards.Add(chosenComputerCard);
            player.Discard(chosenComputerCard);

            Game.AllPlayedCards.Add(chosenComputerCard);

            GameView.ChosenComputerCard(player, chosenComputerCard);
        }