Advertisement
BobMe

mineswep

Aug 3rd, 2023 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.69 KB | None | 0 0
  1. -- Instances:
  2.  
  3. local Clone = Instance.new("Frame")
  4. local TextLabel = Instance.new("TextLabel")
  5.  
  6. --Properties:
  7.  
  8. Clone.Name = "Clone"
  9. Clone.Parent = nil
  10. Clone.BackgroundColor3 = Color3.fromRGB(255, 176, 247)
  11. Clone.BorderColor3 = Color3.fromRGB(199, 116, 192)
  12. Clone.BorderSizePixel = 2
  13. Clone.Size = UDim2.new(0, 50, 0, 50)
  14.  
  15. TextLabel.Parent = Clone
  16. TextLabel.AnchorPoint = Vector2.new(0.5, 0.5)
  17. TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  18. TextLabel.BackgroundTransparency = 1.000
  19. TextLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
  20. TextLabel.BorderSizePixel = 0
  21. TextLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
  22. TextLabel.Size = UDim2.new(0.699999988, 0, 0.699999988, 0)
  23. TextLabel.Font = Enum.Font.SourceSans
  24. TextLabel.Text = " "
  25. TextLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
  26. TextLabel.TextScaled = true
  27. TextLabel.TextSize = 14.000
  28. TextLabel.TextWrapped = true
  29.  
  30.  
  31. local x = 10
  32. local y = 10
  33. local bombs = 15
  34. local g = NP("Minesweeper",true,x*50,(y*50)+30)
  35. local map = {}
  36.  
  37. local function isNumber(x)
  38. if x == "0" or x == "1" or x == "2" or x == "3" or x == "4" or x == "5" or x == "6" or x == "7" or x == "8" or x == "9" then
  39. return true
  40. else
  41. return false
  42. end
  43. end
  44.  
  45. local function zerofill(xx,yy)
  46. local tofill = {{xx,yy,0}} -- { {x,y,0} } 0 is amount of times dided
  47. local cx,cy = xx,yy
  48. local canfill = true
  49.  
  50. while canfill do
  51. --wait(.5)
  52. local oldcount = #tofill
  53. for i=1,oldcount do
  54. local v = tofill[i]
  55. if v[3] == 0 then
  56. v[3] = v[3] + 1
  57. -- west
  58. if v[2]-1 >= 1 then
  59. if map[v[1]][v[2]-1][1] == "0" then
  60. local clone = g.OuterFrame:FindFirstChild(map[v[1]][v[2]-1][2])
  61. clone.TextLabel.Text = " "
  62. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  63. table.insert(tofill,{v[1],v[2]-1,0})
  64. else
  65. local clon = g.OuterFrame:FindFirstChild(map[v[1]][v[2]-1][2])
  66. clon.TextLabel.Text = map[v[1]][v[2]-1][1]
  67. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  68. end
  69. end
  70. -- south
  71. if v[1]-1 >= 1 then
  72. if map[v[1]-1][v[2]][1] == "0" then
  73. local clone = g.OuterFrame:FindFirstChild(map[v[1]-1][v[2]][2])
  74. clone.TextLabel.Text = " "
  75. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  76. table.insert(tofill,{v[1]-1,v[2],0})
  77. else
  78. local clon = g.OuterFrame:FindFirstChild(map[v[1]-1][v[2]][2])
  79. clon.TextLabel.Text = map[v[1]-1][v[2]][1]
  80. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  81. end
  82. end
  83. -- east
  84. if v[2]+1 <= y then
  85. if map[v[1]][v[2]+1][1] == "0" then
  86. local clone = g.OuterFrame:FindFirstChild(map[v[1]][v[2]+1][2])
  87. clone.TextLabel.Text = " "
  88. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  89. table.insert(tofill,{v[1],v[2]+1,0})
  90. else
  91. local clon = g.OuterFrame:FindFirstChild(map[v[1]][v[2]+1][2])
  92. clon.TextLabel.Text = map[v[1]][v[2]+1][1]
  93. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  94. end
  95. end
  96. -- south
  97. if v[1]+1 <= x then
  98. if map[v[1]+1][v[2]][1] == "0" then
  99. local clone = g.OuterFrame:FindFirstChild(map[v[1]+1][v[2]][2])
  100. clone.TextLabel.Text = " "
  101. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  102. table.insert(tofill,{v[1]+1,v[2],0})
  103. else
  104. local clon = g.OuterFrame:FindFirstChild(map[v[1]+1][v[2]][2])
  105. clon.TextLabel.Text = map[v[1]+1][v[2]][1]
  106. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  107. end
  108. end
  109. else
  110. table.remove(tofill,i)
  111. break
  112. end
  113. end
  114. if oldcount == #tofill then
  115. --print("DFGNJKGK")
  116. canfill = false
  117. end
  118. --print("loop")
  119. end
  120. end
  121.  
  122. --[[local function zerofill(xx,yy)
  123. print('looped')
  124. if xx > 0 and xx <= x and yy > 0 and yy <= y then -- isFillable part 1
  125. local clone = g.OuterFrame:FindFirstChild(map[xx][yy][2])
  126. if map[xx][yy][1] == "0" then -- isFillable part 2
  127. clone.TextLabel.Text = " "
  128. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  129. else
  130. clone.TextLabel.Text = map[xx][yy][1]
  131. clone.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  132. end
  133. zerofill(xx+1,yy)
  134. zerofill(xx-1,yy)
  135. zerofill(xx,yy-1)
  136. zerofill(xx,yy+1)
  137. else
  138. return
  139. end
  140. end]]
  141.  
  142.  
  143. for i=1,x do
  144. local xgrid = {}
  145. for ii=1,y do
  146. local clon = Clone:Clone()
  147. clon.Position = UDim2.new(0,(i-1)*50,0,(ii-1)*50)
  148. clon.Parent = g.OuterFrame
  149. clon.Name = "a"..tostring(math.random(111111111,999999999))
  150. table.insert(xgrid,{"0",clon.Name})
  151. local left = Instance.new("BoolValue",clon)
  152. left.Name = "Button"
  153. left.Changed:Connect(function(change)
  154. if change == true then
  155. if clon.TextLabel.Text ~= " " then
  156. if map[i][ii][1] == "bomb" then
  157. clon.TextLabel.Text = "💣"
  158. else
  159. if map[i][ii][1] ~= "0" then
  160. clon.TextLabel.Text = map[i][ii][1]
  161. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  162. else
  163. clon.TextLabel.Text = " "
  164. clon.BackgroundColor3 = Color3.fromRGB(255*.85, 176*.85, 247*.85)
  165. zerofill(i,ii)
  166. end
  167. end
  168. left.Value = false
  169. end
  170. end
  171. end)
  172. local right = Instance.new("BoolValue",clon)
  173. right.Name = "ButtonRight"
  174. right.Changed:Connect(function(change)
  175. if change == true then
  176. if not isNumber(clon.TextLabel.Text) and clon.TextLabel.Text ~= " " then
  177. if string.byte(clon.TextLabel.Text) == 240 then
  178. clon.TextLabel.Text = " "
  179. else
  180. clon.TextLabel.Text = "🚩"
  181. end
  182. end
  183. right.Value = false
  184. end
  185. end)
  186. end
  187. table.insert(map,xgrid)
  188. end
  189.  
  190. local currentb = 0
  191. while currentb ~= bombs do
  192. local randomx = math.random(1,x)
  193. local randomy = math.random(1,y)
  194. if map[randomx][randomy][1] ~= "bomb" then
  195. map[randomx][randomy][1] = "bomb"
  196. currentb = currentb + 1
  197. if randomx-1 >= 1 and randomx-1 <= x and randomy-1 >= 1 and randomy-1 <= y and map[randomx-1][randomy-1][1] ~= "bomb" then
  198. local num = tonumber(map[randomx-1][randomy-1][1])+1
  199. map[randomx-1][randomy-1][1] = tostring(num)
  200. end
  201. if randomx-1 >= 1 and randomx-1 <= x and randomy >= 1 and randomy <= y and map[randomx-1][randomy][1] ~= "bomb" then
  202. local num = tonumber(map[randomx-1][randomy][1])+1
  203. map[randomx-1][randomy][1] = tostring(num)
  204. end
  205. if randomx-1 >= 1 and randomx-1 <= x and randomy+1 >= 1 and randomy+1 <= y and map[randomx-1][randomy+1][1] ~= "bomb" then
  206. local num = tonumber(map[randomx-1][randomy+1][1])+1
  207. map[randomx-1][randomy+1][1] = tostring(num)
  208. end
  209. if randomx >= 1 and randomx <= x and randomy-1 >= 1 and randomy-1 <= y and map[randomx][randomy-1][1] ~= "bomb" then
  210. local num = tonumber(map[randomx][randomy-1][1])+1
  211. map[randomx][randomy-1][1] = tostring(num)
  212. end
  213. if randomx >= 1 and randomx <= x and randomy+1 >= 1 and randomy+1 <= y and map[randomx][randomy+1][1] ~= "bomb" then
  214. local num = tonumber(map[randomx][randomy+1][1])+1
  215. map[randomx][randomy+1][1] = tostring(num)
  216. end
  217. --
  218. if randomx+1 >= 1 and randomx+1 <= x and randomy-1 >= 1 and randomy-1 <= y and map[randomx+1][randomy-1][1] ~= "bomb" then
  219. local num = tonumber(map[randomx+1][randomy-1][1])+1
  220. map[randomx+1][randomy-1][1] = tostring(num)
  221. end
  222. if randomx+1 >= 1 and randomx+1 <= x and randomy >= 1 and randomy <= y and map[randomx+1][randomy][1] ~= "bomb" then
  223. local num = tonumber(map[randomx+1][randomy][1])+1
  224. map[randomx+1][randomy][1] = tostring(num)
  225. end
  226. if randomx+1 >= 1 and randomx+1 <= x and randomy+1 >= 1 and randomy+1 <= y and map[randomx+1][randomy+1][1] ~= "bomb" then
  227. local num = tonumber(map[randomx+1][randomy+1][1])+1
  228. map[randomx+1][randomy+1][1] = tostring(num)
  229. end
  230. end
  231. end
  232.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement