Allow players to skip and end their turn

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

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 == "4") {
        
    }

    // 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 == "4") {
        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.