Advertisement
incinirate

Gui

Aug 25th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.45 KB | None | 0 0
  1. map = {}
  2. mX,mY = term.getSize()
  3. function newMap(handle)
  4.   for i=1,mY do
  5.     map[i] = {}
  6.     for j=1,(mX / 3) * 2 do
  7.       map[i][j] = "*"
  8.       if j > math.ceil(((mX /3) * 2)/2)-1 then
  9.         if j < math.ceil(((mX /3) * 2)/2)+3 then
  10.           if i > math.ceil(mY/2)-2 then
  11.             if i < math.ceil(mY/2)+2 then
  12.               map[i][j] = "0"
  13.             end
  14.           end
  15.         end
  16.       end
  17.       if i == math.ceil(mY/2) then
  18.         if j == math.ceil(((mX /3) * 2)/2)+1 then
  19.           map[i][j] = "H"
  20.         end
  21.       end
  22.     end
  23.   end
  24.   for i=1,mY do
  25.     for j=1,(mX / 3) * 2 do
  26.       handle.writeLine(map[i][j])
  27.     end
  28.   end
  29.   handle.close()
  30. end
  31.  
  32. function readMap(tableData)
  33.   mapData = {}
  34.   i=1
  35.   while true do
  36.     tmp = tableData.readLine()
  37.     if tmp == nil then
  38.       break
  39.     else
  40.       mapData[i] = tmp
  41.     end
  42.     i = i + 1
  43.   end
  44.   k = 1
  45.   for i=1,mY do
  46.     for j=1,(mX / 3) * 2 do
  47.       if map[i] == nil then map[i] = {} end
  48.       if mapData[i] ~= nil then
  49.         map[i][j] = mapData[k]
  50.       end
  51.       k = k + 1
  52.     end
  53.   end
  54.   tableData.close()
  55. end
  56.  
  57. function saveAll()
  58.   handle = fs.open("mine.sav","w")
  59.   for i=1,mY do
  60.     for j=1,(mX / 3) * 2 do
  61.       handle.writeLine(map[i][j])
  62.     end
  63.   end
  64.   handle.close()
  65. end
  66.  
  67. if fs.exists("mine.sav") == false then
  68.   save = fs.open("mine.sav","w")
  69.   newMap(save)
  70. else
  71.   save = fs.open("mine.sav","r")
  72.   readMap(save)
  73. end
  74.  
  75. function showMap()
  76.   for i=1,mY do
  77.     for j=1,(mX / 3) * 2 do
  78.       term.setCursorPos(j,i)
  79.       if map[i][j] == "*" then
  80.         term.setBackgroundColor(colors.magenta)
  81.         write(" ")
  82.       elseif map[i][j] == "0" then
  83.         term.setBackgroundColor(colors.brown)
  84.         write(" ")
  85.       elseif map[i][j] == "H" then
  86.         term.setBackgroundColor(colors.red)
  87.         term.setTextColor(colors.black)
  88.         write("H")
  89.       elseif map[i][j] == "A" then
  90.         term.setBackgroundColor(colors.orange)
  91.         write(" ")
  92.       elseif map[i][j] == "C" then
  93.         term.setBackgroundColor(colors.cyan)
  94.         write(" ")
  95.       end
  96.     end
  97.   end
  98. end
  99.  
  100. intSel = 1
  101. strings = {}
  102. table.insert(strings,"Regular")
  103. table.insert(strings,"Avaliable")
  104. table.insert(strings,"Off Limits")
  105. table.insert(strings,"Completed")
  106.  
  107. function showInterface()
  108.   for i=(mX/3)*2+2,mX do
  109.     for j=1,mY do
  110.       term.setCursorPos(i,j)
  111.       term.setBackgroundColor(colors.yellow)
  112.       write(" ")
  113.     end
  114.   end
  115.   for i=1,mY do
  116.     term.setCursorPos((mX/3)*2+1,i)
  117.     term.setBackgroundColor(colors.gray)
  118.     write(" ")
  119.   end
  120.   for i=1,4 do
  121.     term.setTextColor(colors.white)
  122.     if i==1 then
  123.       term.setBackgroundColor(colors.magenta)
  124.     elseif i==2 then
  125.       term.setBackgroundColor(colors.orange)
  126.     elseif i==3 then
  127.       term.setBackgroundColor(colors.brown)
  128.     elseif i==4 then
  129.       term.setBackgroundColor(colors.cyan)
  130.     end
  131.     term.setCursorPos((mX/3)*2+4,5+i)
  132.     write("             ")
  133.     term.setCursorPos((mX/3)*2+5,5+i)
  134.     write(strings[i])
  135.   end
  136.   term.setCursorPos(mX,1)
  137.   term.setBackgroundColor(colors.red)
  138.   write("X")
  139. end
  140.  
  141. function updateInterface()
  142.   term.setCursorPos((mX/3)*2+3,5+intSel)
  143.   term.setBackgroundColor(colors.yellow)
  144.   term.setTextColor(colors.black)
  145.   write("*")
  146.   e,par1,par2,par3 = os.pullEvent()
  147.   if e == "mouse_click" or e == "mouse_drag" then
  148.   if par1 == 1 then
  149.     if par2 > ((mX/3)*2+4) and par2 < ((mX/3)*2+17) then
  150.       if par3 == 6 then
  151.         --Regular
  152.         intSel = 1
  153.       elseif par3 == 7 then
  154.         --Avaliable
  155.         intSel = 2
  156.       elseif par3 == 8 then
  157.         --Off Limits
  158.         intSel = 3
  159.       elseif par3 == 9 then
  160.         --Complete
  161.         intSel = 4
  162.       end
  163.     end
  164.     if par3 ~= math.ceil(mY/2) or par2 ~= math.ceil(((mX /3) *2)/2)+1 then
  165.           if par2 > 1 then
  166.             if par2 < (mX/3)*2+1 then
  167.               if intSel == 1 then
  168.                 map[par3][par2] = "*"
  169.               elseif intSel == 2 then
  170.                 map[par3][par2] = "A"
  171.               elseif intSel == 3 then
  172.                 map[par3][par2] = "0"
  173.               elseif intSel == 4 then
  174.                 map[par3][par2] = "C"
  175.               end
  176.             end
  177.           end
  178.         end
  179.   end
  180.   if par2 == mX then
  181.     if par3 == 1 then
  182.       term.setBackgroundColor(colors.black)
  183.       shell.run("clear")
  184.       error()
  185.     end
  186.   end
  187.   end
  188. end
  189.  
  190. while true do
  191.   showMap()
  192.   showInterface()
  193.   updateInterface()
  194.   saveAll()
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement