コード例 #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
        internal static void TakeTurn(PlayerInfoModel activePlayer, PlayerInfoModel opponent)
        {
            UIDisplay.DisplayTurnHeader(activePlayer, opponent);

            GridSpotModel shotRequest = UIDisplay.AskForShot(activePlayer, opponent);

            //Validates the shot and loops until the shot is valid
            bool isValidShot = GameLogic.ValidateShot(shotRequest, opponent);

            while (isValidShot == false)
            {
                UIDisplay.DisplayGrid(activePlayer.ShotsGrid);

                shotRequest = UIDisplay.AskForShot(activePlayer, opponent);
                isValidShot = GameLogic.ValidateShot(shotRequest, opponent);
            }

            //Once the player calls a valid shot, the program determins if it's a hit or a miss,
            //records the shot, and changes the opponent's number of remianing ships property
            if (GameLogic.IsAHit(shotRequest, opponent) == true)
            {
                GameLogic.RecordShot(shotRequest, activePlayer, opponent);

                opponent.RemainingShips = GameLogic.QuantifyRemainingShips(opponent);

                UIDisplay.DisplayHitMessage(opponent);
            }

            else
            {
                GameLogic.RecordShot(shotRequest, activePlayer, opponent);

                opponent.RemainingShips = GameLogic.QuantifyRemainingShips(opponent);

                UIDisplay.DisplayMissMessage();
            }
        }