Exemple #1
0
        private ReturnType SetupPlayerBoard(Player myPlayer)
        {
            myPlayer.SetBoard(new Board());
            foreach (ShipType myShipType in Enum.GetValues(typeof(ShipType)))
            {
                Nullable <ShipPlacement> myShipPlacement = null;
                do
                {
                    Console.Clear();
                    //Show Error message if ship placement not successful
                    if (myShipPlacement != null)
                    {
                        switch (myShipPlacement.Value)
                        {
                        case ShipPlacement.Overlap:
                            Console.WriteLine($"Could not place a ship with parameters given. \nIt overlapped another ship. \n\nPress any key to continue, (Q/q) to quit...");
                            if (Console.ReadKey().Key == ConsoleKey.Q)
                            {
                                return(ReturnType.Quit);                                           //User pressed Q.
                            }
                            break;

                        case ShipPlacement.NotEnoughSpace:
                            Console.WriteLine($"Could not place a ship with parameters given. \nThere was not enough space on the board. \n\nPress any key to continue, (Q/q) to quit...");
                            if (Console.ReadKey().Key == ConsoleKey.Q)
                            {
                                return(ReturnType.Quit);                                           //User pressed Q.
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    PlaceShipRequest myRequest = null;
                    //Console.Clear();
                    myRequest = GetShipRequest(myShipType, myPlayer);
                    if (myRequest == null)
                    {
                        return(ReturnType.Error);
                    }
                    myShipPlacement = myPlayer.board.PlaceShip(myRequest);
                } while (myShipPlacement != ShipPlacement.Ok);
            }
            return(ReturnType.Success);
        }