Difference between revisions of "GetScoreForWord"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with " private static int GetScoreForWord(string Word, Dictionary<char, int> TileDictionary) { int Score = 0; for (int Count = 0; Count < Word...")
 
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<syntaxhighlight lang=csharp>
 
         private static int GetScoreForWord(string Word, Dictionary<char, int> TileDictionary)
 
         private static int GetScoreForWord(string Word, Dictionary<char, int> TileDictionary)
 
         {
 
         {
Line 16: Line 17:
 
             return Score;
 
             return Score;
 
         }
 
         }
 +
</syntaxhighlight>
  
The above section of code will use a 'for' loop in order to calculate the score
+
The above section of code will use a 'for' loop in order to calculate the score, by going through the word one letter at a time and adding points based on the letter used. An additional five points are rewarded for words longer than five letters, and an additional 20 are rewarded for words longer than seven. The loop will only run until the count is equal to or greater than the length of the word.

Latest revision as of 13:37, 14 November 2017

        private static int GetScoreForWord(string Word, Dictionary<char, int> TileDictionary)
        {
            int Score = 0;
            for (int Count = 0; Count < Word.Length; Count++)
            {
                Score = Score + TileDictionary[Word[Count]];
            }
            if (Word.Length > 7)
            {
                Score = Score + 20;
            }
            else if (Word.Length > 5)
            {
                Score = Score + 5;
            }
            return Score;
        }

The above section of code will use a 'for' loop in order to calculate the score, by going through the word one letter at a time and adding points based on the letter used. An additional five points are rewarded for words longer than five letters, and an additional 20 are rewarded for words longer than seven. The loop will only run until the count is equal to or greater than the length of the word.