Difference between revisions of "Display list of words (valid and invalid) used by each player at the end of the game"
(One intermediate revision by the same user not shown) | |||
Line 30: | Line 30: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | < | + | <h3>HaveTurn</h3> |
Add "ref List<string> PlayerWords" as a parameter for HaveTurn.<br> | Add "ref List<string> PlayerWords" as a parameter for HaveTurn.<br> | ||
When the player enters a word and not a number or menu option, write "PlayerWords.Add(Choice);" to add the word to the current player's list of words played.<br> | When the player enters a word and not a number or menu option, write "PlayerWords.Add(Choice);" to add the word to the current player's list of words played.<br> | ||
Line 70: | Line 70: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | < | + | <h3>DisplayWinner</h3> |
− | + | Add PlayerOneWords and PlayerTwoWords as parameters for DisplayWinner. | |
+ | Then write out each item in PlayerOneWords and PlayerTwoWords. | ||
<syntaxhighlight lang="C#"> | <syntaxhighlight lang="C#"> | ||
private static void DisplayWinner(int PlayerOneScore, int PlayerTwoScore, List<string> PlayerOneWords, List<string> PlayerTwoWords) | private static void DisplayWinner(int PlayerOneScore, int PlayerTwoScore, List<string> PlayerOneWords, List<string> PlayerTwoWords) |
Latest revision as of 09:57, 24 May 2018
PlayGame
In PlayGame, declare PlayerOneWords and PlayerTwoWords as lists.
Pass each of these with reference into HaveTurn; pass both of these into DisplayWinner.
private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize, int MaxHandSize, int MaxTilesPlayed, int NoOfEndOfTurnTiles)
{
//...
//Declare PlayerOneWords and PlayerTwoWords
List<string> PlayerOneWords = new List<string>();
List<string> PlayerTwoWords = new List<string>();
//...
while (PlayerOneTilesPlayed <= MaxTilesPlayed && PlayerTwoTilesPlayed <= MaxTilesPlayed && PlayerOneTiles.Length < MaxHandSize && PlayerTwoTiles.Length < MaxHandSize)
{
//Pass PlayerOneWords with reference
HaveTurn("Player One", ref PlayerOneTiles, ref PlayerOneTilesPlayed, ref PlayerOneScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerOneWords);
//...
//Pass PlayerTwoWords with reference
HaveTurn("Player Two", ref PlayerTwoTiles, ref PlayerTwoTilesPlayed, ref PlayerTwoScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerTwoWords);
}
//...
DisplayWinner(PlayerOneScore, PlayerTwoScore, PlayerOneWords, PlayerTwoWords);
}
HaveTurn
Add "ref List<string> PlayerWords" as a parameter for HaveTurn.
When the player enters a word and not a number or menu option, write "PlayerWords.Add(Choice);" to add the word to the current player's list of words played.
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 List<string> PlayerWords)
{
//...
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;
//Add this to add the word to the list of words used by that player
PlayerWords.Add(Choice);
//...
}
}
DisplayWinner
Add PlayerOneWords and PlayerTwoWords as parameters for DisplayWinner. Then write out each item in PlayerOneWords and PlayerTwoWords.
private static void DisplayWinner(int PlayerOneScore, int PlayerTwoScore, List<string> PlayerOneWords, List<string> PlayerTwoWords)
{
//...
//Add this to write out each list
Console.WriteLine("These were the words played by Player One:");
PlayerOneWords.ForEach(i => Console.WriteLine("{0}\t", i));
Console.WriteLine();
Console.WriteLine("These were the words played by Player Two:");
PlayerTwoWords.ForEach(i => Console.WriteLine("{0}\t", i));
//...
}