Difference between revisions of "Display list of words (valid and invalid) used by each player at the end of the game"
(Created page with "<syntaxhighlight lang="C#"> private static void PlayGame(List<string> AllowedWords, Dictionary<char, int> TileDictionary, bool RandomStart, int StartHandSize, int MaxHandSize...") |
(No difference)
|
Revision as of 09:46, 24 May 2018
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)
{
HaveTurn("Player One", ref PlayerOneTiles, ref PlayerOneTilesPlayed, ref PlayerOneScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerOneWords);
//...
HaveTurn("Player Two", ref PlayerTwoTiles, ref PlayerTwoTilesPlayed, ref PlayerTwoScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles, ref PlayerTwoWords);
}
//...
DisplayWinner(PlayerOneScore, PlayerTwoScore, PlayerOneWords, PlayerTwoWords);
}
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);
//...
}
}
<syntaxhighlight lang="C#">
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));
//... }
</syntax highlight>