/// <summary>
        /// Get the surrounding tiles of the hexagon parameter [Only visible hex]
        /// </summary>
        /// <param name="hexagon"></param>
        /// <returns></returns>
        public List<Grid> GetSurroundingHexes(Grid hexagon)
        {
            if (hexagon == null)
                return new List<Grid>();
            int x = hexagon.posX;
            int y = hexagon.posY;
            List<Grid> surroundingHexs = new List<Grid>();
            #region LEFT SIDE
            //Left upper sider
            if (y % 2 != 0)
            {
                if (!IsOutOfBounds(x, y - 1))
                {
                    if (Scene._grid[x + (y - 1) * _mapWidth].TileObject != null)
                        surroundingHexs.Add(Scene._grid[x + (y - 1) * _mapWidth]);
                }
            }
            else if (!IsOutOfBounds(x - 1, y - 1))
            {
                if (Scene._grid[(x - 1) + (y - 1) * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x - 1) + (y - 1) * _mapWidth]);
            }

            //Left tile
            if (!IsOutOfBounds(x - 1, y))
            {
                if (Scene._grid[(x - 1) + y * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x - 1) + y * _mapWidth]);
            }
            //Left down tile
            if (y % 2 != 0)
            {
                if (!IsOutOfBounds(x, y + 1))
                {
                    if (Scene._grid[x + (y + 1) * _mapWidth].TileObject != null)
                        surroundingHexs.Add(Scene._grid[x + (y + 1) * _mapWidth]);
                }
            }
            else if (!IsOutOfBounds(x - 1, y + 1))
            {
                if (Scene._grid[(x - 1) + (y + 1) * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x - 1) + (y + 1) * _mapWidth]);
            }

            #endregion
            #region RIGHT SIDE
            //Right down tile
            if (y % 2 == 0)
            {
                if (!IsOutOfBounds(x, y + 1))
                {
                    if (Scene._grid[x + (y + 1) * _mapWidth].TileObject != null)
                        surroundingHexs.Add(Scene._grid[x + (y + 1) * _mapWidth]);
                }
            }
            else if (!IsOutOfBounds(x + 1, y + 1))
            {
                if (Scene._grid[(x + 1) + (y + 1) * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x + 1) + (y + 1) * _mapWidth]);
            }
            //Right tile
            if (!IsOutOfBounds(x + 1, y))
            {
                if (Scene._grid[(x + 1) + y * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x + 1) + y * _mapWidth]);
            }

            if (y % 2 == 0)
            {
                if (!IsOutOfBounds(x, y - 1))
                {
                    if (Scene._grid[x + (y - 1) * _mapWidth].TileObject != null)
                        surroundingHexs.Add(Scene._grid[x + (y - 1) * _mapWidth]);
                }
            }
            else if (!IsOutOfBounds(x + 1, y - 1))
            {
                if (Scene._grid[(x + 1) + (y - 1) * _mapWidth].TileObject != null)
                    surroundingHexs.Add(Scene._grid[(x + 1) + (y - 1) * _mapWidth]);
            }
            #endregion

            return surroundingHexs;
        }
        public void FillGround()
        {
            _grid = new Grid[MapHeight * MapWidth];

            //Set the grid with undisclosed tiles
            for (int x = 0; x < MapWidth; x++)
            {
                for (int y = 0; y < MapHeight; y++)
                {
                    _grid[x + y * MapHeight] = new Grid(new Vector3(x, y, 0f));
                }
            }
        }
        public void RandomFillMap()
        {
            _map = new RawGrid[_mapWidth * _mapHeight];
            _grid = new Grid[_mapWidth * _mapHeight];
            int middle = 0;
            int index;
            for (int x = 0; x < _mapWidth; x++)
            {
                for (int y = 0; y < _mapHeight; y++)
                {
                    index = x + y * _mapHeight;
                    _map[index] = new RawGrid();
                    _grid[index] = new Grid(new Vector3(x, y, 0f), Tile.Full);
                    //Border
                    if (x == 0 || y == 0 || (x == _mapWidth - 1) || (y == _mapHeight - 1))
                    {
                        _map[index].BasicValue = 1;
                    }
                    // Inside
                    else
                    {
                        /*middle = (_mapHeight / 2);

                        if (y == middle)
                            _map[x + y * _mapHeight].BasicValue = 0;
                        else*/
                            _map[index].BasicValue = GetRandomTileStatus(_percentage);
                    }
                }
            }
        }
Exemple #4
0
 public static Grid[] BasicValueToStatus(RawGrid[] rawGrid, int width, int height)
 {
     int length = rawGrid.Length;
     Grid[] changedGrid = new Grid[length];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             changedGrid[x + y * height] = new Grid(new Vector3(x, y, 0f));
             changedGrid[x + y * height].BasicValue = rawGrid[x + y * height].BasicValue;
             if (rawGrid[x + y * height].BasicValue == 0)
             {
                 changedGrid[x + y * height].status = Status.Revealed;
                 changedGrid[x + y * height].tile = Tile.Floor;
             }
             else
             {
                 changedGrid[x + y * height].status = Status.Undisclosed;
                 changedGrid[x + y * height].tile = Tile.Full;
             }
         }
     }
     return changedGrid;
 }
 public List<Grid> GetSurroundingHexes(Grid hex)
 {
     return new List<Grid>();
 }