コード例 #1
0
ファイル: GridBuilder.cs プロジェクト: musapkahraman/hexagon
        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));
            }
        }
コード例 #2
0
ファイル: GridBuilder.cs プロジェクト: musapkahraman/hexagon
        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;
        }