Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local b,c=term,math;local d,e,f,g,h=b.clear,b.setCursorPos,b.setTextColor,b.setBackgroundColor,b.write;local j=fs.getDir(shell.getRunningProgram())local k,l=b.getSize()l=l-1;assert(b.isColor(),"Advanced Computer Required.")local m,n=true,"Lost"local o={"white","orange","magenta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"}local p={colors.green,colors.green,colors.yellow,colors.orange,colors.magenta,colors.purple,colors.lightGray,colors.red}local q={display={text={flag="orange",masked="gray",foreground="black",bomb="red",highlight="lightGray",invalidflag="red",validflag="cyan"},sprites={numbs={"1","2","3","4","5","6","7","8"},flag="^",bomb="!",masked="#",foreground=" ",highlight="-",invalidflag="^",validflag="^"},background={foreground="black",masked="black",flag="lightGray",bomb="black",highlight="black",invalidflag="black",validflag="black"}},settings={enableHighlight=false},number_colors={"lime","green","yellow","orange","magenta","purple","lightGray","red"}}local r=nil;if fs.exists(j.."/theme.lua")then local s=fs.open(j.."/theme.lua","r")r=textutils.unserialize(s.readAll())s.close()end;if r then if r.display then if r.text then q.text=r.text end;if r.sprites then q.sprites=r.sprites end;if r.background then q.background=r.background end end;if r.settings then q.settings=r.settings end;if r.number_colors then q.number_colors=r.number_colors end end;local t,u,v={},{true,0},c.ceil(k*l/c.random(70,100))*10;local w={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{1,-1},{-1,1}}local function z(A,B)local C=0;for i=1,#w do if t[B+w[i][1]]then if t[B+w[i][1]][A+w[i][2]]then if t[B+w[i][1]][A+w[i][2]][1]==10 then C=C+1 end end end end;return C end;local function D()t={}t.x,t.y=k,l;t.totalBombs=v;t.flags=0;t.correctFlags=0;n="Lost"for i=1,t.y do t[i]={}for E=1,t.x do t[i][E]={9,0}end end;local F,G;for i=1,t.totalBombs do local H=true;while H do G=c.random(1,t.y)for E=1,#t[G]do if t[G][E][1]==9 then H=false end end end;repeat F=c.random(1,t.x)until t[G][F][1]==9;t[G][F][1]=10 end;for i=1,#t do for E=1,#t[i]do if t[i][E][1]==9 then t[i][E][1]=z(E,i)end end end end;local function I(x,y)e(x,y)if t[y][x][2]==0 then g(colors[q.display.background.masked]or colors.black)f(colors[q.display.text.masked]or colors.gray)h(q.display.sprites.masked or"#")elseif t[y][x][2]==1 then if t[y][x][1]==10 then g(colors[q.display.background.bomb]or colors.black)f(colors[q.display.text.bomb]or colors.red)h(q.display.sprites.bomb or"!")elseif t[y][x][1]==0 then g(colors[q.display.background.foreground]or colors.black)f(colors[q.display.text.foreground]or colors.black)h(q.display.sprites.foreground or" ")else g(colors[q.display.background.foreground]or colors.black)f(colors[q.number_colors[t[y][x][1]]or 1]or p[t[y][x][1]or 1])h(q.display.sprites.numbs[t[y][x][1]]or"0")end elseif t[y][x][2]==2 then g(colors[q.display.background.masked]or colors.black)f(colors[q.display.text.flag]or colors.orange)h(q.display.sprites.flag or"^")elseif t[y][x][2]==3 then g(colors[q.display.background.validflag]or colors.black)f(colors[q.display.text.validflag]or colors.cyan)h(q.display.sprites.validflag or"^")elseif t[y][x][2]==4 then g(colors[q.display.background.invalidflag]or colors.black)f(colors[q.display.text.invalidflag]or colors.red)h(q.display.sprites.invalidflag or"^")else h(t[y][x][1])end end;local function J()e(1,1)for i=1,#t do e(1,i)for E=1,#t[i]do I(E,i)end end end;local function K()local loop,L=true,1;g(colors.black)f(colors.white)d()local M={}while loop do for i=1,#M do e(1,i)if i==L then g(colors.black)f(colors.white)h("< ")h(M[i][1])h(" >")else g(colors.black)f(colors.gray)h(" ")h(M[i][1])h(" ")end end;local a,i=os.pullEvent("key")if i==keys.w or i==keys.up then if L~=1 then L=L-1 end elseif i==keys.s or i==keys.down then if L~=#M then L=L+1 end elseif i==keys.enter or i==keys.e then if type(M[L][2])~="table"then M[L][2]()end elseif i==keys.q then loop=false end end;d()end;local function N()if q.display.sprites.flag then e(k-string.len(" "..q.display.sprites.flag..t.totalBombs-t.flags.." Time: "..u[2]),l+1)else e(k-string.len(" ^"..t.totalBombs-t.flags.." Time: "..u[2]),l+1)end;g(colors[q.display.background.masked]or colors.black)f(colors[q.display.text.flag]or colors.orange)h(" "..q.display.sprites.flag or"^")f(colors.white)g(colors.black)h(t.totalBombs-t.flags.." ")end;local function O()local M={{"Reset",function()D()u[2]=0;J()N()end},{"Clr Flags",function()for i=1,#t do for E=1,#t[i]do if t[i][E][2]==2 then t[i][E][2]=0 end end end;J()end},{"Exit",function()n="Exit"m=false end}}f(colors.gray)g(colors.black)e(1,l+1)h("[Menu]")while m do sleep(.001)a,i=os.pullEvent("key")if i==keys.leftCtrl or i==keys.rightCtrl then local P,L=true,1;u[1]=false;while P do e(1,l+1)for i=1,#M do if L==i then f(colors.yellow)h("["..M[i][1].."]")else f(colors.gray)h(" "..M[i][1].." ")end end;a,i=os.pullEvent("key")if i==keys.d or i==keys.right then if L~=#M then L=L+1 end elseif i==keys.a or i==keys.left then if L~=1 then L=L-1 end elseif i==keys.enter or i==keys.e then M[L][2]()P=false elseif i==keys.q or i==keys.leftCtrl or i==keys.rightCtrl then P=false end end;f(colors.black)g(colors.black)e(1,l+1)for i=1,#M do h(" "..M[i][1].." ")end;f(colors.gray)g(colors.black)e(1,l+1)h("[Menu]")u[1]=true end end end;local function Q()local R={}local function S(x,y)for i=1,#w do if t[y+w[i][1]]then if t[y+w[i][1]][x+w[i][2]]then if t[y+w[i][1]][x+w[i][2]][2]==0 and t[y+w[i][1]][x+w[i][2]][1]~=9 and t[y+w[i][1]][x+w[i][2]][2]~=10 then t[y+w[i][1]][x+w[i][2]][2]=1;if t[y+w[i][1]][x+w[i][2]][1]==0 then R[#R+1]={x+w[i][2],y+w[i][1]}end;I(x+w[i][2],y+w[i][1])end end end end end;local function T(x,y,U)for i=1,#w do if t[y+w[i][1]]then if t[y+w[i][1]][x+w[i][2]]then if U then e(x+w[i][2],y+w[i][1])f(colors[q.display.text.highlight]or colors.lightGray)g(colors[q.display.background.highlight]or colors.black)h(q.display.sprites.highlight or"-")else I(x+w[i][2],y+w[i][1])end end end end end;while m do a,i,x,y=os.pullEvent("mouse_click")if i==1 then if t[y][x][2]~=2 then if q.settings.enableHighlight then T(x,y,true)os.pullEvent("mouse_up")T(x,y,false)end;t[y][x][2]=1;if t[y][x][1]==10 then m=false elseif t[y][x][1]==0 then S(x,y)repeat local C=#R;for i=1,#R do S(R[i][1],R[i][2])end until#R==C end;I(x,y)end elseif i==2 or i==3 then if t[y][x][2]~=2 and t[y][x][2]~=1 and t.flags~=t.totalBombs then t[y][x][2]=2;t.flags=t.flags+1;if t[y][x][1]==10 then t.correctFlags=t.correctFlags+1 end;N()elseif t[y][x][2]==2 then t[y][x][2]=0;t.flags=t.flags-1;if t[y][x][1]==10 then t.correctFlags=t.correctFlags-1 end;N()end;if t.correctFlags==t.totalBombs then n="Win"m=false end;I(x,y)end end end;local function V()while true do if u[2]>0 then u[2]=0 end;while m do if u[1]then f(colors.white)g(colors.black)e(k-string.len("Time: "..u[2]),l+1)h("Time: "..u[2])sleep(1)u[2]=u[2]+1 else sleep(.00001)end end;sleep(.00001)end end;local function W()D()d()J()N()m=true;parallel.waitForAny(Q,O,V)if n~="Exit"then for i=1,#t do for E=1,#t[i]do if t[i][E][1]==10 and t[i][E][2]==2 then t[i][E][2]=3 elseif t[i][E][1]~=10 and t[i][E][2]==2 then t[i][E][2]=4 else t[i][E][2]=1 end end end;J()e(1,l+1)f(colors.white)g(colors.black)sleep(1)h(n..". Press any key to exit...")sleep(.2)os.pullEvent()end;d()e(1,1)end;local function X()local Y,Z,L=true,1,1;local c={{{"Play Game",function()W()end},{"Set Bombs",function()d()e(1,1)f(colors.white)h("Bombs: ")local C=tonumber(read())if type(C)=="number"then v=c.min(c.max(C,1),k*l-1)end end},{"Create a Theme file",function()f(colors.white)if not fs.exists(j.."/theme.lua")then local s=fs.open(j.."/theme.lua","w")if s then s.wr(textutils.serialize(q))s.close()d()e(1,1)h("Theme file created at '"..j.."/theme.lua'.")else d()e(1,1)h("Failed to create File at '"..j.."/theme.lua'.")end else d()e(1,1)h("Theme file Already exists at '"..j.."/theme.lua'.")sleep(.5)end;sleep(1)loop=false end},{"Exit",function()Y=false end}}}d()while Y do e(1,1)g(colors.black)f(colors.lime)print("Minesweeper")e(1,3)for i=1,#c[Z]do if i==L then f(colors.white)print("> "..c[Z][i][1].." ")else f(colors.gray)print(" "..c[Z][i][1].." ")end end;e(1,l+1)f(colors.gray)h("Bombs: "..v)a,i=os.pullEvent("key")if i==keys.w or i==keys.up then if L~=1 then L=L-1 end elseif i==keys.s or i==keys.down then if L~=#c[Z]then L=L+1 end elseif i==keys.enter or i==keys.e then c[Z][L][2]()d()end end end;X()g(colors.black)f(colors.white)d()e(1,1)sleep(.1)
Advertisement
Add Comment
Please, Sign In to add comment