Ejemplo n.º 1
0
        public TDLevel(string levelData)
        {
            string[] splitLevelData = levelData.Split('\n');
            int      offset         = ReadInMap(splitLevelData);

            offset = ReadLevelParams(splitLevelData, offset);
            offset = ReadArsonPath(splitLevelData, offset);
            offset = ReadNPCCues(splitLevelData, offset);

            _map = new TDMap(tiles, firehouseLocation, totalDurability);
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }