Advertisement
Guest User

Untitled

a guest
Jul 29th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int x = _, y = _; // replace _ with the start x and y. I used the player's coordinate in my own code.
  2. int replaceId = _, id = _; // replaceId is the only block Id it will replace, and it will be replaced with `id`.
  3. List<Point> points = new List<Point>(); // Point is from System.Drawing & lets you remember x's/y's.
  4.  
  5. Block[, ,] tempMap; // replace with whatever method you use to read the map.
  6. // It needs to contain all the blocks in the room. Or, at least the ones you are using.
  7. // I use a three-dimensional array of Block objects. Blocks are found by typing Map[x,y,layer].
  8.  
  9. do // using a do-while instead of a while because the list starts at 0 and it wouldn't execute.
  10. {
  11.     // if you're on the replace id, replace it and remove it from the list.
  12.     if (tempMap[x, y, 0].Id == replaceId)
  13.     {
  14.         Build(id, x, y);
  15.         tempMap[x, y, 0] = new Block(id, x, y);;
  16.  
  17.         for (int ind = 0; ind < points.Count; ind++)
  18.         {
  19.             if (points[ind].X == x && points[ind].Y == y)
  20.             {
  21.                 points.RemoveAt(ind);
  22.             }
  23.         }
  24.     }
  25.     else // If you're not on the replace id, you're on the border. Select a random point and remove it from the list.
  26.     {
  27.         var RanPoint = points[MyRandom.Next(points.Count)]; // Do not use `new Random` here. Do it outside the loop.
  28.         x = RanPoint.X;
  29.         y = RanPoint.Y;
  30.  
  31.         for (int ind = 0; ind < points.Count; ind++)
  32.         {
  33.             if (points[ind].X == x && points[ind].Y == y)
  34.             {
  35.                 points.RemoveAt(ind);
  36.             }
  37.         }
  38.     }
  39.  
  40.     // Move to the right.
  41.     x++;
  42.  
  43.     if (tempMap[x, y, 0].Id == replaceId) // If it's on the replace id, replace it and add it to the list.
  44.     {
  45.         b.Push.Build(id, x, y);
  46.         tempMap[x, y, 0] = new Block(id, x, y);;
  47.         points.Add(new Point(x, y));
  48.     }
  49.  
  50.     // Moooove to the left.
  51.     x -= 2;
  52.  
  53.     if (tempMap[x, y, 0].Id == replaceId)
  54.     {
  55.         b.Push.Build(id, x, y);
  56.         tempMap[x, y, 0] = new Block(id, x, y);;
  57.         points.Add(new Point(x, y));
  58.     }
  59.  
  60.     // 2 hops this time (go one space above the original)
  61.     x++;
  62.     y++;
  63.  
  64.     if (tempMap[x, y, 0].Id == replaceId)
  65.     {
  66.         b.Push.Build(id, x, y);
  67.         tempMap[x, y, 0] = new Block(id, x, y);;
  68.         points.Add(new Point(x, y));
  69.     }
  70.  
  71.     // go one space below the original
  72.     y -= 2;
  73.  
  74.     if (tempMap[x, y, 0].Id == replaceId)
  75.     {
  76.         b.Push.Build(id, x, y);
  77.         tempMap[x, y, 0] = new Block(id, x, y);;
  78.         points.Add(new Point(x, y));
  79.     }
  80.  
  81.     y++;
  82.  
  83.     // You just added a few points to the list. Return, select a random one, delete it, and repeat until there are none left.
  84.     // Often times it will select a point that is already surrounded with dots, making the process much quicker.
  85. } while (points.Count > 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement