private void UpdatePlayerHands(Player player)
 {
     player.HandsMade++;
     foreach (Card card in cardsOnTable.Keys)
     {
         player.TotalUsedCards.Add(card);
     }
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            roundFont = Content.Load<SpriteFont>("Palatino Linotype");
            menuFont = Content.Load<SpriteFont>("Old English Text MT");
            titleFont = Content.Load<SpriteFont>("Broadway");
            menuFont = Content.Load<SpriteFont>("Bookman Old Style");
            InstructionsFont = Content.Load<SpriteFont>("Broadway");
            //menuBackground = Content.Load<Texture2D>(@"Images/Menus/BackGround");
            AboutFont = Content.Load<SpriteFont>("Matura");
            Random random = new Random();
            theMenu = new Menu(titleFont, menuFont);

            string name;

            while (PlayerNames.Count < 3)
            {
                name = listOfNames[random.Next(listOfNames.Count - 1)];
                if (!PlayerNames.Contains(name))
                {
                    PlayerNames.Add(name);
                }
            }

            player2 = new Player();
            player2.PlayerNumber = PlayerIndex.Two;
            player2.Name = PlayerNames[0];

            player3 = new Player();
            player3.PlayerNumber = PlayerIndex.Three;
            player3.Name = PlayerNames[1];

            player4 = new Player();
            player4.PlayerNumber = PlayerIndex.Four;
            player4.Name = PlayerNames[2];

            CalculatePlayerCardPositions();

            StartNewGame();

            StringBuilder key = new StringBuilder();
            // add items to the menu
            for (int index = 0; index < 15; index++)
            {
                for (int indexString = 0; indexString < theMenu.MenuStrings.Count; indexString++)
                {
                    key = key.Remove(0, key.Length);
                    key.Append(theMenu.MenuStrings[indexString]);
                    key.Append(index);
                    theMenu.MenuScreens.Add(key.ToString(), Content.Load<Texture2D>(@"Images/Menus/" + key));
                }
            }

            Texture2D backgroundWood = Content.Load<Texture2D>(@"Images/BackgroundWood2");
            theMenu.BackgroundWood = backgroundWood;
            theMenu.MainScreen = Content.Load<Texture2D>(@"Images/Menus/MainScreen");
            theMenu.BackgroundRed = Content.Load<Texture2D>(@"Images/BackgroundRed");
            theMenu.BackgroundOrange = Content.Load<Texture2D>(@"Images/BackgroundGrayScale");
        }
 private Card PlaceCard(Player player)
 {
     Card card;
     player.CardsOnTable.Clear();
     foreach (Card cardKey in cardsOnTable.Keys)
     {
         player.CardsOnTable.Add(cardKey);
     }
     card = player.PlaceCard();
     card.Position = new Vector2(player.CardPosition.X, player.CardPosition.Y);
     cardsOnTable.Add(card, player.PlayerNumber);
     cardsOnTableList.Add(card);
     return card;
 }
        private Player GetPlayerWithMaxScore()
        {
            Player[] players = { player2, player3, player4 };

            Player maxScore = new Player();
            maxScore.TotalScore = -1;

            // we need to find the player with the max hands so that we can select his
            // trump
            for (int index = 0; index < players.Length; index++)
            {
                if (players[index].TotalScore > maxScore.TotalScore)
                {
                    maxScore = players[index];
                }
            }

            if (TotalScore > maxScore.TotalScore)
            {
                return null; // null will refer to player 1
            }
            else
            {
                return maxScore;
            }
        }
        private Player GetPlayerWithMaximumHands()
        {
            Player[] players = { player2, player3, player4 };

            Player maxHands = new Player();
            maxHands.HandsStated = -1;

            // we need to find the player with the max hands so that we can select his
            // trump
            for (int index = 0; index < players.Length; index++)
            {
                if (players[index].HandsStated > maxHands.HandsStated)
                {
                    maxHands = players[index];
                }
            }

            if (deck.HandsStated > maxHands.HandsStated)
            {
                return null; // null will refer to player 1
            }
            else
            {
                // we now check if the multiple players have stated the same hands
                List<PlayerIndex> playersWithEqualHands = new List<PlayerIndex>();

                // we add all players to the list who have stated equal hands
                if (deck.HandsStated == maxHands.HandsStated)
                {
                    playersWithEqualHands.Add(PlayerIndex.One);
                }

                if (player2.HandsStated == maxHands.HandsStated)
                {
                    playersWithEqualHands.Add(PlayerIndex.Two);
                }
                if (player3.HandsStated == maxHands.HandsStated)
                {
                    playersWithEqualHands.Add(PlayerIndex.Three);
                }
                if (player4.HandsStated == maxHands.HandsStated)
                {
                    playersWithEqualHands.Add(PlayerIndex.Four);
                }
                int firstPlayer = (int)playerToStart;
                PlayerIndex playerToState = playerToStart;
                bool playerFound = false;
                while (true)
                {
                    // we now find the first player who stated the maximum hands
                    // the player number will be incremented starting with 'playerToStart'
                    for (int index = 0; index < playersWithEqualHands.Count; index++)
                    {
                        if (firstPlayer == (int)playersWithEqualHands[index])
                        {
                            playerToState = playersWithEqualHands[index];
                            playerFound = true;
                            break;
                        }
                    }
                    if (playerFound)
                    {
                        break;
                    }
                    firstPlayer++;
                    if (firstPlayer > 3)
                    {
                        firstPlayer = 0;
                    }
                }

                switch (playerToState)
                {
                    case PlayerIndex.Four:
                        maxHands = player4;
                        break;
                    case PlayerIndex.One:
                        maxHands = null;
                        break;
                    case PlayerIndex.Three:
                        maxHands = player3;
                        break;
                    case PlayerIndex.Two:
                        maxHands = player2;
                        break;
                    default:
                        break;
                }
                playerToStart = playerToState;
                return maxHands;
            }
        }
        private void CompareHandsAndSetTrump()
        {
            Player[] players = { player2, player3, player4 };

            Player maxHands = new Player();
            maxHands.HandsStated = -1;

            for (int index = 0; index < players.Length; index++)
            {
                if (players[index].HandsStated > maxHands.HandsStated)
                {
                    maxHands = players[index];
                }
            }
            Suit trumpSuit = Suit.Unspecified;

            if (deck.HandsStated > maxHands.HandsStated)
            {
                trumpSuit = deck.Trump;
                HandSummary.Add(name + " stated the maximum hands i.e. " + deck.HandsStated + " hands.");
                HandSummary.Add("Hence, " + name + " chose the trump which is " + trumpSuit + ".");
            }
            else
            {
                trumpSuit = maxHands.Trump;
                HandSummary.Add(maxHands.Name + " stated the maximum hands i.e. " + maxHands.HandsStated + " hands.");
                HandSummary.Add("Hence, " + maxHands.Name + " chose the trump which is " + trumpSuit + ".");
            }

            deck.Trump = trumpSuit;
            player2.Trump = trumpSuit;
            player3.Trump = trumpSuit;
            player4.Trump = trumpSuit;
        }
        private void CalculateHandsAndTrump(Player player, Suit trump)
        {
            OldTrump = trump;
            player.StateHandsAndTrump(ref OldTrump, ref NewTrump, ref OldHands, ref NewHands);
            // check if new hands is greater than old hands
            // if it is we need to check with the other players hands
            bool changeTrump = false;
            if (NewHands > OldHands)
            {
                changeTrump = true;

                for (int index = 0; index < HandsStated.Count; index++)
                {
                    if (NewHands < HandsStated[index])
                    {
                        changeTrump = false;
                    }
                }
            }

            if (changeTrump)
            {
                // the trump can be changed now
                HandSummary.Add(player.Name + " changed the trump to " + NewTrump + ".");
                deck.Trump = NewTrump;
                HandSummary.Add(player.Name + " stated " + NewHands + " hands.");
                player.SetTrumpAndInitialize(NewTrump);
                player.HandsStated = NewHands;
                HandsStated.Add(NewHands);
            }
            else
            {
                deck.Trump = OldTrump;
                HandSummary.Add(player.Name + " stated " + OldHands + " hands.");
                player.SetTrumpAndInitialize(OldTrump);
                player.HandsStated = OldHands;
                HandsStated.Add(OldHands);
            }
            SummaryShown = false;
        }