AStartTest.TileSystem.TileMap.GetTileNeighbor C# (CSharp) Method

GetTileNeighbor() public static method

Gets a neigbhoring tile's position
public static GetTileNeighbor ( Tile tile, NeighborTile neighborTile ) : Tile
tile Tile The start tile
neighborTile NeighborTile The neighbor to examine
return Tile
        public static Tile GetTileNeighbor(Tile tile, NeighborTile neighborTile)
        {
            int newIndex = 0;// tile.ID;
            int min, max, tileId;
            tileId = tile.ID;
            min = mins[tileId];// (tile.ID / numTilesX) * numTilesX;
            max = maxs[tileId];// min + numTilesX - 1;
            switch (neighborTile)
            {
                case NeighborTile.Up: newIndex = tileId - (int)numTiles.X;
                    break;
                case NeighborTile.Down: newIndex = tileId + (int)numTiles.X;
                    break;
                case NeighborTile.Left: newIndex = tileId - 1;
                    if (newIndex < min)
                        newIndex = tileId;
                    break;
                case NeighborTile.Right: newIndex = tileId + 1;
                    if (newIndex > max)
                        newIndex = tileId;
                    break;
                case NeighborTile.UpLeft: newIndex = tileId - numTilesX - 1;
                    if (newIndex < min - (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.UpRight: newIndex = tileId - numTilesX + 1;
                    if (newIndex > max - (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.DownLeft: newIndex = tileId + numTilesX - 1;
                    if (newIndex < min + (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.DownRight: newIndex = tileId + numTilesX + 1;
                    if (newIndex > max + (int)numTiles.X)
                        newIndex = tileId;
                    break;
            }

            if (newIndex < 0 || newIndex >= (numTilesX * numTilesY))
            {
                newIndex = tileId;
            }
            if (newIndex == tileId)
            {
                return new Tile();
            }

            return tiles[newIndex];
        }

Usage Example

 public void GetTileNeighborTest()
 {
     Vector2 position = null; // TODO: Initialize to an appropriate value
     Vector2 numTiles = null; // TODO: Initialize to an appropriate value
     Vector2 tileSize = null; // TODO: Initialize to an appropriate value
     IList<Panel> panels = null; // TODO: Initialize to an appropriate value
     TileMap target = new TileMap(position, numTiles, tileSize, panels); // TODO: Initialize to an appropriate value
     Tile tile = null; // TODO: Initialize to an appropriate value
     NeighborTile neighborTile = new NeighborTile(); // TODO: Initialize to an appropriate value
     Tile expected = null; // TODO: Initialize to an appropriate value
     Tile actual;
     actual = target.GetTileNeighbor(tile, neighborTile);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }