Advertisement
JustDoesGames

Terrace MG

Feb 11th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. --+= TERRACE MG =+--
  2.  
  3. --+= Just Does Games =+--
  4.  
  5.  
  6. --+= Setup =+--
  7. local x,y = term.getSize()
  8. --if x ~= 51 or y ~= 19 or term.isColor() ~= true then print("51x19 Advanced Only") return end
  9. --+= Setup =+--
  10.  
  11. --+= Variables & Menus =+--
  12. function data(option)
  13.     if option == "save" then
  14.         local file = fs.open("sv.lua","w")
  15.         file.writeLine(balance)
  16.         file.writeLine(gen)
  17.         file.writeLine(cost)
  18.         file.close()
  19.     elseif option == "load" then
  20.         if fs.exists("sv.lua") == true then
  21.             local file = fs.open("sv.lua", "r")
  22.             balance = tonumber(file.readLine())
  23.             gen = tonumber(file.readLine())
  24.             cost = tonumber(file.readLine())
  25.             file.close()
  26.         else
  27.             balance = 0
  28.             gen = 1
  29.             cost = 2
  30.         end
  31.     end
  32. end
  33. data("load")
  34. running = true
  35. sel_0 = 1
  36. sel_1 = 1
  37.  
  38. m_0 = {"Game", "Shop","Options"}
  39. m_1 = {"Generate $","-"}
  40. m_2 = {"Increase Value","-"}
  41. m_2_cost = {cost,0,0}
  42. m_3 = {"Save & Exit Game","Erase Data","-"}
  43. int_m_sel = {m_1,m_2,m_3}
  44. int_m = int_m_sel[1]
  45. --+= Variables & Menus =+--
  46.  
  47.  
  48. --+= Functions =+--
  49. function setBack(col) term.setBackgroundColor(colors[col]) end
  50. function setText(col) term.setBackgroundColor(colors[col]) end
  51. function clr(a) if a == true or a == 1 then shell.run("clear") else term.clear() end end
  52.  
  53. function main()
  54.     while running do
  55.         if ref ~= false then clr(true) else ref = true term.setCursorPos(1,1) end
  56.         if balance > 1000000 then
  57.             print("Balance: $999999")
  58.         else
  59.             print("Balance: $"..balance)
  60.         end
  61.         if gen > 1000000 then
  62.             print("$ Value: $999999")
  63.         else
  64.             print("$ Value: $"..gen)
  65.         end
  66.         term.setCursorPos(1,y)
  67.         for i=1, #m_0 do
  68.             if sel_0 == i then
  69.                 write("["..m_0[i].."]")
  70.             else
  71.                 write(" "..m_0[i].." ")
  72.             end
  73.         end
  74.         for i=1, #int_m do
  75.             term.setCursorPos(2,3+i)
  76.  
  77.             if int_m == m_2 then
  78.                 if sel_1 == i and int_m[i] ~= "-" then
  79.                     print("[ "..int_m[i].." ] $"..m_2_cost[i])
  80.                 elseif sel_1 == i and int_m[i] == "-" then
  81.                     print("[ "..int_m[i].." ]")
  82.                 else
  83.                     print(int_m[i])
  84.                 end
  85.             else
  86.                 if sel_1 == i then
  87.                     print("[ "..int_m[i].." ]")
  88.                 else
  89.                     print(int_m[i])
  90.                 end
  91.             end
  92.         end
  93.         a,i = os.pullEvent("key")
  94.         if i == keys.w or i == keys.up then
  95.             if sel_1 ~= 1 then
  96.                 sel_1 = sel_1 - 1
  97.             else
  98.                 ref = false
  99.             end
  100.         elseif i == keys.s or i == keys.down then
  101.             if sel_1 ~= #int_m then
  102.                 sel_1 = sel_1 + 1
  103.             else
  104.                 ref = false
  105.             end
  106.         elseif i == keys.a or i == keys.left then
  107.             if sel_0 ~= 1 then
  108.                 sel_0 = sel_0 - 1
  109.                 sel_1 = 1
  110.                 int_m = int_m_sel[sel_0]
  111.             end
  112.         elseif i == keys.d or i == keys.right then
  113.             if sel_0 ~= #m_0 then
  114.                 sel_0 = sel_0 + 1
  115.                 sel_1 = 1
  116.                 int_m = int_m_sel[sel_0]
  117.             end
  118.         elseif i == keys.e or i == keys.enter or i == keys.space then
  119.             check()
  120.         else
  121.             ref = false
  122.         end
  123.     end
  124. end
  125.  
  126. function check()
  127.     if sel_0 == 1 then
  128.         if sel_1 == 1 then
  129.             balance = balance + gen
  130.             ref = false
  131.         end
  132.     elseif sel_0 == 2 then
  133.         if sel_1 == 1 then
  134.             if balance >= cost then
  135.                 balance = balance - cost
  136.                 gen = gen + 1
  137.                 cost = cost * 2
  138.                 m_2_cost[1] = cost
  139.             else
  140.                 ref = false
  141.             end
  142.         elseif sel_1 == 2 then
  143.  
  144.         elseif sel_1 == 3 then
  145.  
  146.         end
  147.     elseif sel_0 == 3 then
  148.         if sel_1 == 1 then
  149.             clr(true)
  150.             data("save")
  151.             running = false
  152.         elseif sel_1 == 2 then
  153.             clr(true)
  154.             balance = 0
  155.             gen = 1
  156.             cost = 2
  157.             data("save")
  158.             running = false
  159.         end
  160.     else
  161.         running = false
  162.     end
  163. end
  164. --+= Functions =+--
  165.  
  166. main()
  167. print("=)")
  168. sleep(.1)
  169. clr(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement