Difference between revisions of "If the player spells a ten or more letter word, they should receive a 200 point bonus"
(Syntax prettifying) |
|||
(One intermediate revision by one other user not shown) | |||
Line 2: | Line 2: | ||
<syntaxhighlight lang = csharp> | <syntaxhighlight lang = csharp> | ||
− | private static int GetScoreForWord(string Word, Dictionary<char, int> TileDictionary) | + | 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; | |
− | + | } | |
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Change the if statement by adding a new condition, and change the current >7 condition to an else if instead. See below: | Change the if statement by adding a new condition, and change the current >7 condition to an else if instead. See below: | ||
− | |||
<syntaxhighlight lang = csharp> | <syntaxhighlight lang = csharp> | ||
− | + | if (Word.Length > 10) | |
− | if (Word.Length > 10) | ||
− | |||
score = score + 200; | score = score + 200; | ||
− | |||
else if (Word.Length > 7) | else if (Word.Length > 7) | ||
− | |||
Score = Score + 20; | Score = Score + 20; | ||
− | |||
else if (Word.Length > 5) | else if (Word.Length > 5) | ||
− | |||
Score = Score + 5; | Score = Score + 5; | ||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− |
Latest revision as of 18:45, 14 November 2017
Find the GetScoreForWord method. The for loop will calculate the score for the word played, the if statement adds any bonus points.
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;
}
Change the if statement by adding a new condition, and change the current >7 condition to an else if instead. See below:
if (Word.Length > 10)
score = score + 200;
else if (Word.Length > 7)
Score = Score + 20;
else if (Word.Length > 5)
Score = Score + 5;