Пример #1
0
        public void PlaceShip(ShipLocation shipLocation)
        {
            _playerValidator.ValidateNumberOfPlacedShips(shipLocation.Ship, _ships);

            _ships.Add(shipLocation.Ship);
            OwnBoard.SetShip(shipLocation);
        }
Пример #2
0
        public void FillArrays()
        {
            OwnSavedBoard    = new Cell[OwnBoard.GetCells().Length];
            AttackSavedBoard = new Cell[AttackBoard.GetCells().Length];
            int iterator = 0;

            for (int x = 0; x < OwnBoard.Board.GetLength(0); x++)
            {
                for (int y = 0; y < OwnBoard.Board.GetLength(1); y++)
                {
                    OwnSavedBoard[iterator] = OwnBoard.Board[x, y];
                    iterator++;
                }
            }

            iterator = 0;
            for (int x = 0; x < AttackBoard.Board.GetLength(0); x++)
            {
                for (int y = 0; y < AttackBoard.Board.GetLength(1); y++)
                {
                    AttackSavedBoard[iterator] = AttackBoard.Board[x, y];
                    iterator++;
                }
            }
        }
Пример #3
0
        public ShootResult Shoot(Coordinate coordinate)
        {
            var result = OwnBoard.Shoot(coordinate);

            MarkResultsOnOpponentsBoard(coordinate, result);

            if (result == ShootResult.Sunk && OwnBoard.AnyShipsLeftInBattle())
            {
                return(ShootResult.Won);
            }

            return(result);
        }