Пример #1
0
        internal void CheckPlayerInput(string playerInput, ref Player player)
        {
            // Convert string coordinates to array based coordinates.
            int[] convertedInput = ConvertPlayerInput(playerInput);

            // Check if ship is in board boundaries and if it's nearby any other ships.
            CheckingService checkingService = new CheckingService();

            if (checkingService.CheckBoardBoundaries(convertedInput, ref player) == true && checkingService.CheckNearbyCells(convertedInput, ref player) == true)
            {
                BoardService boardService = new BoardService();

                boardService.PlaceShipOnBoard(convertedInput, ref player);
            }
            else
            {
                Console.Write("Something went wrong:\n" +
                              "- Did you use wrong coordinates?\n" +
                              "- Did you placed your ship outside the board boundaries?\n" +
                              "- Did you placed your ship near another already placed ship?\n\n");
            }
        }
Пример #2
0
        internal void Start()
        {
            // Create two player instances with board and ships.
            Player playerOne = new Player(), playerTwo = new Player();

            // Create BoardService() and fill players boards and dummy boards with empty cells.
            BoardService boardService = new BoardService();

            playerOne.board = boardService.CreateNewEmptyBoard();
            playerTwo.board = boardService.CreateNewEmptyBoard();

            playerOne.dummyBoard = boardService.CreateNewEmptyBoard();
            playerTwo.dummyBoard = boardService.CreateNewEmptyBoard();

            // Create ShipService() and let players place their ships.
            ShipService shipService = new ShipService();

            shipService.PlaceShips(ref playerOne, ref playerTwo);

            // Start the battle.
            boardService.StartBattle(ref playerOne, ref playerTwo);

            throw new NotImplementedException();
        }