Example #1
0
        public static void StartGame()
        {
            // Welcome Message
            ConsoleMessages.WelcomeMessage();

            // Create Player One
            PlayerInfoModel player = Game.CreatePlayer("Player 1");
            // Create Player Two
            PlayerInfoModel opponent = Game.CreatePlayer("Player 2");

            Console.Clear();

            // Set default shotgrid
            GameLogic.SetDefaultShotGrid(player);
            GameLogic.SetDefaultShotGrid(opponent);

            // Ship positions
            ShipPositions(player);
            Console.Clear();
            ShipPositions(opponent);
            Console.Clear();

            // Game
            PlayerInfoModel winner = StartBattle(player, opponent);

            // Message to winner
            ConsoleMessages.WinnerMessage(winner);
        }
Example #2
0
        private static void ShipPositions(PlayerInfoModel player)
        {
            ConsoleMessages.PostionMessage(player);
            DisplayShotGrid(player);
            Console.WriteLine();
            Console.WriteLine();

            do
            {
                // Ask player ship-positions
                string shipSpot = DataRequests.AskPlayerShipSpot(player);

                // Store position
                GameLogic.AddShipToGrid(player, shipSpot);
            } while (player.PlayerShipSpot.Count < 5);
        }
Example #3
0
        private static PlayerInfoModel StartBattle(PlayerInfoModel player, PlayerInfoModel opponent)
        {
            PlayerInfoModel winner = null;

            do
            {
                // DisplayShotGrid(player);
                ConsoleMessages.DisplayPlayerName(player);
                Console.WriteLine();
                DisplayShotGrid(player);
                Console.WriteLine();

                // Ask player shot - validate
                string shot = DataRequests.AskPlayerShotSpot(player);
                Console.WriteLine();


                // Check if it hit a ship or water
                ConsoleMessages.ShowShotResult(player, opponent, shot);

                // Update player shotgrid and opponent ship status
                GameLogic.UpadateGrid(player, opponent, shot);

                // Show opponents remaining ships
                ConsoleMessages.ShowShipsNumber(player, opponent);

                if (GameLogic.RemainingShips(opponent) == 0)
                {
                    winner = player;
                }
                else
                {
                    (player, opponent) = (opponent, player);
                }

                ConsoleMessages.PressAnyKeyMessage();
                Console.Clear();
            } while (winner == null);

            return(winner);
        }