Difference between revisions of "Bonus points at end of game for longest and highest scored words"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "Create four local variables in the main game class. <syntaxhighlight lang="C#"> private static int highestScoredWord = 0; private static string highestScoredWordByPlayer = St...")
 
 
Line 28: Line 28:
 
         // Some stuff is here
 
         // Some stuff is here
 
     }
 
     }
 +
}
 +
</syntaxhighlight>
 +
 +
Then in play game before displaying the winner, add any earned points.
 +
 +
<syntaxhighlight lang="C#">
 +
private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize, int MaxHandSize, int MaxTilesPlayed, int NoOfEndOfTurnTiles) {
 +
    // Some Stuff Was Here
 +
 +
    if (highestScoredWordByPlayer == "Player One") {
 +
        PlayerOneScore += 10;
 +
    } else if (highestScoredWordByPlayer == "Player Two") {
 +
        PlayerTwoScore += 10;
 +
    }
 +
 +
    if (longestScoredWordByPlayer == "Player One") {
 +
        PlayerOneScore += 10;
 +
    } else if (longestScoredWordByPlayer == "Player Two") {
 +
        PlayerTwoScore += 10;
 +
    }
 +
 +
    DisplayWinner(PlayerOneScore, PlayerTwoScore);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 09:59, 24 May 2018

Create four local variables in the main game class.

private static int highestScoredWord = 0;
private static string highestScoredWordByPlayer = String.Empty;

private static int longestScoredWord = 0;
private static string longestScoredWordByPlayer = String.Empty;

Then in the Have Turn method, after the player has entered a valid choice

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) {
    // Some Stuff Was Here

    if (ValidWord) {
        if (Choice.Length > longestScoredWord) {
            longestScoredWord = Choice.Length;
            longestScoredWordByPlayer = PlayerName;
        }

        if (GetScoreForWord(Choice, TileDictionary) > highestScoredWord) {
            highestScoredWord = GetScoreForWord(Choice, TileDictionary);
            highestScoredWordByPlayer = PlayerName;
        }

        // Some stuff is here
    }
}

Then in play game before displaying the winner, add any earned points.

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

    if (highestScoredWordByPlayer == "Player One") {
        PlayerOneScore += 10;
    } else if (highestScoredWordByPlayer == "Player Two") {
        PlayerTwoScore += 10;
    }

    if (longestScoredWordByPlayer == "Player One") {
        PlayerOneScore += 10;
    } else if (longestScoredWordByPlayer == "Player Two") {
        PlayerTwoScore += 10;
    }

    DisplayWinner(PlayerOneScore, PlayerTwoScore);
}