Пример #1
0
        public static void Main()
        {
            Random r          = new Random();
            int    goingFirst = r.Next(1, 3);

            SplashScreen.ShowSplashScreen();
            Player p1 = new Player();
            Player p2 = new Player();

            Console.Write("Enter Player 1's Name: ");
            string p1Name = Console.ReadLine();

            p1.Name = p1Name;
            Console.Write("Enter Player 2's Name: ");
            string p2Name = Console.ReadLine();

            p2.Name = p2Name;
            SetupWorkflow.PlaceShips(p1);
            SetupWorkflow.PlaceShips(p2);
            switch (goingFirst)
            {
            case 1:
                GameWorkflow.WhoGoesFirst(p1.Name);
                break;

            case 2:
                GameWorkflow.WhoGoesFirst(p2.Name);
                break;
            }
            bool GameOver = false;

            while (!GameOver)
            {
                GameWorkflow.PrintEnemyBoard(p2);
                BLL.Responses.ShotStatus value1 = (GameWorkflow.FireShotAtEnemey(p2));
                if (value1 == BLL.Responses.ShotStatus.Victory)
                {
                    Console.WriteLine("Game over " + p1.Name + " wins.. ROLLTIDE");
                    GameOver = true;
                }
                GameWorkflow.PrintEnemyBoard(p1);
                BLL.Responses.ShotStatus value2 = (GameWorkflow.FireShotAtEnemey(p1));
                if (value2 == BLL.Responses.ShotStatus.Victory)
                {
                    Console.WriteLine("Game over " + p1.Name + " wins.. ROLLTIDE");
                    GameOver = true;
                }
            }
            if (GameOver)
            {
                Console.Clear();
                Console.WriteLine("Would you to play again? y or n ");
                string input = Console.ReadLine();
                if (input == "y")
                {
                    Program.Main();
                }
            }
        }
Пример #2
0
        public void Play()
        {
            var playerTurn = _setup.Player1GoesFirst;

            bool playOn = true;

            while (playOn)
            {
                ShotStatus status = new ShotStatus();

                Console.Clear();

                if (playerTurn)
                {
                    status = FireShotPrompt(_setup.Player2Board, _setup.Player1Name);
                }

                else
                {
                    status = FireShotPrompt(_setup.Player1Board, _setup.Player2Name);
                }

                if (status == ShotStatus.Invalid || status == ShotStatus.Duplicate)
                {
                    playerTurn = !playerTurn;
                }

                playerTurn = !playerTurn;

                if (status != ShotStatus.Victory)
                {
                    playOn = true;
                }

                else
                {
                    playOn = false;

                    Console.WriteLine("Press ENTER to play again or press Q to quit.");

                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        return;
                    }

                    else
                    {
                        SetupWorkflow restart = new SetupWorkflow();
                        restart.Start();
                    }
                }
            }
        }
Пример #3
0
        public void Game()
        {
            ConsoleOutput.SplashScreen();

            Player P1 = SetupWorkflow.GetPlayer(1);

            Console.Clear();
            Player P2 = SetupWorkflow.GetPlayer(2);

            Console.Clear();

            PlayerTurns(P1, P2, WhoIsGoingFirst());
        }
Пример #4
0
        internal static void Run()
        {
            bool playAgain = true;

            while (playAgain)
            {
                ConsoleIO.SplashScreen("Press any key to start a new game.");

                Game game = SetupWorkflow.Run();
                AlternateFiring(game);

                playAgain = PlayAnotherGame();
            }
            ConsoleIO.SplashScreen("        Thanks for playing!");
        }
Пример #5
0
        public void RunProg()
        {
            ConsoleOutput.DisplayTitle();
            Console.Clear();
            ConsoleKeyInfo keyPressed;


            do
            {
                mySetup = new SetupWorkflow();
                //myManager = new GameManager();
                SetupWorkflow.SetupPlayers();
                SetupWorkflow.SetupBoard();
                int firstTurn = myManager.RandomTurn();
                //if(firstTurn==0)

                keyPressed = ConsoleInput.ContinueOrQuit();

                Console.Clear();
            } while (!(keyPressed.Key == ConsoleKey.Q));
        }
Пример #6
0
 // Creates both player's boards
 private static void CreateBoards()
 {
     playerOneBoard = SetupWorkflow.CreateBoard((int)Players.PlayerOne);
     playerTwoBoard = SetupWorkflow.CreateBoard((int)Players.PlayerTwo);
 }
Пример #7
0
        public void PlayGame()
        {
            bool gameOver = false;

            //welcome message
            ConsoleOutput.Welcome();

            while (gameOver == false)
            {
                string[] playerlist     = ConsoleInput.GetPlayerNames();
                int      startingPlayer = DetermineWhoStarts();
                string   currentPlayer  = playerlist[startingPlayer];

                //run game setup
                SetupWorkflow gameBoard = new SetupWorkflow();
                Board         player1Board;
                Board         player2Board;

                if (currentPlayer == playerlist[0])
                {
                    ConsoleOutput.PlayerStartPrompt(playerlist[0]);
                    player1Board = gameBoard.GameSetUp();
                    ConsoleOutput.PlayerStartPrompt(playerlist[1]);
                    player2Board = gameBoard.GameSetUp();
                }
                else
                {
                    ConsoleOutput.PlayerStartPrompt(playerlist[1]);
                    player2Board = gameBoard.GameSetUp();
                    ConsoleOutput.PlayerStartPrompt(playerlist[0]);
                    player1Board = gameBoard.GameSetUp();
                }

                bool winnerFound = false;
                while (winnerFound == false)
                {
                    /*Show a grid with marks from the their board's shot history. Place a yellow M in a coordinate if a shot has been fired and missed at that location or a red H if a shot has been fired that has hit.*/
                    if (currentPlayer == playerlist[0])
                    {
                        ShowGrid(player1Board.GetShotHistory());
                    }
                    else
                    {
                        ShowGrid(player2Board.GetShotHistory());
                    }

                    //Prompt the user for a coordinate entry (ex: B10). Validate the entry; if valid, create a coordinate object, convert the letter to a number, and call the opponent board's FireShot() method.
                    Coordinate       shot = GetShotCoordinates(currentPlayer);
                    FireShotResponse response;

                    if (currentPlayer == playerlist[0])
                    {
                        response = player2Board.FireShot(shot);
                    }
                    else
                    {
                        response = player1Board.FireShot(shot);
                    }

                    //Retrieve the response from the FireShot method and display an appropriate message to the user.
                    ConsoleOutput.DisplayShotResult(response);

                    if (response.ShotStatus == ShotStatus.Victory)
                    {
                        winnerFound = true;
                    }

                    //if the shot is not invalid and not a duplicate switch players
                    if (response.ShotStatus != ShotStatus.Invalid && response.ShotStatus != ShotStatus.Duplicate)
                    {
                        Console.Clear();
                        currentPlayer = SwitchPlayer(currentPlayer, playerlist);
                    }
                }
                //ask if they would like to play again
                //reset boards if they do
                //exit if they dont
                bool playAgain = ConsoleInput.PlayAgain(currentPlayer);
                if (playAgain == false)
                {
                    gameOver = true;
                }
            }
            //Ending message
            ConsoleOutput.GameOver();
        }
Пример #8
0
        static void Main(string[] args)
        {
            SetupWorkflow tempSetup = new SetupWorkflow();

            tempSetup.Start();
        }
Пример #9
0
        //int _sunkCount;
        //ShotHistory p1currentShot;
        //ShotHistory p2currentShot;

        public void RunProg()
        {
            CreateGameManagerInstance();
            ConsoleOutput.DisplayTitle();
            Console.Clear();
            ConsoleKeyInfo keyPressed;
            //string player1Name;
            //string player2Name;
            FireShotResponse fireShotResponseP1 = new FireShotResponse();
            FireShotResponse fireShotResponseP2 = new FireShotResponse();
            ConsoleInput     input  = new ConsoleInput();
            ConsoleOutput    output = new ConsoleOutput();

            //ConsoleOutput.ContinueOrQuitMessage;

            CreateRandomTurn();
            Coordinate    coordinate;
            SetupWorkflow setup = new SetupWorkflow();

            do
            {
                //SetupWorkflow.SetupPlayers();
                //setup.SetupBoard();
                Console.Clear();
                _manager.player1.Name = input.GetPlayerName();
                _manager.player2.Name = input.GetPlayerName();
                Console.Clear();
                ConsoleOutput.PlayerTurnMessage(_manager.player1.Name);
                _manager.player1.Board = setup.SetupBoard(_manager.player1.Name);
                ConsoleOutput.PlayerTurnMessage(_manager.player2.Name);
                _manager.player2.Board      = setup.SetupBoard(_manager.player2.Name);
                _manager.player1.turnNumber = 0;
                _manager.player2.turnNumber = 1;
                //CreateRandomTurn();
                bool victory = false;
                do
                {
                    if (_manager.player1.turnNumber == _turn)
                    {
                        Console.Clear();
                        ConsoleOutput.PlayerTurnMessage(_manager.player1.Name);
                        ConsoleOutput.CurrentPlayerTurn(_manager.player1.Name);
                        Console.WriteLine();
                        output.DrawBoard(_manager.player2.Board);
                        Console.WriteLine();
                        Console.WriteLine("Lets try to hit an opponent's ship.");
                        Console.WriteLine();

                        do
                        {
                            coordinate         = input.GetCoordinates();
                            fireShotResponseP1 = _manager.player2.Board.FireShot(coordinate);
                            if (fireShotResponseP1.ShotStatus == ShotStatus.Duplicate)
                            {
                                output.DuplicateMessage();
                            }
                        } while (fireShotResponseP1.ShotStatus == ShotStatus.Duplicate);


                        if (fireShotResponseP1.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            output.HitAndSunkMessage(fireShotResponseP1.ShipImpacted);

                            Console.ReadKey();
                        }
                        else
                        {
                            output.DisplayShotStatus(fireShotResponseP1.ShotStatus);
                        }


                        if (fireShotResponseP1.ShotStatus == ShotStatus.Victory)
                        {
                            victory = true;
                            string currentPlayerName = _manager.player1.Name;
                            ConsoleOutput.VictoryMessage(currentPlayerName);
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                            break;
                        }
                        //else
                        //{
                        //    ConsoleOutput.SwitchPlayerPrompt();
                        //}

                        //Console.ReadKey();
                        _turn = 1;
                    }

                    else
                    {
                        Console.Clear();
                        ConsoleOutput.PlayerTurnMessage(_manager.player2.Name);
                        ConsoleOutput.CurrentPlayerTurn(_manager.player2.Name);
                        Console.WriteLine();
                        output.DrawBoard(_manager.player1.Board);
                        Console.WriteLine();
                        Console.WriteLine("Lets try to hit an opponent's ship.");
                        Console.WriteLine();

                        do
                        {
                            coordinate         = input.GetCoordinates();
                            fireShotResponseP2 = _manager.player1.Board.FireShot(coordinate);
                            if (fireShotResponseP2.ShotStatus == ShotStatus.Duplicate)
                            {
                                output.DuplicateMessage();
                            }
                        } while (fireShotResponseP2.ShotStatus == ShotStatus.Duplicate);


                        if (fireShotResponseP2.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            output.HitAndSunkMessage(fireShotResponseP2.ShipImpacted);

                            Console.ReadKey();
                        }
                        else
                        {
                            output.DisplayShotStatus(fireShotResponseP2.ShotStatus);
                        }


                        if (fireShotResponseP2.ShotStatus == ShotStatus.Victory)
                        {
                            victory = true;
                            string currentPlayerName = _manager.player2.Name;
                            ConsoleOutput.VictoryMessage(currentPlayerName);
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        //else
                        //{
                        //    ConsoleOutput.SwitchPlayerPrompt();
                        //}
                        _turn = 0;
                    }
                } while (/*!(fireShotResponseP1.ShotStatus == ShotStatus.Victory) || (fireShotResponseP2.ShotStatus == ShotStatus.Victory)*/ !victory);



                keyPressed = ConsoleInput.ContinueOrQuit();
            } while (!(keyPressed.Key == ConsoleKey.Q));
        }