Пример #1
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();
        }
Пример #2
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();



        }