private void SetInitialMap() { for (var columnIndex = 0; columnIndex < _gridSize.x; columnIndex++) for (var rowIndex = 0; rowIndex < _gridSize.y; rowIndex++) { var position = new Vector3Int(rowIndex, columnIndex, 0); var hexagon = hexagons[Random.Range(0, hexagons.Count)]; if (NeighborHood.FindNeighbor(position, _placedHexagons, _grid, NeighborType.BottomLeft, out var neighbor)) while (neighbor.Hexagon.color.Equals(hexagon.color)) hexagon = hexagons[Random.Range(0, hexagons.Count)]; var tile = CreateTile(hexagon); _tilemap.SetTile(position, tile); _placedHexagons.Add(new PlacedHexagon(hexagon, position)); } }
public IEnumerable<PlacedHexagon> GetComplementaryHexagons(bool shouldPlaceBomb) { var alreadyPlacedBomb = false; var complementaryHexagons = new List<PlacedHexagon>(); for (var columnIndex = 0; columnIndex < _gridSize.x; columnIndex++) for (var rowIndex = 0; rowIndex < _gridSize.y; rowIndex++) { var position = new Vector3Int(rowIndex, columnIndex, 0); var value = _placedHexagons.Find(placedHexagon => placedHexagon.Cell == position); if (value != null) continue; if (shouldPlaceBomb && !alreadyPlacedBomb) { alreadyPlacedBomb = true; var hexagon = bombHexagons[Random.Range(0, bombHexagons.Count)]; if (NeighborHood.FindNeighbor(position, _placedHexagons, _grid, NeighborType.BottomLeft, out var neighbor)) while (neighbor.Hexagon.color.Equals(hexagon.color)) hexagon = bombHexagons[Random.Range(0, bombHexagons.Count)]; var tile = CreateTile(hexagon); _tilemap.SetTile(position, tile); var item = new BombHexagon(hexagon, position, Random.Range(6, 10)); complementaryHexagons.Add(item); _placedHexagons.Add(item); } else { var hexagon = hexagons[Random.Range(0, hexagons.Count)]; if (NeighborHood.FindNeighbor(position, _placedHexagons, _grid, NeighborType.BottomLeft, out var neighbor)) while (neighbor.Hexagon.color.Equals(hexagon.color)) hexagon = hexagons[Random.Range(0, hexagons.Count)]; var tile = CreateTile(hexagon); _tilemap.SetTile(position, tile); var item = new PlacedHexagon(hexagon, position); complementaryHexagons.Add(item); _placedHexagons.Add(item); } } return complementaryHexagons; }
public void OnPointerClick(PointerEventData eventData) { if (_isUserRotateInput) { return; } var cameraClickedWorldPoint = _camera.ScreenToWorldPoint(eventData.position); var clickedPoint = new Vector3(cameraClickedWorldPoint.x, cameraClickedWorldPoint.y, 0); var neighbors = NeighborHood.GetNeighbors(_grid, clickedPoint, _gridBuilder.GetPlacement(), selectionCount); var sumX = 0f; var sumY = 0f; for (var i = 0; i < selectionCount; i++) { var center = _grid.GetCellCenterWorld(neighbors[i].Cell); sumX += center.x; sumY += center.y; } _selectionCenter = new Vector3(sumX / selectionCount, sumY / selectionCount, 0); _groupController.ShowRotatingGroupAtCenter(_selectionCenter, neighbors); }