Ejemplo n.º 1
0
    void createRandomWalls(int amountWalls)
    {
        while (true)
        {
            Debug.Log("create walls " + amountWalls);
            walls = new LinkedList <Wall> ();
            for (int i = 0; i < amountWalls; i++)
            {
                int            x         = UnityEngine.Random.Range(0, Width);
                int            y         = UnityEngine.Random.Range(0, Height);
                int            dir       = UnityEngine.Random.Range(0, 4);
                Wall.Direction direction = (Wall.Direction)dir;

                Wall wall = new Wall(x, y, direction, Wall.WallType.Full);

                walls.AddFirst(wall);
            }

            //check of goal reachable
            Pathfinder finder = new Pathfinder(this);
            if (finder.calculatePath(getTileAt(0, 0), goal) == null)
            {
                Debug.Log("Could not find path from start to finish, create walls again.");
            }
            else
            {
                return;
            }
        }
    }
Ejemplo n.º 2
0
 public void AddWall(Wall.Direction direction, GameObject wallType)
 {
     if (!hasWall(direction))
     {
         walls.Add(new Wall(this, direction
                            , wallType));
     }
 }
Ejemplo n.º 3
0
 public bool hasWall(Wall.Direction direction)
 {
     foreach (Wall wall in walls)
     {
         if (wall.direction.Equals(direction))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 private bool blocked(Tile root, Wall.Direction direction)
 {
     foreach (var wall in walls)
     {
         if (wall.blocks(root, direction))
         {
             return(true);
         }
     }
     return(false);
 }