示例#1
0
 public static Gameboard.GameMode ChooseGameMode(Player player1, Player player2)
 {
     do
     {
         Console.WriteLine("Choose a gamemode!");
         CX.Print("1 - Classic Mode", player1.Colour, null, endLine: true);
         CX.Print("2 - Infinity Mode\n", player2.Colour, null, endLine: true);
         try
         {
             Gameboard.Mode = (Gameboard.GameMode)CX.GetKey() - 1;
             Console.Clear();
         }
         catch { CX.Catch(false); }
         if (Gameboard.Mode == Gameboard.GameMode.Classic)
         {
             Console.WriteLine("You have chosen Classic Mode!\n");
         }
         else if (Gameboard.Mode == Gameboard.GameMode.Infinity)
         {
             Console.WriteLine("You have chosen Infinity Mode!\n");
         }
         else
         {
             CX.Print("Please try again.", ConsoleColor.Red);
         }
     } while (Gameboard.Mode != Gameboard.GameMode.Classic && Gameboard.Mode != Gameboard.GameMode.Infinity);
     return(Gameboard.Mode);
 }
示例#2
0
        public static void ColourChanger(Player player1, Player player2)
        {
            while (true)
            {
                // Declaring the player objects that determine which player has been selected.
                Player chosenPlayer = player1, otherPlayer = player2;

                sbyte playerColourChoice = 0; // Declaring the variable for user input and giving it a default that triggers the question .
                Console.Clear();

                // Choosing the player to change the colour of.
                while (playerColourChoice != 1 && playerColourChoice != 2)
                {
                    Console.WriteLine("What player would you like to change the colour of?");
                    CX.Print($"1 - {player1.Name}", player1.Colour, null, true);
                    CX.Print($"2 - {player2.Name}", player2.Colour, null, true);
                    Console.WriteLine("Please enter your choice...");
                    Console.WriteLine("Enter \"-1\" to exit without changing any player colours...");
                    try
                    {
                        playerColourChoice = sbyte.Parse(Console.ReadLine());
                        if (playerColourChoice == 2)
                        {
                            // Swapping the initialised variables values around should the user choose so.
                            chosenPlayer = player2;
                            otherPlayer  = player1;
                        }
                        else if (playerColourChoice == -1)
                        {
                            Console.Clear();
                            return;
                        }
                        else
                        {
                            Console.WriteLine("That wasn't a valid option, please try again...\n");
                        }
                    }
                    catch { CX.Catch(false); }
                    finally { Console.Clear(); }
                }

                // Selecting a colour to set for the chosen user.
                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Please select a colour");

                    // We get the colours from the Print method.
                    ConsoleColor?[] colourChoices = new ConsoleColor?[12];
                    colourChoices[0]  = CX.Print("1 - Dark Red", ConsoleColor.DarkRed, null, true);
                    colourChoices[1]  = CX.Print("2 - Red", ConsoleColor.Red, null, true);
                    colourChoices[2]  = CX.Print("3 - Dark Yellow", ConsoleColor.DarkYellow, null, true);
                    colourChoices[3]  = CX.Print("4 - Yellow", ConsoleColor.Yellow, null, true);
                    colourChoices[4]  = CX.Print("5 - Green", ConsoleColor.Green, null, true);
                    colourChoices[5]  = CX.Print("6 - Dark Green", ConsoleColor.DarkGreen, null, true);
                    colourChoices[6]  = CX.Print("7 - Dark Blue", ConsoleColor.DarkBlue, null, true);
                    colourChoices[7]  = CX.Print("8 - Blue", ConsoleColor.Blue, null, true);
                    colourChoices[8]  = CX.Print("9 - Dark Cyan", ConsoleColor.DarkCyan, null, true);
                    colourChoices[9]  = CX.Print("10 - Cyan", ConsoleColor.Cyan, null, true);
                    colourChoices[10] = CX.Print("11 - Pink", ConsoleColor.Magenta, null, true);
                    colourChoices[11] = CX.Print("12 - Dark Pink", ConsoleColor.DarkMagenta, null, true);
                    Console.WriteLine("Chose the wrong player? Enter \"0\" to go back...");
                    Console.WriteLine("Decided you like the colours as they are? Enter \"-1\" to go back");

                    try
                    {
                        sbyte colour = sbyte.Parse(Console.ReadLine());
                        Console.Clear();

                        // Sorting out non-colour changing related options.
                        if (colour == -1)
                        {
                            return;
                        }
                        else if (colour == 0)
                        {
                            break;
                        }

                        // colour will always be +1 higher than the array because the array starts at '0'.
                        // Dealing with errors that would otherwise cause the player reassign the same colour or assign the same colour to different players.
                        if (chosenPlayer.Colour == colourChoices[colour - 1])
                        {
                            Console.WriteLine($"{player1.Name} already has this colour selected.\n"); Console.ReadKey(); continue;
                        }
                        else if (otherPlayer.Colour == colourChoices[colour - 1])
                        {
                            Console.WriteLine($"{player2.Name} already has this colour selected, please choose another colour.\nPress any key to try again..."); Console.ReadKey(); continue;
                        }
                        else
                        {
                            byte answer = 0;
                            while (true)
                            {
                                // Assigning the colour to the chosen player.
                                chosenPlayer.Colour = colourChoices[colour - 1];

                                // Offering the player the option to change the other players colour.
                                Console.Write("Would you like to change the colour of ");
                                CX.Print(otherPlayer.Name, otherPlayer.Colour);
                                Console.WriteLine("?");
                                Console.Write("1 - Yes | 2 - No | 0 - Recolour ");
                                CX.Print(chosenPlayer.Name, chosenPlayer.Colour, null, true);

                                // Processing user input.
                                answer = CX.GetKey(limit: 2);
                                if (answer == 0 || answer == 1)
                                {
                                    break;
                                }
                                else if (answer == 2)
                                {
                                    return;
                                }
                                else if (answer != 0 && answer != 1)
                                {
                                    // Error handling.
                                    Console.Clear();
                                    Console.WriteLine("That wasn't a valid option.\nPress any key to try again...");
                                    Console.ReadKey();
                                    Console.Clear();
                                }
                            }
                            if (answer == 0)
                            {
                                continue;
                            }
                            if (answer == 1)
                            {
                                Player temporaryPlayer = chosenPlayer;
                                chosenPlayer = otherPlayer;
                                otherPlayer  = temporaryPlayer;
                                break;
                            }
                        }
                    }
                    catch { CX.Catch(null); }
                    Console.Clear();
                }
            }
        }
示例#3
0
        public static void ChangeNameChoice(Player player1, Player player2)
        {
            Player chosenPlayer = player1, otherPlayer = player2;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("What player would you like to change the name of?");
                CX.Print($"1 - {player1.Name}\n", player1.Colour, null, true);
                CX.Print($"2 - {player2.Name}\n", player2.Colour, null, true);
                Console.WriteLine("Please enter your choice...");
                Console.WriteLine("Enter \"0\" to exit without changing any player names...");
                try
                {
                    byte playerNameChangeChoice = CX.GetKey(limit: 2);
                    if (playerNameChangeChoice == 2)
                    {
                        chosenPlayer = player2;
                        otherPlayer  = player1;
                    }
                    else if (playerNameChangeChoice == 0)
                    {
                        return;
                    }
                    else
                    {
                        CX.Print("That wasn't a valid option, please try again...\n", ConsoleColor.Red, null, true);
                    }
                    while (true)
                    {
                        byte answer = 0;
                        chosenPlayer.ChangeName(otherPlayer);
                        Console.WriteLine();
                        while (true)
                        {
                            Console.Write("Would you also like to rename ");
                            CX.Print(otherPlayer.Name, otherPlayer.Colour);

                            Console.Write("?\n1 - Yes | 2 - No | 0 - Rename ");
                            CX.Print(chosenPlayer.Name, chosenPlayer.Colour);

                            answer = CX.GetKey(limit: 2);
                            if (answer == 0 || answer == 1)
                            {
                                break;
                            }
                            else if (answer == 2)
                            {
                                return;
                            }
                            else
                            {
                                Console.WriteLine("That wasn't a valid option.\nPress any key to try again...");
                                Console.ReadKey();
                                Console.Clear();
                            }
                        }
                        if (answer == 0)
                        {
                            continue;
                        }
                        else if (answer == 1)
                        {
                            Player temporaryPlayer = chosenPlayer;
                            chosenPlayer = otherPlayer;
                            otherPlayer  = temporaryPlayer;
                            break;
                        }
                    }
                }
                catch { CX.Catch(true); }
                finally { Console.Clear(); }
            }
        }
示例#4
0
        public static byte PauseMenu(Player player1, Player player2)
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("* PAUSE MENU *");
                Console.WriteLine("Select an option by entering the relevant number.");
                Console.WriteLine("1 - Continue Playing");
                Console.Write("2 - ");
                CX.Print("C", ConsoleColor.Red);
                CX.Print("h", ConsoleColor.DarkYellow);
                CX.Print("a", ConsoleColor.Yellow);
                CX.Print("n", ConsoleColor.Green);
                CX.Print("g", ConsoleColor.Cyan);
                CX.Print("e", ConsoleColor.DarkCyan);
                CX.Print(" C", ConsoleColor.Blue);
                CX.Print("o", ConsoleColor.Magenta);
                CX.Print("l", ConsoleColor.DarkMagenta);
                CX.Print("o", ConsoleColor.DarkRed);
                CX.Print("u", ConsoleColor.Red);
                CX.Print("r", ConsoleColor.DarkYellow);
                Console.WriteLine("s", ConsoleColor.Yellow);
                Console.WriteLine("3 - Change Player Names\n4 - Instructions (How to Play)\n5 - Modify Game\n7 - Restart Game\n0 - Quit Game");
                try
                {
                    byte Option = CX.GetKey();

                    Console.Clear();
                    switch (Option)
                    {
                    case 1:     // Resume the game.
                        Console.WriteLine("Returning to the game\nPress any key...");
                        Console.ReadKey();
                        Console.Clear();
                        return(1);

                    case 2:     // Change the playerss colours.
                        Console.Clear();
                        Player.ColourChanger(player1, player2);
                        break;

                    case 3:
                        Player.ChangeNameChoice(player1, player2);
                        break;

                    case 4:     // View the instructions.
                        Instructions();
                        break;

                    case 5:
                        Console.WriteLine("You can change the size of the board, change the height of the board and the number of counters needed to win.");
                        if (GameEngine.NumberOfPlayers < 2)
                        {
                            Console.WriteLine("You can also change the computer difficulty.");
                        }
                        if (GameEngine.NumberOfPlayers == 2)
                        {
                            Console.WriteLine("Modifying the board will end the match, are you sure you want to modify the board?");
                        }
                        Console.WriteLine((GameEngine.NumberOfPlayers < 2 ? "1 - Modify Game\n" : "1 - Modfiy Board\n") + "2 - Return to Pause Menu");
                        byte answer = CX.GetKey(limit: 2);
                        if (answer == 1)
                        {
                            GameEngine.ModifyGame(player1, player2);
                        }
                        break;

                    case 6:     // Restart the game.
                        Console.WriteLine("Restarting the game\n");
                        Console.Clear();
                        return(6);

                    case 0:     // Quit the game.
                        return(0);

                    default:
                        CX.Print("This wasn't an option.", ConsoleColor.Red);
                        Console.WriteLine("Press any key to try again...");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    }
                }
                catch { CX.Catch(false); }
            }
        }