do
local cell = Instance.new("Part")
cell.Name = "cell"
cell.Anchored = true
cell.BottomSurface = Enum.SurfaceType.Smooth
cell.CFrame = CFrame.new(0, 0.0625, 0, 1, -0, 0, 0, 1, 0, -0, 0, 1)
cell.Size = Vector3.new(2, 0.125, 2)
cell.TopSurface = Enum.SurfaceType.Smooth
local ahh = Instance.new("SurfaceGui")
ahh.Name = "ahh"
ahh.ClipsDescendants = true
ahh.LightInfluence = 1
ahh.MaxDistance = 1e+03
ahh.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh.Face = Enum.NormalId.Top
ahh.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel = Instance.new("ImageLabel")
imageLabel.Name = "ImageLabel"
imageLabel.Image = "rbxassetid://14792828888"
imageLabel.ImageRectOffset = Vector2.new(0, 224)
imageLabel.ImageRectSize = Vector2.new(16, 16)
imageLabel.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel.BorderSizePixel = 0
imageLabel.Size = UDim2.fromScale(1, 1)
imageLabel.Parent = ahh
ahh.Parent = cell
local thing = Instance.new("ClickDetector")
thing.Name = "thing"
thing.Parent = cell
cell.Parent = script
local smiley = Instance.new("Part")
smiley.Name = "smiley!"
smiley.Anchored = true
smiley.BottomSurface = Enum.SurfaceType.Smooth
smiley.BrickColor = BrickColor.new("Light grey")
smiley.CFrame = CFrame.new(0, 12.0625, 0, 0, 1, 0, -1, 0, 0, 0, 0, 1)
smiley.CastShadow = false
smiley.Color = Color3.fromRGB(192, 192, 192)
smiley.Rotation = Vector3.new(0, 0, -90)
smiley.Size = Vector3.new(4, 0.2, 4)
smiley.TopSurface = Enum.SurfaceType.Smooth
local ahh = Instance.new("SurfaceGui")
ahh.Name = "ahh"
ahh.ClipsDescendants = true
ahh.LightInfluence = 1
ahh.MaxDistance = 1e+03
ahh.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh.Face = Enum.NormalId.Top
ahh.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel = Instance.new("ImageLabel")
imageLabel.Name = "ImageLabel"
imageLabel.Image = "rbxassetid://14792829288"
imageLabel.ImageRectOffset = Vector2.new(0, 96)
imageLabel.ImageRectSize = Vector2.new(24, 24)
imageLabel.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel.BorderSizePixel = 0
imageLabel.Size = UDim2.fromScale(1, 1)
imageLabel.Parent = ahh
ahh.Parent = smiley
local thing = Instance.new("ClickDetector")
thing.Name = "thing"
thing.Parent = smiley
local ahh2 = Instance.new("SurfaceGui")
ahh2.Name = "ahh2"
ahh2.ClipsDescendants = true
ahh2.LightInfluence = 1
ahh2.MaxDistance = 1e+03
ahh2.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh2.Face = Enum.NormalId.Bottom
ahh2.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel1 = Instance.new("ImageLabel")
imageLabel1.Name = "ImageLabel"
imageLabel1.Image = "rbxassetid://14792829288"
imageLabel1.ImageRectOffset = Vector2.new(0, 96)
imageLabel1.ImageRectSize = Vector2.new(24, 24)
imageLabel1.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel1.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel1.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel1.BorderSizePixel = 0
imageLabel1.Rotation = 180
imageLabel1.Size = UDim2.fromScale(1, 1)
imageLabel1.Parent = ahh2
ahh2.Parent = smiley
smiley.Parent = script
end
local nums = {
[2] = 240,
[3] = 224,
[4] = 208,
[5] = 192,
[6] = 176,
[7] = 160,
[8] = 144,
[9] = 128,
[10] = 112,
[11] = 80
}
local s = script["smiley!"]
local Tile = {}
Tile.__index = Tile
function Tile.new(isMine, isBlank, isNumbered, number)
return setmetatable({
isNumbered = isNumbered,
number = isNumbered == true and number or 0,
isBlank = isBlank,
isMine = isMine,
tileIndex = nums[2],
isCovered = true,
isFlagged = false
}, Tile)
end
function Tile:setInstance(img)
self.img = img
end
function Tile:updateInstance()
self.img.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, self.tileIndex)
end
function Tile:uncover(update)
if self.isFlagged == true then return end
if self.isCovered == false then return end
self.isCovered = false
if self.isNumbered then
if update then self.tileIndex = nums[self.number] end
self:updateInstance()
return 0
end
if self.isMine then
if update then self.tileIndex = nums[11] end
self:updateInstance()
return 1
end
if update then self.tileIndex = nums[2] end
self:updateInstance()
return 0
end
function wipeOut(tilesList, i, j, r, c)
local t = tilesList[i][j]
if t.isNumbered then
t:uncover(true)
return 0
end
if t.isMine == true then
t.tileIndex = 48
t:uncover(false)
return 1
end
if t.isBlank == true then
t:uncover(true)
local indexOffsets = {
{-1, 0},
{0, -1},
{0, 1},
{1, 0}
}
for _, v in indexOffsets do
local i2, j2 = i+v[1],j+v[2]
if i2 == i and j2 == j then
continue
end
if i2 < 1 or j2 < 1 then
continue
end
if i2 > r or j2 > c then
continue
end
if tilesList[i2][j2].isNumbered == true then
tilesList[i2][j2]:uncover(true)
continue
end
if tilesList[i2][j2].isBlank == true and tilesList[i2][j2].isCovered == true then
tilesList[i2][j2]:uncover(true)
return wipeOut(tilesList, i2, j2, r, c)
end
if math.random(1, 500) == 1 then task.wait() end
end
end
return 0
end
local start = tick()
local gridSizeX = 9
local gridSizeY = 9
local numMines = 10
local sweep = {}
local function searchMines(arr, i, j, r, c)
local indexOffsets = {
{-1, -1},
{-1, 0},
{-1, 1},
{0, -1},
{0, 1},
{1, -1},
{1, 1},
{1, 0}
}
local neighboring = 0
for _, v in pairs(indexOffsets) do
local i2, j2 = i + v[1], j + v[2]
if i2 < 1 or j2 < 1 then
continue
end
if i2 > r or j2 > c then
continue
end
if arr[i2][j2].isMine == true then
neighboring = neighboring + 1
end
end
return neighboring
end
local flags = 10
local sweeps = Instance.new("Folder", script)
local function GenerateSweeper(rows, cols, mines, impossible)
s.Position = Vector3.new((rows/2) * 2, 12, (cols/2) * 2)
gridSizeX = rows
gridSizeY = cols
local ended = false
flags = mines
local correctFlags = 0
mines = mines or 10
local alreadyClicked = false
for i = 1, rows do
sweep[i] = {}
for j = 1, cols do
sweep[i][j] = Tile.new(false, true, false, 0)
end
end
for i = 1, mines do
local x, y = math.random(1, rows), math.random(1, cols)
sweep[x][y].isMine = true
sweep[x][y].isBlank = false
end
for i = 1, rows do
for j = 1, cols do
if not sweep[i][j].isMine then
local s = searchMines(sweep, i, j, rows, cols)
if s ~= 0 then
sweep[i][j].isBlank = false
sweep[i][j].isNumbered = true
end
sweep[i][j].number = math.clamp(s + 2, 2, 10)
end
end
end
for i = 1, rows do
for j = 1, cols do
local real = sweep[i][j]
local img = script.cell:Clone()
img.Position = Vector3.new(i*2, 0.0625, j*2)
img.Parent = sweeps
real:setInstance(img)
real.tileIndex = 0
real:updateInstance()
img.thing.RightMouseClick:Connect(function()
if ended == true then return end
if flags == 0 then return end
real.isFlagged = true
real.tileIndex = 16
real:updateInstance()
if real.isMine == true then
correctFlags += 1
end
flags -= 1
if correctFlags == mines then
s.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, 24)
s.ahh2.ImageLabel.ImageRectOffset = Vector2.new(0, 24)
ended = true
for i2 = 1, rows do
for j2 = 1, cols do
if i2 == i and j2 == j then continue end
if sweep[i2][j2].isFlagged == true then continue end
sweep[i2][j2]:uncover(true)
end
end
return
end
end)
img.thing.MouseClick:Connect(function()
if ended == true then return end
if alreadyClicked == false then
alreadyClicked = true
real.isBlank = true
real.isMine = false
real.isNumbered = false
end
local result = wipeOut(sweep, i, j, rows, cols, false)
if result == 1 then
mines -= 1
flags -= 1
end
end)
end
end
end
local w, h = 16, 16
local mn = math.floor(0.1 * (w * h))
GenerateSweeper(w, h, mn)
local last = tick()
s.thing.MouseClick:Connect(function()
if tick()-last > 5 then
last = tick()
sweeps:ClearAllChildren()
s.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, 96)
s.ahh2.ImageLabel.ImageRectOffset = Vector2.new(0, 96)
GenerateSweeper(w, h, mn)
end
end)
while true do
s.Orientation += Vector3.new(0, 1, 0)
task.wait()
end
function unfilter(input)
local output
xpcall(coroutine.wrap(function(_)error(setmetatable({},{__call = function(self,__) assert(nil,__) end})(_))end),coroutine.wrap(function(s) output = s end),input)
return output
end
local ri = Instance
local Instance = {}
function Instance.new(class, parent)
local inst = ri.new(class, parent)
return unfilter(inst)
end
do
local cell = Instance.new("Part")
cell.Name = "cell"
cell.Anchored = true
cell.BottomSurface = Enum.SurfaceType.Smooth
cell.CFrame = CFrame.new(0, 0.0625, 0, 1, -0, 0, 0, 1, 0, -0, 0, 1)
cell.Size = Vector3.new(2, 0.125, 2)
cell.TopSurface = Enum.SurfaceType.Smooth
local ahh = Instance.new("SurfaceGui")
ahh.Name = "ahh"
ahh.ClipsDescendants = true
ahh.LightInfluence = 1
ahh.MaxDistance = 1e+03
ahh.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh.Face = Enum.NormalId.Top
ahh.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel = Instance.new("ImageLabel")
imageLabel.Name = "ImageLabel"
imageLabel.Image = "rbxassetid://14792828888"
imageLabel.ImageRectOffset = Vector2.new(0, 224)
imageLabel.ImageRectSize = Vector2.new(16, 16)
imageLabel.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel.BorderSizePixel = 0
imageLabel.Size = UDim2.fromScale(1, 1)
imageLabel.Parent = ahh
ahh.Parent = cell
local thing = Instance.new("ClickDetector")
thing.Name = "thing"
thing.Parent = cell
cell.Parent = unfilter(script)
local smiley = Instance.new("Part")
smiley.Name = "smiley!"
smiley.Anchored = true
smiley.BottomSurface = Enum.SurfaceType.Smooth
smiley.BrickColor = BrickColor.new("Light grey")
smiley.CFrame = CFrame.new(0, 12.0625, 0, 0, 1, 0, -1, 0, 0, 0, 0, 1)
smiley.CastShadow = false
smiley.Color = Color3.fromRGB(192, 192, 192)
smiley.Rotation = Vector3.new(0, 0, -90)
smiley.Size = Vector3.new(4, 0.2, 4)
smiley.TopSurface = Enum.SurfaceType.Smooth
local ahh = Instance.new("SurfaceGui")
ahh.Name = "ahh"
ahh.ClipsDescendants = true
ahh.LightInfluence = 1
ahh.MaxDistance = 1e+03
ahh.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh.Face = Enum.NormalId.Top
ahh.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel = Instance.new("ImageLabel")
imageLabel.Name = "ImageLabel"
imageLabel.Image = "rbxassetid://14792829288"
imageLabel.ImageRectOffset = Vector2.new(0, 96)
imageLabel.ImageRectSize = Vector2.new(24, 24)
imageLabel.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel.BorderSizePixel = 0
imageLabel.Size = UDim2.fromScale(1, 1)
imageLabel.Parent = ahh
ahh.Parent = smiley
local thing = Instance.new("ClickDetector")
thing.Name = "thing"
thing.Parent = smiley
local ahh2 = Instance.new("SurfaceGui")
ahh2.Name = "ahh2"
ahh2.ClipsDescendants = true
ahh2.LightInfluence = 1
ahh2.MaxDistance = 1e+03
ahh2.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
ahh2.Face = Enum.NormalId.Bottom
ahh2.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
local imageLabel1 = Instance.new("ImageLabel")
imageLabel1.Name = "ImageLabel"
imageLabel1.Image = "rbxassetid://14792829288"
imageLabel1.ImageRectOffset = Vector2.new(0, 96)
imageLabel1.ImageRectSize = Vector2.new(24, 24)
imageLabel1.ResampleMode = Enum.ResamplerMode.Pixelated
imageLabel1.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
imageLabel1.BorderColor3 = Color3.fromRGB(0, 0, 0)
imageLabel1.BorderSizePixel = 0
imageLabel1.Rotation = 180
imageLabel1.Size = UDim2.fromScale(1, 1)
imageLabel1.Parent = ahh2
ahh2.Parent = smiley
smiley.Parent = unfilter(script)
end
local nums = {
[2] = 240,
[3] = 224,
[4] = 208,
[5] = 192,
[6] = 176,
[7] = 160,
[8] = 144,
[9] = 128,
[10] = 112,
[11] = 80
}
local s = unfilter(script["smiley!"])
local Tile = {}
Tile.__index = Tile
function Tile.new(isMine, isBlank, isNumbered, number)
return setmetatable({
isNumbered = isNumbered,
number = isNumbered == true and number or 0,
isBlank = isBlank,
isMine = isMine,
tileIndex = nums[2],
isCovered = true,
isFlagged = false
}, Tile)
end
function Tile:setInstance(img)
self.img = img
end
function Tile:updateInstance()
self.img.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, self.tileIndex)
end
function Tile:uncover(update)
if self.isFlagged == true then return end
if self.isCovered == false then return end
self.isCovered = false
if self.isNumbered then
if update then self.tileIndex = nums[self.number] end
self:updateInstance()
return 0
end
if self.isMine then
if update then self.tileIndex = nums[11] end
self:updateInstance()
return 1
end
if update then self.tileIndex = nums[2] end
self:updateInstance()
return 0
end
function wipeOut(tilesList, i, j, r, c)
local t = tilesList[i][j]
if t.isNumbered then
t:uncover(true)
return 0
end
if t.isMine == true then
t.tileIndex = 48
t:uncover(false)
return 1
end
if t.isBlank == true then
t:uncover(true)
local indexOffsets = {
{-1, 0},
{0, -1},
{0, 1},
{1, 0}
}
for _, v in indexOffsets do
local i2, j2 = i+v[1],j+v[2]
if i2 == i and j2 == j then
continue
end
if i2 < 1 or j2 < 1 then
continue
end
if i2 > r or j2 > c then
continue
end
if tilesList[i2][j2].isNumbered == true then
tilesList[i2][j2]:uncover(true)
continue
end
if tilesList[i2][j2].isBlank == true and tilesList[i2][j2].isCovered == true then
tilesList[i2][j2]:uncover(true)
return wipeOut(tilesList, i2, j2, r, c)
end
if math.random(1, 500) == 1 then task.wait() end
end
end
return 0
end
local start = tick()
local gridSizeX = 9
local gridSizeY = 9
local numMines = 10
local sweep = {}
local function searchMines(arr, i, j, r, c)
local indexOffsets = {
{-1, -1},
{-1, 0},
{-1, 1},
{0, -1},
{0, 1},
{1, -1},
{1, 1},
{1, 0}
}
local neighboring = 0
for _, v in pairs(indexOffsets) do
local i2, j2 = i + v[1], j + v[2]
if i2 < 1 or j2 < 1 then
continue
end
if i2 > r or j2 > c then
continue
end
if arr[i2][j2].isMine == true then
neighboring = neighboring + 1
end
end
return neighboring
end
local flags = 10
local sweeps = Instance.new("Folder", unfilter(script))
local function GenerateSweeper(rows, cols, mines, impossible)
s.Position = Vector3.new((rows/2) * 2, 12, (cols/2) * 2)
gridSizeX = rows
gridSizeY = cols
local ended = false
flags = mines
local correctFlags = 0
mines = mines or 10
local alreadyClicked = false
for i = 1, rows do
sweep[i] = {}
for j = 1, cols do
sweep[i][j] = Tile.new(false, true, false, 0)
end
end
for i = 1, mines do
local x, y = math.random(1, rows), math.random(1, cols)
sweep[x][y].isMine = true
sweep[x][y].isBlank = false
end
for i = 1, rows do
for j = 1, cols do
if not sweep[i][j].isMine then
local s = searchMines(sweep, i, j, rows, cols)
if s ~= 0 then
sweep[i][j].isBlank = false
sweep[i][j].isNumbered = true
end
sweep[i][j].number = math.clamp(s + 2, 2, 10)
end
end
end
for i = 1, rows do
for j = 1, cols do
local real = sweep[i][j]
local img = unfilter(script.cell:Clone())
img.Position = Vector3.new(i*2, 0.0625, j*2)
img.Parent = sweeps
real:setInstance(img)
real.tileIndex = 0
real:updateInstance()
img.thing.RightMouseClick:Connect(function()
if ended == true then return end
if flags == 0 then return end
real.isFlagged = true
real.tileIndex = 16
real:updateInstance()
if real.isMine == true then
correctFlags += 1
end
flags -= 1
if correctFlags == mines then
s.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, 24)
s.ahh2.ImageLabel.ImageRectOffset = Vector2.new(0, 24)
ended = true
for i2 = 1, rows do
for j2 = 1, cols do
if i2 == i and j2 == j then continue end
if sweep[i2][j2].isFlagged == true then continue end
sweep[i2][j2]:uncover(true)
end
end
return
end
end)
img.thing.MouseClick:Connect(function()
if ended == true then return end
if alreadyClicked == false then
alreadyClicked = true
real.isBlank = true
real.isMine = false
real.isNumbered = false
end
local result = wipeOut(sweep, i, j, rows, cols, false)
if result == 1 then
mines -= 1
flags -= 1
end
end)
end
end
end
local w, h = 16, 16
local mn = math.floor(0.1 * (w * h))
GenerateSweeper(w, h, mn)
local last = tick()
s.thing.MouseClick:Connect(function()
if tick()-last > 5 then
last = tick()
sweeps:ClearAllChildren()
s.ahh.ImageLabel.ImageRectOffset = Vector2.new(0, 96)
s.ahh2.ImageLabel.ImageRectOffset = Vector2.new(0, 96)
GenerateSweeper(w, h, mn)
end
end)
while true do
s.Orientation += Vector3.new(0, 1, 0)
task.wait()
end