/// <summary> /// Gets a neigbhoring tile's position /// </summary> /// <param name="tile">The start tile</param> /// <param name="neighborTile">The neighbor to examine</param> /// <returns>Returns the tile neighbor or a null tile if neighbor is not found</returns> 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]; }
/// <summary> /// Gets a neigbhoring Tile2's position /// </summary> /// <param name="Tile2">The start Tile2</param> /// <param name="neighborTile">The neighbor to examine</param> /// <returns>Returns the Tile2 neighbor or a null Tile2 if neighbor is not found</returns> public static Tile GetTileNeighbor(Tile Tile2, NeighborTile neighborTile) { //return Tile2.tileNeighbors[(int)neighborTile]; int newIndex = 0;// Tile2.ID; int min, max, tileId; tileId = Tile2.ID; min = mins[tileId];// (Tile2.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 >= totalTiles) { newIndex = tileId; } if (newIndex == tileId) { return Tile.NullTile; } return tiles[newIndex]; }
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."); }