Posted 29 August 2013 - 07:41 AM
hi everyone this is yet another one of my programs i have made.
i wanted to experiment around with screen mapping so i did this
about: this is a simple minesweeper game based off the original you click certain positions and it tells you how many mines
are around it or if you hit a mine you lose
more info: at the top of the file there is a bunch of variables(cColor, rColor) etc. these are the colors the game uses
change them to the colors you desire they should be described by a comment
notes:
updates will come out this is only basic atm.
planned -
i wanted to experiment around with screen mapping so i did this
about: this is a simple minesweeper game based off the original you click certain positions and it tells you how many mines
are around it or if you hit a mine you lose
more info: at the top of the file there is a bunch of variables(cColor, rColor) etc. these are the colors the game uses
change them to the colors you desire they should be described by a comment
notes:
updates will come out this is only basic atm.
planned -
-right button clicking to flag a square
-difficulties
-user made minefields
--and more fun stuff :)/>
pastebin : http://pastebin.com/ngvfpn8t orpastebin get ngvfpn8t minesweeper
U NO WANT TO CLICK LINK???Spoiler
w,h = term.getSize()
mColor = colors.black -- mine color: hidden
rColor = colors.red -- mine color: revealed
bColor = colors.black -- background color
cColor = colors.blue -- color when clicked on
--[[default colors
mColor = colors.black
rColor = colors.red
bColor = colors.black
cColor = colors.blue
]]
map = {}
lose = false
sMap = {}
function clear()
term.setBackgroundColor(2^15)
term.clear()
term.setCursorPos(1,1)
end
clear()
function setField()
-- blank field
for x = 1, w do
map[x] = {}
sMap[x] = {}
for y = 1, h do
map[x][y] = "noclick"
sMap[x][y] = 0
end
end
-- enter mine positions
for l = 1, h do
for m = 1, 4 do
minepos = math.random(1,w)
-- PRINT MINE POSITIONS
--paintutils.drawPixel(minepos, l, 32)
map[minepos][l] = "mine"
end
end
end
function countSurround(x,y)
s = 0
if x > 1 then if map[x-1][y] == "mine" then s = s + 1 end end
-- to the left
if x < w then if map[x+1][y] == "mine" then s = s + 1 end end
-- to the right
if y < h then if map[x][y+1] == "mine" then s = s + 1 end end
-- below
if y > 1 then if map[x][y-1] == "mine" then s = s + 1 end end
-- above
if y > 1 and x > 1 then if map[x-1][y-1] == "mine" then s = s + 1 end end
-- above, to the left
if y < h and x > 1 then if map[x-1][y+1] == "mine" then s = s + 1 end end
-- below, to left
if y > 1 and x < w then if map[x+1][y-1] == "mine" then s = s + 1 end end
-- above, to right
if y < h and x < w then if map[x+1][y+1] == "mine" then s = s + 1 end end
--below, to right
sMap[x][y] = s
end
function checkClick()
e, button, xPos, yPos = os.pullEvent("mouse_click")
if map[xPos][yPos] == "mine" then
lose = true
drawMap()
else
map[xPos][yPos] = "click"
countSurround(xPos,yPos)
end
end
function drawMap()
for a = 1, w do
for b = 1, h do
if map[a][b] == "noclick" then
paintutils.drawPixel(a,b,bColor)
elseif map[a][b] == "click" then
paintutils.drawPixel(a,b,cColor)
term.setCursorPos(a,B)/>/>/>/>
write(sMap[a][b])
elseif map[a][b] == "mine" then
if lose == false then paintutils.drawPixel(a,b,mColor) end
if lose == true then paintutils.drawPixel(a,b,rColor) end
end
end
os.queueEvent("pull")
os.pullEvent("pull")
--sleep(0)
end
end
setField()
while not lose do
drawMap()
checkClick()
end
sleep(5)
clear()
print[[
You Lost!
Program Made By Jadengregory00
]]