private void AddShips(Board board) { var shipFactory = new ShipFactory(); foreach (var shipType in this._shipsType) { for (var i = 0; i < shipType.Value; i++) { var direction = this.GetRandomShipDirection(); var ship = shipFactory.Get(shipType.Key.Name, direction); ship.OriginPosition = this.GetRandomShipPosition(direction, ship.Length, board.Width, board.Height); while (board.ShipsOverlap(ship)) { ship.OriginPosition = this.GetRandomShipPosition(direction, ship.Length, board.Width, board.Height); } board.PlaceShip(ship); } } }
public Board Get() { var board = new Board(10, 10); this.AddShips(board); return board; }
public GameProcessor(IBoardFactory boardFactory, IUserInterface userInterface) { this._board = boardFactory.Get(); this._userInterface = userInterface; _lastPlay = LastPlay.Init; }