Пример #1
0
        public void PlayTheGame(PlayerInfo player1, PlayerInfo player2, GameBoard gameBoard)
        {
            FireShotResponse response = new FireShotResponse();
            int userTurn = 1;

            //sets to player2 to start
            PlayerInfo opponentsTurn = NextPlayersTurn(player1, player2, userTurn);
            PlayerInfo currentTurn = NextPlayersTurn(player1, player2, opponentsTurn.UserTurn);

            while (response.ShotStatus != ShotStatus.Victory)
            {
                //assigns currentTurn to player1
                Console.WriteLine("\n\t--- {0}'s TURN ---", currentTurn.UserName.ToUpper());

                //get X & Y
                Console.WriteLine("\n**Currently Displaying {0}'s Board**\n", opponentsTurn.UserName);

                DisplayBoardDuringGamePlay(opponentsTurn);

                Console.Write("\nPlayer {0}, Please enter the X & Y coordinate you would like to hit(Ex: A1): ",
                   currentTurn.UserName);

                response = opponentsTurn.MyBoard.FireShot(ConvertX.AcceptUserCoordinate(opponentsTurn, gameBoard));
                Responses(response);

                opponentsTurn = NextPlayersTurn(player1, player2, opponentsTurn.UserTurn);
                currentTurn = NextPlayersTurn(player1, player2, currentTurn.UserTurn);
                Console.WriteLine("It's now {0}'s turn. Press enter to continue", currentTurn.UserName);
                Console.ReadLine();
                Console.Clear();
            }
        }
Пример #2
0
        public void AllowUserToPlace5Ships(GameBoard gameBoard, PlayerInfo playerInfo)
        {
            Console.WriteLine("Hello, {0}! Let's place your ships \n", playerInfo.UserName);
            //places ship
            int counter = 0;
            //iterates through for all 5 placements
            while (counter < 5)
            {
                    Console.WriteLine("\n-- Place Ship #{0}", counter+1);

                ShipSetUp setUpYourShip = new ShipSetUp(); // acces UI Ship Placement
                PlaceShipRequest shipRequest = new PlaceShipRequest(); // initiates placeship request business logic

                //assigns user entered ship placeemnt biz logic request using the associated board dictionary
                shipRequest = setUpYourShip.SetUpShip(gameBoard.BoardDictionary,counter);

                //assigns ship request to player1's board

                //PlaceShip method on the Board(biz logic) checks if the PlaceShip is valid
                ShipPlacement placeShipResult = playerInfo.MyBoard.PlaceShip(shipRequest);

                if (placeShipResult != ShipPlacement.Ok )
                {
                    Console.WriteLine("\n\t\t****ERROR -- INVALID SHIP PLACEMENT****\n");
                    counter--;
                }
                ;
                counter++;
            }

            Console.WriteLine("Thank you for your input {0}! Press enter to clear the console so the other player cannot cheat!", playerInfo.UserName);
            Console.ReadLine();
            Console.Clear();
        }
Пример #3
0
        public static Coordinate AcceptUserCoordinate(PlayerInfo playerInfo, GameBoard gameBoard)
        {
            string coordinateRequested = Console.ReadLine();
            ConvertX convertX = new ConvertX();
            Coordinate aCoordinate = convertX.Conversion(gameBoard.BoardDictionary, coordinateRequested);

            return aCoordinate;
            

        }
Пример #4
0
        static void Main(string[] args)
        {

            PlayerInfo player1 = new PlayerInfo();
            PlayerInfo player2 = new PlayerInfo();


            StartMenu menu = new StartMenu();

            //assign turns
            player1.UserTurn = 1;
            player2.UserTurn = 2;

          //assign userName
            player1.UserName = menu.Execute(player1.UserTurn);
            player2.UserName = menu.Execute(player2.UserTurn);

            //create gameboard
            GameBoard gameBoard = new GameBoard();

        //allow users to place ships -- player1
            gameBoard.PrintGameBoard();
            ShipSetUp setUpShips = new ShipSetUp();
            setUpShips.AllowUserToPlace5Ships(gameBoard,player1);

            //allow users to place ships -- player2
            gameBoard.PrintGameBoard();
            setUpShips.AllowUserToPlace5Ships(gameBoard,player2); 
        
 
            GamePlay playGame = new GamePlay();
            playGame.PlayTheGame(player1, player2, gameBoard);
            Console.ReadLine();



        }