Difference between revisions of "Allow players to skip and end their turn"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "Quite simple, First we must add a new command: <syntaxhighlight lang="C#"> private static string GetChoice() { // Previous Commands Console.WriteLine(" press 8 t...")
 
 
Line 17: Line 17:
 
     // Some Stuff Was Here
 
     // Some Stuff Was Here
  
     else if (Choice == "4") {
+
     else if (Choice == "8") {
 
          
 
          
 
     }
 
     }
Line 31: Line 31:
 
     // Some Stuff Was Here
 
     // Some Stuff Was Here
  
     else if (Choice == "4") {
+
     else if (Choice == "8") {
 
         Console.WriteLine("Your turn has been skipped");
 
         Console.WriteLine("Your turn has been skipped");
 
         break; // Break loop and end method
 
         break; // Break loop and end method

Latest revision as of 09:17, 17 November 2017

Quite simple, First we must add a new command:

private static string GetChoice() {
    // Previous Commands

    Console.WriteLine("     press 8 to skip your turn");

    // Succeeding Commands
}

Then we must create a new condition within the HaveTurn method for the corresponding number:

private static string HaveTurn() {
    // Some Stuff Was Here

    else if (Choice == "8") {
        
    }

    // Some Stuff Is Here
}

Now as for actual logic, to end a players turn the while loop using Not(ValidChoice) must be broken. This can be done by just typing break or be setting the value of ValidChoice to true. Because the users input isn't an actual "ValidChoice", I feel it'd be more prudent to just break the loop and reach the end of the method; hence that's what I'll do.

private static string HaveTurn() {
    // Some Stuff Was Here

    else if (Choice == "8") {
        Console.WriteLine("Your turn has been skipped");
        break; // Break loop and end method
    }

    // Some Stuff Is Here
}

That's it, now if the player ever enters eight their move will be skipped.