Guest User

Untitled

a guest
Feb 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Map_Generation
  7. {
  8. class Program
  9. {
  10.  
  11. static void Main(string[] args)
  12. {
  13. int width = 6;
  14. int height = 6;
  15. int[,,,] land = new int[width,height, 1, 1];
  16. int amountOfLand;
  17. int[] assignedLand = new int[width];
  18. int number;
  19.  
  20. Random randNumGen = new Random();
  21.  
  22.  
  23. amountOfLand = (((width * height) / 36) * 25);
  24. //Runs a for loop to place land, only places land if there is 4 or less pieces of land in the current row
  25. while (amountOfLand > 0)
  26. {
  27. for (int i = 0; i < width; i++)
  28. {
  29. for(int j = 0; j < height; j++)
  30. {
  31. if (land[i, j, 0, 0] == 0 && amountOfLand > 0 && assignedLand[i] <= 4)
  32. {
  33. number = randNumGen.Next(1, 5);
  34. if (number <= 3)
  35. {
  36. land[i, j, 0, 0] = 1;
  37. amountOfLand--;
  38. assignedLand[i]++;
  39. }
  40. else
  41. {
  42. land[i, j, 0, 0] = 0;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. //Code to check for any land isolated from all other land
  49. for (int i = 0; i < width; i++)
  50. {
  51. for (int j = 0; j < height; j++)
  52. {
  53. if (land[i, j, 0, 0] == 1)
  54. {
  55. int numberOfNeighbours = 0;
  56. if ((i - 1) > 0)
  57. {
  58. if (land[(i - 1), j, 0, 0] == 1)
  59. {
  60. numberOfNeighbours++;
  61. }
  62. }
  63. if ((i - 1) > 0 && (j + 1) < width)
  64. {
  65. if (land[(i - 1), (j + 1), 0, 0] == 1)
  66. {
  67. numberOfNeighbours++;
  68. }
  69. }
  70. if ((j + 1) < width)
  71. {
  72. if (land[i, (j + 1), 0, 0] == 1)
  73. {
  74. numberOfNeighbours++;
  75. }
  76. }
  77. if ((i + 1) < height && (j + 1) < width)
  78. {
  79. if (land[(i + 1), (j + 1), 0, 0] == 1)
  80. {
  81. numberOfNeighbours++;
  82. }
  83. }
  84. if ((i + 1) < height)
  85. {
  86. if (land[(i + 1), j, 0, 0] == 1)
  87. {
  88. numberOfNeighbours++;
  89. }
  90. }
  91. if ((i + 1) < height && (j - 1) > 0)
  92. {
  93. if (land[(i + 1), (j - 1), 0, 0] == 1)
  94. {
  95. numberOfNeighbours++;
  96. }
  97. }
  98. if ((j - 1) > 0)
  99. {
  100. if (land[i, (j - 1), 0, 0] == 1)
  101. {
  102. numberOfNeighbours++;
  103. }
  104. }
  105. if ((i - 1) > 0 && (j - 1) > 0)
  106. {
  107. if (land[(i - 1), (j - 1), 0, 0] == 1)
  108. {
  109. numberOfNeighbours++;
  110. }
  111. }
  112. if (numberOfNeighbours == 0)
  113. {
  114. Console.WriteLine("There are no neighbours at " + i + " " + j);
  115. }
  116. }
  117.  
  118. }
  119.  
  120. }
  121. for (int i = 0; i < width; i++)
  122. {
  123. for (int j = 0; j < height; j++)
  124. {
  125. if (land[i, j, 0, 0] == 0)
  126. {
  127. Console.Write("0 ");
  128. }
  129. else
  130. {
  131. Console.Write("1 ");
  132. }
  133. }
  134. Console.WriteLine();
  135. }
  136. Console.WriteLine(amountOfLand);
  137.  
  138. }
  139.  
  140. }
  141. }
Add Comment
Please, Sign In to add comment