Difference between revisions of "Display the highest scored word by each player at the end of the game"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "<h3>PlayGame</h3> <syntaxhighlight lang="C#"> private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize...")
 
 
Line 33: Line 33:
  
 
<h3>HaveTurn</h3>
 
<h3>HaveTurn</h3>
 +
Add HighestScore and HighestScoringWord as parameters of HaveTurn with reference.
 
<syntaxhighlight lang="C#">
 
<syntaxhighlight lang="C#">
 
  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)
 
  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)
Line 89: Line 90:
  
 
<h3>UpdateAfterAllowedWord</h3>
 
<h3>UpdateAfterAllowedWord</h3>
 +
Add HighestScore and HighestScoringWord as parameters of UpdateAfterAllowedWord with reference.
 
<syntaxhighlight lang="C#">
 
<syntaxhighlight lang="C#">
 
  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)
 
  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)
Line 102: Line 104:
 
                 HighestScore = GetScoreForWord(Word, TileDictionary);
 
                 HighestScore = GetScoreForWord(Word, TileDictionary);
 
             }
 
             }
 +
        }
 +
</syntaxhighlight>
 +
 +
<h3>DisplayWinner</h3>
 +
Add PlayerOneHighestScore, PlayerTwoHighestScore, PlayerOneHighestScoringWord and PlayerTwoHighestScoringWord as parameters of DisplayWinner.
 +
<syntaxhighlight lang="C#">
 +
private static void DisplayWinner(int PlayerOneScore, int PlayerTwoScore, int PlayerOneHighestScore, int PlayerTwoHighestScore, string PlayerOneHighestScoringWord, string PlayerTwoHighestScoringWord)
 +
        {
 +
            //...           
 +
 +
            //Write out the highest scoring word and corresponding score for each player
 +
            Console.WriteLine("Player One your highest scoring word was " + PlayerOneHighestScoringWord + ", which scored " + PlayerOneHighestScore + " points.");
 +
            Console.WriteLine("Player Two your highest scoring word was " + PlayerTwoHighestScoringWord + ", which scored " + PlayerTwoHighestScore + " points.");
 +
 +
            //...
 
         }
 
         }
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 10:24, 24 May 2018

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

Add HighestScore and HighestScoringWord as parameters of HaveTurn with reference.

 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

Add HighestScore and HighestScoringWord as parameters of UpdateAfterAllowedWord with reference.

 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);
            }
        }

DisplayWinner

Add PlayerOneHighestScore, PlayerTwoHighestScore, PlayerOneHighestScoringWord and PlayerTwoHighestScoringWord as parameters of DisplayWinner.

private static void DisplayWinner(int PlayerOneScore, int PlayerTwoScore, int PlayerOneHighestScore, int PlayerTwoHighestScore, string PlayerOneHighestScoringWord, string PlayerTwoHighestScoringWord)
        {
            //...            

            //Write out the highest scoring word and corresponding score for each player
            Console.WriteLine("Player One your highest scoring word was " + PlayerOneHighestScoringWord + ", which scored " + PlayerOneHighestScore + " points.");
            Console.WriteLine("Player Two your highest scoring word was " + PlayerTwoHighestScoringWord + ", which scored " + PlayerTwoHighestScore + " points.");

            //...
        }