Example #1
0
        public List <TDTile> GetAdjacentTiles(TDTile tile)
        {
            List <TDTile> adjacent = new List <TDTile> ();

            int tileX = tile.GetX();
            int tileY = tile.GetY();

            if (tileX > 0)
            {
                adjacent.Add(_tiles[tileX - 1, tileY]);
            }

            if (tileX < _width - 1)
            {
                adjacent.Add(_tiles[tileX + 1, tileY]);
            }

            if (tileY > 0)
            {
                adjacent.Add(_tiles[tileX, tileY - 1]);
            }

            if (tileY < _height - 1)
            {
                adjacent.Add(_tiles[tileX, tileY + 1]);
            }

            return(adjacent);
        }
Example #2
0
 public bool Equals(TDTile other)
 {
     return(other != null &&
            other.GetX() == x &&
            other.GetY() == y &&
            other.type == type);
 }
Example #3
0
        public Vector3 FindPointAdjacentToTileWithBuffer(TDTile other, float bufferDistance, Vector3 start)
        {
            Vector3 point = start;

            int xDiff = other.x - this.x;
            int yDiff = other.y - this.y;

            if (xDiff > 0)
            {
                point.x = other.x - bufferDistance;
            }
            else if (xDiff < 0)
            {
                point.x = this.x + bufferDistance;
            }

            if (yDiff > 0)
            {
                point.z = -(other.y - bufferDistance);
            }
            else if (yDiff < 0)
            {
                point.z = -(this.y + bufferDistance);
            }

            return(point);
        }
Example #4
0
        public bool IsOtherAdjacent(TDTile other)
        {
            bool xDiff = Math.Abs(this.x - other.x) == 1;
            bool yDiff = Math.Abs(this.y - other.y) == 1;

            return((xDiff || yDiff) && !(xDiff && yDiff));
        }
Example #5
0
        public List <TDTile> FindAdjacentTilesOfType(TDTile tile, TDTile.Type tileType)
        {
            List <TDTile> adjacentOfType = new List <TDTile> ();
            List <TDTile> allAdjacent    = GetAdjacentTiles(tile);

            for (int i = 0; i < allAdjacent.Count; i++)
            {
                TDTile other = allAdjacent[i];
                if (other.type == tileType)
                {
                    adjacentOfType.Add(other);
                }
            }

            return(adjacentOfType);
        }
Example #6
0
        public List <TDTile> FindAdjacentFlammableTiles(TDTile tile)
        {
            List <TDTile> adjacentFlammable = new List <TDTile> ();
            List <TDTile> allAdjacent       = GetAdjacentTiles(tile);

            for (int i = 0; i < allAdjacent.Count; i++)
            {
                TDTile other = allAdjacent[i];
                if (other.IsFlammable())
                {
                    adjacentFlammable.Add(other);
                }
            }

            return(adjacentFlammable);
        }
Example #7
0
        private List <TDStep> ReconstructPath(Dictionary <TDTile, TDTile> cameFrom, TDTile current)
        {
            List <TDStep> pathSteps = new List <TDStep> ();

            if (cameFrom.ContainsKey(current))
            {
                TDTile previous;
                if (cameFrom.TryGetValue(current, out previous))
                {
                    pathSteps = ReconstructPath(cameFrom, previous);
                    pathSteps.Add(new TDStep(current));
                }
            }
            else
            {
                pathSteps = new List <TDStep>();
                pathSteps.Add(new TDStep(current));
            }

            return(pathSteps);
        }
Example #8
0
        int ReadInMap(string[] splitLevelData)
        {
            string mapSize = splitLevelData [0];

            string[] mapSizes = mapSize.Split(VALUE_DELIMITER);
            mapWidth  = int.Parse(mapSizes [0]);
            mapHeight = int.Parse(mapSizes [1]);
            int offset = 1;            //Read one line for width and height

            tiles = new TDTile[mapWidth, mapHeight];
            int flamableCount = 0;

            for (int y = offset; y < mapHeight + offset; y++)
            {
                string mapRowData = splitLevelData[y];
                for (int x = 0; x < mapWidth; x++)
                {
                    TDTile tile = new TDTile(x, y - offset);
                    tile.type = TDTile.GetTypeForString(mapRowData[x].ToString());
                    if (tile.type == TDTile.Type.FIREHOUSE)
                    {
                        firehouseLocation = new Vector2(x, y - offset);
                    }

                    if (tile.IsFlammable())
                    {
                        flamableCount++;
                        float tileDurability = tile.durability;
                        totalDurability += tileDurability;
                    }

                    tiles[x, y - offset] = tile;
                }
            }

            return(mapHeight + offset);
        }
Example #9
0
        public void BuildPath(TDMap map, TDTile start, TDTile end)
        {
            if (end.type != TDTile.Type.STREET && end.type != TDTile.Type.FIREHOUSE)
            {
                List <TDTile> nearbyStreets = map.FindAdjacentTilesOfType(end, TDTile.Type.STREET);
                if (nearbyStreets.Count > 0)
                {
                    end = nearbyStreets[0];
                }
            }

            List <TDTile> closed = new List <TDTile> ();
            List <TDTile> open   = new List <TDTile> ();

            open.Add(start);
            Dictionary <TDTile, TDTile> cameFrom = new Dictionary <TDTile, TDTile> ();

            while (open.Count > 0)
            {
                TDTile current = open[0];

                if (current.Equals(end))
                {
                    steps = ReconstructPath(cameFrom, end);
                    break;
                }

                open.Remove(current);
                closed.Add(current);

                if (end.type == TDTile.Type.FIREHOUSE)
                {
                    List <TDTile> firestation = map.FindAdjacentTilesOfType(current, TDTile.Type.FIREHOUSE);
                    for (int i = 0; i < firestation.Count; i++)
                    {
                        TDTile station = firestation[i];
                        if (closed.Contains(station))
                        {
                            continue;
                        }

                        if (!open.Contains(station))
                        {
                            if (!current.Equals(start))
                            {
                                cameFrom.Add(station, current);
                            }
                            open.Add(station);
                        }
                    }
                }

                List <TDTile> neighborStreets = map.FindAdjacentTilesOfType(current, TDTile.Type.STREET);

                for (int i = 0; i < neighborStreets.Count; i++)
                {
                    TDTile neighbor = neighborStreets[i];
                    if (closed.Contains(neighbor))
                    {
                        continue;
                    }

                    if (!open.Contains(neighbor))
                    {
                        if (!current.Equals(start))
                        {
                            cameFrom.Add(neighbor, current);
                        }
                        open.Add(neighbor);
                    }
                }
            }
        }