Exemple #1
0
        private ReturnType SetupPlayer(Player myPlayer, string myPlayerName)
        {
            //Setup a SPECIFIC PLAYER - Do not use currentPlayer object here!!!

            //Does the player have a name from before?
            if (myPlayer.Name.Length == 0)
            {
                bool skipError = true;
                while (myPlayerName.Length == 0)
                {
                    //Prompt user for name
                    Console.Clear();
                    if (skipError != true)
                    {
                        Console.WriteLine("Invalid Entry, try again... \n\n");
                    }
                    skipError = false;
                    Console.WriteLine("Enter a name for this player: \n\nPress ENTER to continue, (Q/q) to quit...");
                    myPlayerName = Console.ReadLine();
                    if (myPlayerName.ToUpper() == "Q")
                    {
                        return(ReturnType.Quit);
                    }
                }
                myPlayer.SetName(myPlayerName);
            }

            //ReInit
            if (myPlayer.PlayerStatus == PlayerStatus.FinishedGame || myPlayer.PlayerStatus == PlayerStatus.Initialized)
            {
                //No current need to do any other kind of other cleanup (SetupPlayerBoard method initializes a new board each time)
            }
            myPlayer.SetPlayerStatus(PlayerStatus.Uninitialized);   //Going to reset the player's board, uninitialized until SetupPlayerBoard returns true
            //StubSetupPlayerBoard(myPlayer) can alternately be used for UI testing -- non-interactive board setup
            if (SetupPlayerBoard(myPlayer) == ReturnType.Success)
            {
                myPlayer.SetPlayerStatus(PlayerStatus.Initialized);
            }
            else
            {
                return(ReturnType.Error);
            }

            Console.Clear();
            Console.WriteLine($"Great!  Your board is now completely setup, {myPlayer.Name}! \nIt is setup as shown below:");
            _grid.Grid(myPlayer, BoardViewType.ShipPositions);
            if (P1.PlayerStatus == PlayerStatus.Uninitialized || P2.PlayerStatus == PlayerStatus.Uninitialized)
            {
                Console.WriteLine("\nSwitch Seats with the other player, and let them set up their board. :-)");
            }
            else if (P1.PlayerStatus == PlayerStatus.Initialized && P2.PlayerStatus == PlayerStatus.Initialized)
            {
                Console.WriteLine("\nThe game is now ready to play. :-)");
            }
            else
            {
                //Something unexpected is happening to PlayerStatus - you need to debug and refactor...
            }
            Console.WriteLine("Press any key to continue...");
            if (Console.ReadKey().Key == ConsoleKey.Q)
            {
                return(ReturnType.Quit);
            }

            return(ReturnType.Success);
        }