Пример #1
0
        internal static GridSpotModel AskForShot(PlayerInfoModel activePlayer, PlayerInfoModel opponent)
        {
            bool isValidShot = false;

            UIDisplay.DisplayGrid(activePlayer.ShotsGrid);
            Console.WriteLine();
            Console.Write($"{activePlayer.PlayerName}: Where would you like to fire: ");
            string gridSpotSelection = Console.ReadLine();

            GridSpotModel output = UILogic.ParseStringToGridSpot(gridSpotSelection);

            isValidShot = GameLogic.ValidateShot(output, opponent);

            while (isValidShot == false)
            {
                Console.Clear();
                Console.WriteLine($"Oops!  \"{gridSpotSelection}\" was not a valid shot.  Please try again.");

                UIDisplay.DisplayGrid(activePlayer.ShotsGrid);
                Console.WriteLine();
                Console.Write($"{activePlayer.PlayerName}: Where would you like to fire: ");
                gridSpotSelection = Console.ReadLine();

                output = UILogic.ParseStringToGridSpot(gridSpotSelection);

                isValidShot = GameLogic.ValidateShot(output, opponent);
            }
            return(output);
        }
Пример #2
0
        static void Main(string[] args)
        {
            UIDisplay.ApplicationStartMessage();

            PlayerInfoModel activePlayer = UILogic.CreatePlayer("Player 1");
            PlayerInfoModel opponent     = UILogic.CreatePlayer("Player 2");

            PlayerInfoModel winner = null;

            do
            {
                UILogic.TakeTurn(activePlayer, opponent);

                //Determine if the game is over
                if (GameLogic.GameIsOver(opponent) == true)
                {
                    UIDisplay.EndGameMessage(activePlayer);

                    winner = activePlayer;
                }

                else
                {
                    //Switch player spots for next turn
                    (activePlayer, opponent) = (opponent, activePlayer);
                }
            } while (winner == null);
        }
Пример #3
0
        internal static void GetShipPlacements(PlayerInfoModel newPlayer)
        {
            //Initialize a grid for the player's ship placements
            newPlayer.ShipLocations = GameLogic.InitializeGrid();

            List <GridSpotModel> shipPlacements = new List <GridSpotModel>();

            bool isValidPlacement = false;

            do
            {
                DisplayGrid(newPlayer.ShipLocations);
                Console.WriteLine("");


                //Ask player for their next ship location

                string newPlacement = GetShipPlacementSelection(shipPlacements.Count);

                //Parse selection into GridSpotModel.GridSpotLetter and GridSpotNumber
                GridSpotModel gridSpotSelection = UILogic.ParseStringToGridSpot(newPlacement);


                //Check to see if that spot is a valid spot on the grid or if they have already placed a ship there
                isValidPlacement = GameLogic.IsValidShipPlacement(gridSpotSelection, newPlayer.ShipLocations);
                while (isValidPlacement == false)
                {
                    Console.Clear();

                    Console.WriteLine("Oops!  That's not a valid selection on your grid.  Please try again.");

                    DisplayGrid(newPlayer.ShipLocations);
                    Console.WriteLine("");

                    newPlacement = GetShipPlacementSelection(shipPlacements.Count);

                    gridSpotSelection = UILogic.ParseStringToGridSpot(newPlacement);

                    isValidPlacement = GameLogic.IsValidShipPlacement(gridSpotSelection, newPlayer.ShipLocations);
                }

                //Mark gridspot status as "ship" if the selection is valid
                GameLogic.RecordShipPlacement(gridSpotSelection, newPlayer.ShipLocations);

                shipPlacements.Add(gridSpotSelection);

                Console.Clear();

                //Loop back through until player has placed all five ships
            } while (shipPlacements.Count < 5);
        }