Esempio n. 1
0
        static void Main(string[] args)
        {
            bool keepPlaying;

            do
            {

                GameWorkflow game = new GameWorkflow();

                game.SplashScreen();
                game.PromptPlayerName();
                game.PromptShipPlacement();
                ShipSetter.SetShip(game);
                game.NextTurn();
                game.PromptShipPlacement();
                ShipSetter.SetShip(game);
                game.NextTurn();
                GamePlay.PlayGame(game);

                keepPlaying = GamePlay.NewGame();

                Console.ReadLine();
                Console.Clear();

            } while (keepPlaying);
        }
Esempio n. 2
0
        public static void PlayGame(GameWorkflow game)
        {
            string coordinateInput = "";
            char[] coordinateOutput;
            bool isValidInput;
            Coordinate coordinate;
            FireShotResponse response = new FireShotResponse();

            Console.WriteLine("Your ships are set, let's start the game!");

            do
            {
                Console.WriteLine("{0}, it is now your turn.", game.CurrentPlayer.Name);
                Console.WriteLine();
                do
                {
                    do
                    {
                        Console.WriteLine("This is Your Shot History...");
                        Console.WriteLine();
                        BoardDrawer.DrawShotHistoryBoard(game.OtherPlayer);
                        Console.WriteLine();
                        Console.WriteLine("Here are your ships that got hit.");
                        Console.WriteLine();
                        BoardDrawer.DrawShotHistoryBoard(game.CurrentPlayer);
                        Console.WriteLine();
                        Console.WriteLine("{0}, pick a coordinate to fire at: ", game.CurrentPlayer.Name);
                        coordinateInput = Console.ReadLine().ToUpper();

                        isValidInput = InputChecker.CheckInput(coordinateInput);

                        if (!isValidInput)
                        {
                            Console.WriteLine();
                            Console.WriteLine("{0}, that was not a valid shot coordinate.  Please try again!",
                                game.CurrentPlayer.Name);
                            ScreenCleaner.ClearBoard();
                        }
                        else
                        {
                            coordinateOutput = coordinateInput.ToCharArray();
                            coordinate = GridConversion.CoordinateConversion(coordinateOutput);
                            response = game.OtherPlayer.PlayerBoard.FireShot(coordinate);
                        }
                    } while (!isValidInput);

                    switch (response.ShotStatus)
                    {
                        case ShotStatus.Invalid:
                            Console.WriteLine();
                            Console.WriteLine("Not a valid coordinate.");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Duplicate:
                            Console.WriteLine();
                            Console.WriteLine("Duplicate coordinate.");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Miss:
                            Console.WriteLine();
                            Console.WriteLine("That was a miss!");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Hit:
                            Console.WriteLine();
                            Console.WriteLine("You hit the {0} ship!", response.ShipImpacted);
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.HitAndSunk:
                            Console.WriteLine();
                            Console.WriteLine("You sank the {0} ship!", response.ShipImpacted);
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Victory:
                            Console.WriteLine();
                            Console.WriteLine("Congratulations, {0}, you won!", game.CurrentPlayer.Name);
                            ScreenCleaner.ClearBoard();
                            break;
                    }

                } while (response.ShotStatus == ShotStatus.Invalid || response.ShotStatus == ShotStatus.Duplicate);

                game.NextTurn();

            } while (response.ShotStatus != ShotStatus.Victory);
        }