Allow a player to buy a vowel for 10 points

From TRCCompSci - AQA Computer Science
Revision as of 15:09, 15 November 2017 by M0hk4l3 (talk | contribs) (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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