Exemple #1
0
        public bool RunOneTurn(Player otherPlayer, Player currentPlayer)
        {
            bool keepPlaying = true;

            ConsoleIO.DrawBoard(otherPlayer, currentPlayer);

            string status = "";

            ConsoleIO.DrawBoard(otherPlayer, currentPlayer);


            FireShotResponse ckShot = currentPlayer.Fire();

            ConsoleIO.DrawBoard(otherPlayer, currentPlayer);

            status = ckShot.ShotStatus.ToString();
            Console.WriteLine(status);
            switch (ckShot.ShotStatus)
            {
            case ShotStatus.Invalid:
                break;

            case ShotStatus.Duplicate:
                do
                {
                    Console.WriteLine("Enter a coordinate you have not used.");
                    ckShot = currentPlayer.Fire();
                    ConsoleIO.DrawBoard(otherPlayer, currentPlayer);

                    status = ckShot.ShotStatus.ToString();
                } while (status == "Duplicate");
                break;

            case ShotStatus.Miss:
                break;

            case ShotStatus.Hit:
                break;

            case ShotStatus.HitAndSunk:
                string otherName = currentPlayer.name;
                Console.WriteLine($"You sunk {otherName}'s {ckShot.ShipImpacted}!");
                break;

            case ShotStatus.Victory:
                ConsoleIO.DrawBoard(currentPlayer, otherPlayer);
                Console.WriteLine(currentPlayer.name + " wins!");
                ConsoleIO.Continue();
                keepPlaying = ConsoleIO.AskToPlayAgain();

                //keepPlaying = true;
                break;
            }
            //if (status == "HitAndSunk")
            //{
            //    string otherName = currentPlayer.name;
            //    Console.WriteLine($"You sunk {otherName}'s {ckShot.ShipImpacted}!");
            //}


            //ConsoleIO.DrawBoard(currentPlayer, otherPlayer);
            //Console.WriteLine(currentPlayer.name + " wins!");
            //ConsoleIO.Continue();
            //ConsoleIO.AskToPlayAgain();


            ConsoleIO.Continue();

            return(keepPlaying);
        }