Difference between revisions of "Provide a method for the player to swap their entire hand"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "An option for "Swap out your entire hand." is added to the player's options. private static string GetChoice() { string Choice; Console.WriteL...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
An option for "Swap out your entire hand." is added to the player's options.
 
An option for "Swap out your entire hand." is added to the player's options.
  
private static string GetChoice()
+
<syntaxhighlight lang=Csharp>
        {
+
private static string GetChoice() {
            string Choice;
+
    string Choice;
            Console.WriteLine();
+
    Console.WriteLine();
            Console.WriteLine("Either:");
+
    Console.WriteLine("Either:");
            Console.WriteLine("    enter the word you would like to play OR");
+
    Console.WriteLine("    enter the word you would like to play OR");
            Console.WriteLine("    press 1 to display the letter values OR");
+
    Console.WriteLine("    press 1 to display the letter values OR");
            Console.WriteLine("    press 4 to view the tile queue OR");
+
    Console.WriteLine("    press 4 to view the tile queue OR");
            Console.WriteLine("    press 7 to view your tiles again OR");
+
    Console.WriteLine("    press 7 to view your tiles again OR");
            Console.WriteLine("    press 0 to fill hand and stop the game.");
+
    Console.WriteLine("    press 0 to fill hand and stop the game.");
            Console.WriteLine("    press 2 to swap out your entire hand.");
+
    Console.WriteLine("    press 2 to swap out your entire hand."); // <- New command here
            Console.Write("> ");
+
    Console.Write("> ");
            Choice = Console.ReadLine();
+
    Choice = Console.ReadLine();
            Console.WriteLine();
+
    Console.WriteLine();
            Choice = Choice.ToUpper();
+
    Choice = Choice.ToUpper();
            return Choice;
 
        }
 
  
The following code is added to the choices in HaveTurn:
+
    return Choice;
 +
}
 +
</syntaxhighlight>
  
else if (Choice == "2")
+
The following code is added to the choices in the method called HaveTurn:
                {
+
 
                    //method to swap entire hand
+
<syntaxhighlight lang=Csharp>
                    int handsize = PlayerTiles.Length;
+
else if (Choice == "2") {
                    PlayerTiles = "";
+
    //method to swap entire hand
                    PlayerTiles = GetStartingHand(TileQueue, handsize);
+
    int handsize = PlayerTiles.Length;
                    DisplayTilesInHand(PlayerTiles);
+
    PlayerTiles = "";
                }
+
    PlayerTiles = GetStartingHand(TileQueue, handsize);
 +
    DisplayTilesInHand(PlayerTiles);
 +
}
 +
</syntaxhighlight>
  
 
The first line records the size of the player's hand. The second empties their hand, and the third calls GetStartingHand() to give them a new hand the same size as their old one. Then the player is shown their new hand.
 
The first line records the size of the player's hand. The second empties their hand, and the third calls GetStartingHand() to give them a new hand the same size as their old one. Then the player is shown their new hand.

Latest revision as of 21:12, 14 November 2017

An option for "Swap out your entire hand." is added to the player's options.

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 0 to fill hand and stop the game.");
    Console.WriteLine("     press 2 to swap out your entire hand."); // <- New command here
    Console.Write("> ");
    Choice = Console.ReadLine();
    Console.WriteLine();
    Choice = Choice.ToUpper();

    return Choice;
}

The following code is added to the choices in the method called HaveTurn:

else if (Choice == "2") {
    //method to swap entire hand
    int handsize = PlayerTiles.Length;
    PlayerTiles = "";
    PlayerTiles = GetStartingHand(TileQueue, handsize);
    DisplayTilesInHand(PlayerTiles);
}

The first line records the size of the player's hand. The second empties their hand, and the third calls GetStartingHand() to give them a new hand the same size as their old one. Then the player is shown their new hand.