Advertisement
Guest User

Untitled

a guest
May 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. bool Check(Point cord, bool diagonals = false)
  2. {
  3. int edgestate = 0;
  4.  
  5. if (cord.x > 0 && grid[cord.x - 1, cord.y] == Tile.Empty)
  6. {
  7. edgestate++;
  8. }
  9.  
  10. if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y] == Tile.Empty)
  11. {
  12. edgestate += 2;
  13. }
  14.  
  15. if (cord.y > 0 && grid[cord.x, cord.y - 1] == Tile.Empty)
  16. {
  17. edgestate += 4;
  18. }
  19.  
  20. if (cord.y < gridheight - 1 && grid[cord.x, cord.y + 1] == Tile.Empty)
  21. {
  22. edgestate += 8;
  23. }
  24.  
  25. if (!diagonals)
  26. {
  27. if (edgestate == 1)
  28. {
  29. if (cord.x < gridlength - 1)
  30. {
  31. if (cord.y > 0 && grid[cord.x + 1, cord.y - 1] == Tile.Empty)
  32. {
  33. return false;
  34. }
  35.  
  36. if (cord.y < gridheight - 1 && grid[cord.x + 1, cord.y + 1] == Tile.Empty)
  37. {
  38. return false;
  39. }
  40. }
  41.  
  42. return true;
  43.  
  44. }
  45.  
  46. else if (edgestate == 2)
  47. {
  48. if (cord.x > 0)
  49. {
  50.  
  51. if (cord.y > 0 && grid[cord.x - 1, cord.y - 1] == Tile.Empty)
  52. {
  53. return false;
  54. }
  55.  
  56. if (cord.y < gridheight - 1 && grid[cord.x - 1, cord.y + 1] == Tile.Empty)
  57. {
  58. return false;
  59. }
  60. }
  61.  
  62. return true;
  63.  
  64. }
  65.  
  66. else if (edgestate == 4)
  67. {
  68. if (cord.y < gridheight - 1)
  69. {
  70.  
  71. if (cord.x > 0 && grid[cord.x - 1, cord.y + 1] == Tile.Empty)
  72. {
  73. return false;
  74. }
  75.  
  76. if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y + 1] == Tile.Empty)
  77. {
  78. return false;
  79. }
  80. }
  81.  
  82. return true;
  83.  
  84. }
  85.  
  86. else if (edgestate == 8)
  87. {
  88. if (cord.y > 0)
  89. {
  90. if (cord.x > 0 && grid[cord.x - 1, cord.y - 1] == Tile.Empty)
  91. {
  92. return false;
  93. }
  94.  
  95. if (cord.x < gridlength - 1 && grid[cord.x + 1, cord.y - 1] == Tile.Empty)
  96. {
  97. return false;
  98. }
  99. }
  100.  
  101. return true;
  102. }
  103.  
  104. return false;
  105. }
  106.  
  107. else
  108. {
  109. if (edgestate == 1 || edgestate == 2 || edgestate == 4 || edgestate == 8)
  110. {
  111. return true;
  112. }
  113.  
  114. return false;
  115.  
  116. }
  117. }
  118.  
  119. // This function creates a space on the grid and updates the frontier
  120. void Carve(Point point)
  121. {
  122. extra = new List<Point>();
  123.  
  124. grid [point.x, point.y] = Tile.Empty;
  125.  
  126. if (point.y > 0 && grid[point.x, point.y - 1] == Tile.Unknown)
  127. {
  128. grid[point.x, point.y - 1] = Tile.Processing;
  129. extra.Add(new Point(point.x, point.y - 1));
  130. }
  131.  
  132. if (point.y < gridlength - 1 && grid[point.x, point.y + 1] == Tile.Unknown)
  133. {
  134. grid[point.x, point.y + 1] = Tile.Processing;
  135. extra.Add(new Point(point.x, point.y + 1));
  136. }
  137.  
  138. if (point.x > 0 && grid[point.x - 1, point.y] == Tile.Unknown)
  139. {
  140. grid[point.x - 1, point.y] = Tile.Processing;
  141. extra.Add(new Point(point.x - 1, point.y));
  142. }
  143.  
  144. if (point.x < gridheight - 1 && grid[point.x + 1, point.y] == Tile.Unknown)
  145. {
  146. grid[point.x + 1, point.y] = Tile.Processing;
  147. extra.Add(new Point(point.x + 1, point.y));
  148. }
  149.  
  150. RandomizeList(extra);
  151. frontier.AddRange(extra);
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement