Difference between revisions of "Allow a player to buy a vowel for 10 points"
Line 95: | Line 95: | ||
Console.WriteLine(PlayerName + " it is your turn."); | Console.WriteLine(PlayerName + " it is your turn."); | ||
DisplayTilesInHand(PlayerTiles); | DisplayTilesInHand(PlayerTiles); | ||
− | + | ||
− | + | //[...] | |
− | + | //ignore everything until you see the following if statement | |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
if (ValidWord) | if (ValidWord) | ||
{ | { | ||
Line 139: | Line 108: | ||
Console.WriteLine(); | Console.WriteLine(); | ||
UpdateAfterAllowedWord(Choice, ref PlayerTiles, ref PlayerScore, ref PlayerTilesPlayed, TileDictionary, AllowedWords); | UpdateAfterAllowedWord(Choice, ref PlayerTiles, ref PlayerScore, ref PlayerTilesPlayed, TileDictionary, AllowedWords); | ||
− | + | Console.WriteLine("Your current score is: " + PlayerScore); | |
NewTileChoice = GetNewTileChoice(); | NewTileChoice = GetNewTileChoice(); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 10:52, 16 November 2017
In all honesty, I'm unsure as to what this is asking. In perpetuity I feel there are three potential answers to what is being asked:
- 1) It wants me to select a random tile in the players hand and replace it with a vowel (penalising the player should the removed tile also be a vowel).
- 2) It wants me to select a random tile which isn't a vowel and replace it with a vowel (which poses a risk for error if the players hand is filled with vowels).
- 3) Allow the player to decide which tile in his hand he/she wishes to replace with a vowel.
In all honesty, only the last solution appears to complete the required task and leave as little room for error as possible.
Well then, without hesitation, let's begin:
private static string GetChoice() {
string Choice;
Console.WriteLine();
Console.WriteLine("Either:");
Console.WriteLine(" enter the word you would like to play OR");
Console.WriteLine(" press 1 to display the letter values OR");
Console.WriteLine(" press 4 to view the tile queue OR");
Console.WriteLine(" press 7 to view your tiles again OR");
Console.WriteLine(" press 6 to sell 10 points for a vowel");
Console.WriteLine(" press 0 to fill hand and stop the game.");
Console.Write("> ");
Choice = Console.ReadLine();
Console.WriteLine();
Choice = Choice.ToUpper();
return Choice;
}
Firstly we must add our new command to our get choice method.
// ... Some stuff was here
else if (Choice == "6") {
}
// ... Some stuff is here
Once we've done that, we need to create a new conditional check in our HaveTurn method.
It's time to add the desired logic. Firstly, we must check if the player has more than 10 points.
// ... Some stuff was here
else if (Choice == "6") {
if (PlayerScore < 10) Console.WriteLine("Not enough points available"); else {
}
}
// ... Some stuff is here
Now the contents of the else statement is only run once the player has enough points.
// ... Some stuff was here
else if (Choice == "6") {
if (PlayerScore < 10) Console.WriteLine("Not enough points available"); else {
Random random = new Random(); // Random instance to get vowel
String tileToRemove = "", vowel = new string[] { "A", "E", "I", "O", "U" }[random.Next(0, 4)];
Console.WriteLine("Your Current Hand: {0}\n", PlayerTiles);
do {
Console.Write("\nPlease Input Which Tile You'd Like To Remove :> ");
tileToRemove = Console.ReadLine().Trim().ToUpper(); // Read new tile from console stream
} while (tileToRemove.Length != 1 && !PlayerTiles.Contains(tileToRemove));
int removalTileIndex = PlayerTiles.IndexOf(tileToRemove); // Index of tile to replace
PlayerTiles = PlayerTiles.Remove(removalTileIndex, 1).Insert(removalTileIndex, vowel);
}
}
// ... Some stuff is here
Alternative Method
This is the existing method for a player's turn. You only need to add/edit one line of this method.
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)
{
Console.WriteLine();
Console.WriteLine(PlayerName + " it is your turn.");
DisplayTilesInHand(PlayerTiles);
//[...]
//ignore everything until you see the following if statement
if (ValidWord)
{
ValidWord = CheckWordIsValid(Choice, AllowedWords);
if (ValidWord)
{
Console.WriteLine();
Console.WriteLine("Valid word");
Console.WriteLine();
UpdateAfterAllowedWord(Choice, ref PlayerTiles, ref PlayerScore, ref PlayerTilesPlayed, TileDictionary, AllowedWords);
Console.WriteLine("Your current score is: " + PlayerScore);
NewTileChoice = GetNewTileChoice();
}
This is a method to generate a random number, which is then used to select a random vowel:
private static string RandomVowel()
{
string Vowel ="";
Random RandomNumber = new Random();
int Value = RandomNumber.Next(0, 4);
switch (Value)
{
case 0:
Vowel = "A";
break;
case 1:
Vowel = "E";
break;
case 2:
Vowel = "I";
break;
case 3:
Vowel = "O";
break;
case 4:
Vowel = "U";
break;
default:
Vowel = "A";
break;
}
return Vowel;
}
private static void AddEndOfTurnTiles(ref QueueOfTiles TileQueue, ref string PlayerTiles, ref string NewTileChoice, string Choice, ref int PlayerScore)
{
int NoOfEndOfTurnTiles = 0;
if (NewTileChoice == "1")
{
NoOfEndOfTurnTiles = Choice.Length;
}
else if (NewTileChoice == "2")
{
NoOfEndOfTurnTiles = 3;
}
else if (NewTileChoice == "3")
{
NoOfEndOfTurnTiles = Choice.Length + 3;
}
else if (NewTileChoice == "5")
{
if (PlayerScore >= 10)
{
PlayerTiles = PlayerTiles + RandomVowel();
PlayerScore = PlayerScore - 10;
}
else
{
Console.WriteLine("You do not have enough points to make this choice.");
Console.WriteLine("");
NewTileChoice = GetNewTileChoice();
}
}
for (int Count = 0; Count < NoOfEndOfTurnTiles; Count++)
{
PlayerTiles = PlayerTiles + TileQueue.Remove();
TileQueue.Add();
}
}
private static string GetNewTileChoice()
{
string NewTileChoice = "";
string[] TileChoice = { "1", "2", "3", "4", "5" };
while (Array.IndexOf(TileChoice, NewTileChoice) == -1)
{
Console.WriteLine("Do you want to:");
Console.WriteLine(" replace the tiles you used (1) OR");
Console.WriteLine(" get three extra tiles (2) OR");
Console.WriteLine(" replace the tiles you used and get three extra tiles (3) OR");
Console.WriteLine(" get no new tiles (4) OR");
Console.WriteLine(" get a random vowel for 10 points (5)?");
Console.Write("> ");
NewTileChoice = Console.ReadLine();
}
return NewTileChoice; ;
}