// 게임 시작 시 유저 쉽 생성 private void Start() { Engineer engineer = new Engineer(); // TODO:추후 로그를 남겨 유저쉽 판단 후 생성 BattleshipBuilder battleshipBuilder = GetComponent <BattleshipBuilder>(); battleshipBuilder.MakeBattleship(); // 빌더를 통해 구성해야 할 제품을 입력받아 제품을 구성한다. engineer.Construct(battleshipBuilder); // 최종 생상된 제품을 반환한다. Ship battleship = battleshipBuilder.GetShip(); Debug.Log(battleship.GetPartsList()); }
private static Battleship CreateGameBattleship(int battleshipSize, int boardSize) { var coordinates = new Coordinate[battleshipSize]; var isHorizontalPos = _randGenerator.Next(boardSize - 1) % 2 == 0; var xCoordinate = _randGenerator.Next(boardSize - 1); var yCoordinate = _randGenerator.Next(boardSize - 1); if (xCoordinate + battleshipSize > boardSize) { xCoordinate = GetSingleCoordinateWithinBoardGame(battleshipSize, boardSize); } if (yCoordinate + battleshipSize > boardSize) { yCoordinate = GetSingleCoordinateWithinBoardGame(battleshipSize, boardSize); } if (isHorizontalPos) { for (int i = 0; i < battleshipSize; i++) { coordinates[i] = new Coordinate(xCoordinate, yCoordinate); xCoordinate++; } } else { for (int i = 0; i < battleshipSize; i++) { coordinates[i] = new Coordinate(xCoordinate, yCoordinate); yCoordinate++; } } return(BattleshipBuilder.BuildBattleShip(coordinates)); }