Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- map = {}
- mX,mY = term.getSize()
- function newMap(handle)
- for i=1,mY do
- map[i] = {}
- for j=1,(mX / 3) * 2 do
- map[i][j] = "*"
- if j > math.ceil(((mX /3) * 2)/2)-1 then
- if j < math.ceil(((mX /3) * 2)/2)+3 then
- if i > math.ceil(mY/2)-2 then
- if i < math.ceil(mY/2)+2 then
- map[i][j] = "0"
- end
- end
- end
- end
- if i == math.ceil(mY/2) then
- if j == math.ceil(((mX /3) * 2)/2)+1 then
- map[i][j] = "H"
- end
- end
- end
- end
- for i=1,mY do
- for j=1,(mX / 3) * 2 do
- handle.writeLine(map[i][j])
- end
- end
- handle.close()
- end
- function readMap(tableData)
- mapData = {}
- i=1
- while true do
- tmp = tableData.readLine()
- if tmp == nil then
- break
- else
- mapData[i] = tmp
- end
- i = i + 1
- end
- k = 1
- for i=1,mY do
- for j=1,(mX / 3) * 2 do
- if map[i] == nil then map[i] = {} end
- if mapData[i] ~= nil then
- map[i][j] = mapData[k]
- end
- k = k + 1
- end
- end
- tableData.close()
- end
- function saveAll()
- handle = fs.open("mine.sav","w")
- for i=1,mY do
- for j=1,(mX / 3) * 2 do
- handle.writeLine(map[i][j])
- end
- end
- handle.close()
- end
- if fs.exists("mine.sav") == false then
- save = fs.open("mine.sav","w")
- newMap(save)
- else
- save = fs.open("mine.sav","r")
- readMap(save)
- end
- function showMap()
- for i=1,mY do
- for j=1,(mX / 3) * 2 do
- term.setCursorPos(j,i)
- if map[i][j] == "*" then
- term.setBackgroundColor(colors.magenta)
- write(" ")
- elseif map[i][j] == "0" then
- term.setBackgroundColor(colors.brown)
- write(" ")
- elseif map[i][j] == "H" then
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- write("H")
- elseif map[i][j] == "A" then
- term.setBackgroundColor(colors.orange)
- write(" ")
- elseif map[i][j] == "C" then
- term.setBackgroundColor(colors.cyan)
- write(" ")
- end
- end
- end
- end
- intSel = 1
- strings = {}
- table.insert(strings,"Regular")
- table.insert(strings,"Avaliable")
- table.insert(strings,"Off Limits")
- table.insert(strings,"Completed")
- function showInterface()
- for i=(mX/3)*2+2,mX do
- for j=1,mY do
- term.setCursorPos(i,j)
- term.setBackgroundColor(colors.yellow)
- write(" ")
- end
- end
- for i=1,mY do
- term.setCursorPos((mX/3)*2+1,i)
- term.setBackgroundColor(colors.gray)
- write(" ")
- end
- for i=1,4 do
- term.setTextColor(colors.white)
- if i==1 then
- term.setBackgroundColor(colors.magenta)
- elseif i==2 then
- term.setBackgroundColor(colors.orange)
- elseif i==3 then
- term.setBackgroundColor(colors.brown)
- elseif i==4 then
- term.setBackgroundColor(colors.cyan)
- end
- term.setCursorPos((mX/3)*2+4,5+i)
- write(" ")
- term.setCursorPos((mX/3)*2+5,5+i)
- write(strings[i])
- end
- term.setCursorPos(mX,1)
- term.setBackgroundColor(colors.red)
- write("X")
- end
- function updateInterface()
- term.setCursorPos((mX/3)*2+3,5+intSel)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- write("*")
- e,par1,par2,par3 = os.pullEvent()
- if e == "mouse_click" or e == "mouse_drag" then
- if par1 == 1 then
- if par2 > ((mX/3)*2+4) and par2 < ((mX/3)*2+17) then
- if par3 == 6 then
- --Regular
- intSel = 1
- elseif par3 == 7 then
- --Avaliable
- intSel = 2
- elseif par3 == 8 then
- --Off Limits
- intSel = 3
- elseif par3 == 9 then
- --Complete
- intSel = 4
- end
- end
- if par3 ~= math.ceil(mY/2) or par2 ~= math.ceil(((mX /3) *2)/2)+1 then
- if par2 > 1 then
- if par2 < (mX/3)*2+1 then
- if intSel == 1 then
- map[par3][par2] = "*"
- elseif intSel == 2 then
- map[par3][par2] = "A"
- elseif intSel == 3 then
- map[par3][par2] = "0"
- elseif intSel == 4 then
- map[par3][par2] = "C"
- end
- end
- end
- end
- end
- if par2 == mX then
- if par3 == 1 then
- term.setBackgroundColor(colors.black)
- shell.run("clear")
- error()
- end
- end
- end
- end
- while true do
- showMap()
- showInterface()
- updateInterface()
- saveAll()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement