Exemple #1
0
 public RouteTile(RouteTile parent, LandTile myTile, LandTile goal)
 {
     tile   = myTile;
     Parent = parent;
     gCost  = parent.fCost + TileManager.GetDistance(myTile, parent.tile);
     hCost  = TileManager.GetDistance(myTile, goal);
 }
    public void SetTower(RouteTile routeTile, Tower tower)
    {
        this.routeTile = routeTile;
        selectedTower  = tower;
        var towerBlocks = selectedTower.GetBlocks();

        for (var blockIndex = 0; blockIndex < towerBlocks.Count; blockIndex++)
        {
            blocks[blockIndex].SetBlock(towerBlocks[blockIndex]);
        }

        ShowTowerInfo();
        ShowPanel();
    }
Exemple #3
0
    public Route CalculatePath(LandTile start, LandTile end)
    {
        List <RouteTile>    openSet   = new List <RouteTile>();
        HashSet <RouteTile> closedSet = new HashSet <RouteTile>();
        Route path = new Route();

        openSet.Add(new RouteTile(start, end));

        while (openSet.Count > 0)
        {
            RouteTile currentTile = openSet[0];
            for (int i = 0; i < openSet.Count; i++)
            {
                if (openSet[i].fCost < currentTile.fCost || openSet[i].fCost == currentTile.fCost && openSet[i].hCost < currentTile.hCost)
                {
                    currentTile = openSet[i];
                }
            }
            openSet.Remove(currentTile);
            closedSet.Add(currentTile);

            if (currentTile.tile == end)
            {
                while (currentTile.Parent != null)
                {
                    path.Positions.Add(currentTile.tile.transform.position);
                    currentTile = currentTile.Parent;
                }
                break;
            }

            foreach (LandTile neighbor in TileManager.instance.GetNeighbors(currentTile.tile))
            {
                RouteTile tile = new RouteTile(currentTile, neighbor, end);
                if (tile.gCost < TileManager.GetDistance(start, neighbor) || !openSet.Contains(tile))
                {
                    openSet.Add(tile);
                }
            }
        }
        return(path);
    }
Exemple #4
0
 public void SetTowerTile(RouteTile routeTile)
 {
     selectedTile = routeTile;
     ShowPanel();
 }