Difference between revisions of "UpdateAfterAllowedWord"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 
Line 11: Line 11:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  - The code here passes variables for the Word, PlayerTiles, PlayerScore, PlayerTilesPlayed, TileDictionary and AllowedWords.
 
  - The code here passes variables for the Word, PlayerTiles, PlayerScore, PlayerTilesPlayed, TileDictionary and AllowedWords.
  - It then adds the word length to the tiles played and then removes the amount of player tiles used to create the word, thus updating the  
+
  - It then adds the word length to the tiles played and then removes the amount of player tiles used to create the word, thus updating the available tiles to the player (A reduction in this case).
available tiles to the player (A reduction in this case).
 
 
  - Finally, the code then adds the score of the word (If valid), after checking the tile dictionary to work out its value, and this score is added onto the existing score of the player.
 
  - Finally, the code then adds the score of the word (If valid), after checking the tile dictionary to work out its value, and this score is added onto the existing score of the player.

Latest revision as of 14:42, 14 November 2017

private static void UpdateAfterAllowedWord(string Word, ref string PlayerTiles, ref int PlayerScore, ref int PlayerTilesPlayed, Dictionary<char, int> TileDictionary, List<string> AllowedWords)
        {
            PlayerTilesPlayed = PlayerTilesPlayed + Word.Length;
            foreach (var Letter in Word)
            {
                PlayerTiles = PlayerTiles.Remove(PlayerTiles.IndexOf(Letter), 1);
            }
            PlayerScore = PlayerScore + GetScoreForWord(Word, TileDictionary);
        }
- The code here passes variables for the Word, PlayerTiles, PlayerScore, PlayerTilesPlayed, TileDictionary and AllowedWords.
- It then adds the word length to the tiles played and then removes the amount of player tiles used to create the word, thus updating the available tiles to the player (A reduction in this case).
- Finally, the code then adds the score of the word (If valid), after checking the tile dictionary to work out its value, and this score is added onto the existing score of the player.