예제 #1
0
        void recurseFill(vector2i parent)
        {
            //DFS
            if (map[parent.x, parent.y] == DungeonGen.wall ||visited[parent.x, parent.y]){
                return;
            }
            visited [parent.x, parent.y] = true;
            count++;

            List<vector2i> neighbors = parent.getCardinalTiles (map.GetLength (0), map.GetLength (1));

            foreach(vector2i i in neighbors){
                recurseFill(i);
            }
        }
예제 #2
0
        public List<vector2i> getCardinalTiles(int boundsX = 0, int boundsY = 0)
        {
            vector2i north = new vector2i (x,y + 1);
            vector2i east = new vector2i (x + 1, y);
            vector2i south = new vector2i (x, y - 1);
            vector2i west = new vector2i (x - 1, y);
            List<vector2i> adjWalls = new List<vector2i>{ north, south, east, west };

            adjWalls.RemoveAll(i => !i.isInBounds(boundsX, boundsY));

            return adjWalls;
        }
예제 #3
0
        public int reachableSpaces(int[,] dungeonMap, vector2i freeSpace)
        {
            map = dungeonMap;
            visited = new bool[map.GetLength(0), map.GetLength(1)]; //Should be initialized to false.
            count = 0;
            recurseFill(freeSpace);

            return count;
        }
예제 #4
0
        List<vector2i> getAdjTiles(vector2i check)
        {
            List<vector2i> adjTiles = new List<vector2i> ();

            adjTiles.Add (new vector2i (check.x - 1, check.y + 1));
            adjTiles.Add (new vector2i (check.x - 1, check.y));
            adjTiles.Add (new vector2i (check.x - 1, check.y - 1));
            adjTiles.Add (new vector2i (check.x, check.y + 1));
            adjTiles.Add (new vector2i (check.x, check.y - 1));
            adjTiles.Add (new vector2i (check.x + 1, check.y + 1));
            adjTiles.Add (new vector2i (check.x + 1, check.y));
            adjTiles.Add (new vector2i (check.x + 1, check.y - 1));

            return adjTiles;
        }
예제 #5
0
 int countAdjWall(vector2i check)
 {
     List<vector2i> adjWalls = getAdjTiles (check);
     int num = 0;
     foreach (vector2i i in adjWalls) {
         if (isInBounds (i) && newDungeon [i.x,i.y] == wall) {
             num += 1;
         }
     }
     return num;
 }
예제 #6
0
        public List<vector2i> wallCrawl(List<vector2i> wallList)
        {
            List<vector2i> newWalls = new List<vector2i> ();
            FloodFill f = new FloodFill ();
            vector2i start = null;
            for (int x = 0; x < newDungeon.GetLength(0); x++){
                for (int y = 0; y < newDungeon.GetLength(1); y++){
                    if ( newDungeon[x,y] == space){
                        start = new vector2i (x, y);
                        break;
                    }
                }
                if (start != null){
                    break;
                }
            }
            UnityEngine.Debug.Log ("(" + start.x + " " + start.y + ")");

            foreach (vector2i i in wallList) {
                int spaces = f.reachableSpaces (newDungeon, start);
                List<vector2i> card = i.getCardinalTiles (newDungeon.GetLength(0), newDungeon.GetLength(1));
                vector2i newWall = card [rand.Next (0, card.Count)];

                if (newDungeon[newWall.x, newWall.y] == space){
                    newWalls.Add (newWall);
                    newDungeon [newWall.x,newWall.y] = wall;
                    int newSpaces = f.reachableSpaces(newDungeon, start);

                    if (spaces - newSpaces > 3){
                        newWalls.Remove (newWall);

                        newDungeon [newWall.x,newWall.y] = space;
                    } else {
                        spaces = newSpaces;
                    }

                }

            }

            wallList.AddRange (newWalls);

            //newWalls = new List<vector2i> ();

            return wallList;
        }
예제 #7
0
 public bool isInBounds(vector2i coord)
 {
     if (coord.x < newDungeon.GetLength(0) && coord.x >= 0) {
         if (coord.y < newDungeon.GetLength(1) && coord.y >= 0) {
             return true;
         }
         //						#print "coord", coord
     }
     return false;
 }