Display the highest scored word by each player at the end of the game

From TRCCompSci - AQA Computer Science
Revision as of 09:21, 24 May 2018 by Megan (talk | contribs) (Created page with "<h3>PlayGame</h3> <syntaxhighlight lang="C#"> private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PlayGame

private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize, int MaxHandSize, int MaxTilesPlayed, int NoOfEndOfTurnTiles)
        {
            //...

            //Declare PlayerOneHighestScore and PlayerTwoHighestScore as integers
            int PlayerOneHighestScore = 0;
            int PlayerTwoHighestScore = 0;

            //Declare PlayerOneHighestScoringWord and PlayerTwoHighestScoringWord as strings
            string PlayerOneHighestScoringWord = "";
            string PlayerTwoHighestScoringWord = "";
            
            //...

            while (PlayerOneTilesPlayed <= MaxTilesPlayed && PlayerTwoTilesPlayed <= MaxTilesPlayed && PlayerOneTiles.Length < MaxHandSize && PlayerTwoTiles.Length < MaxHandSize)
            {
                //Pass PlayerOneHighestScore and PlayerOneHighestScoringWord with reference
                HaveTurn("Player One", ref PlayerOneTiles, ref PlayerOneTilesPlayed, ref PlayerOneScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerOneHighestScore, ref PlayerOneHighestScoringWord);
                
                //...
                
                 //Pass PlayerTwoHighestScore and PlayerTwoHighestScoringWord with reference
                HaveTurn("Player Two", ref PlayerTwoTiles, ref PlayerTwoTilesPlayed, ref PlayerTwoScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerTwoHighestScore, ref PlayerTwoHighestScoringWord);
            }

            //...
            //Pass PlayerOneHighestScore, PlayerTwoHighestScore, PlayerOneHighestScoringWord and PlayerTwoHighestScoringWord
            DisplayWinner(PlayerOneScore, PlayerTwoScore, PlayerOneHighestScore, PlayerTwoHighestScore, PlayerOneHighestScoringWord, PlayerTwoHighestScoringWord);
        }

HaveTurn

 private static void HaveTurn(string PlayerName, ref string PlayerTiles, ref int PlayerTilesPlayed, ref int PlayerScore, Dictionary<char, int> TileDictionary, ref QueueOfTiles TileQueue, List<string> AllowedWords, int MaxHandSize, int NoOfEndOfTurnTiles, ref int HighestScore, ref string HighestScoringWord)
        {
            //...
            while (!ValidChoice)
            {
                Choice = GetChoice();
                if (Choice == "1")
                {
                    DisplayTileValues(TileDictionary, AllowedWords);
                }
                else if (Choice == "4")
                {
                    TileQueue.Show();
                }
                else if (Choice == "7")
                {
                    DisplayTilesInHand(PlayerTiles);
                }
                else if (Choice == "0")
                {
                    ValidChoice = true;
                    FillHandWithTiles(ref TileQueue, ref PlayerTiles, MaxHandSize);
                }
                else
                {
                    ValidChoice = true;
                    if (Choice.Length == 0)
                    {
                        ValidWord = false;
                    }
                    else
                    {
                        ValidWord = CheckWordIsInTiles(Choice, PlayerTiles);
                    }
                    if (ValidWord)
                    {
                        ValidWord = CheckWordIsValid(Choice, AllowedWords);
                        if (ValidWord)
                        {
                            //If the word is valid
                            Console.WriteLine();
                            Console.WriteLine("Valid word");
                            Console.WriteLine();     
                            //Pass HighestScore and HighestScoringWord into UpdateAfterAllowedWord with reference                       
                            UpdateAfterAllowedWord(Choice, ref PlayerTiles, ref PlayerScore, ref PlayerTilesPlayed, TileDictionary, AllowedWords, ref HighestScore, ref HighestScoringWord);
                            NewTileChoice = GetNewTileChoice();
                        }
                    }

                    //...
            }
        }

UpdateAfterAllowedWord

 private static void UpdateAfterAllowedWord(string Word, ref string PlayerTiles, ref int PlayerScore, ref int PlayerTilesPlayed, Dictionary<char, int> TileDictionary, List<string> AllowedWords, ref int HighestScore, ref string HighestScoringWord)
        {
            //...

            //If the score for the new word is higher than the current high score for a single word for that player
            if((GetScoreForWord(Word, TileDictionary)) > HighestScore)
            {
                //Set HighestScoringWord equal to the new word
                HighestScoringWord = Word;
                //Set HighestScore equal to the score for the new world
                HighestScore = GetScoreForWord(Word, TileDictionary);
            }
        }