JustDoesGames

Menu Tycoon I Beta Version

Feb 24th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.37 KB | None | 0 0
  1. -- Menu Tycoon 1 --
  2. -- JDG Brian --
  3. -- 2/20/2020 5:30 --
  4.  
  5. dir = fs.getDir(shell.getRunningProgram())
  6. version = "1.0."..string.sub(tostring(fs.getSize(shell.getRunningProgram()))-1,-6)
  7. w,h = term.getSize()
  8. -- temp
  9. if not term.isColor() then return print("Requires Advanced Computer (soon any computer).") end
  10. local cols
  11. if term.isColor() then
  12.     cols = {"white", "orange", "magenta", "lightBlue", "yellow", "lime", "pink", "gray", "lightGray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
  13. else
  14.     cols = {"white", "gray", "lightGray", "black"}
  15. end
  16.  
  17. -- Mini-Engine --
  18.  
  19. clr = function() term.clear() end
  20. cp = function(x,y) term.setCursorPos(x,y) end
  21. slowtext = function(speed, text)
  22.     for i=1, string.len(text) do
  23.         write(string.sub(text, i,i))
  24.         sleep(speed)
  25.     end
  26. end
  27. local p = function(text) print(text) end
  28.  
  29. local print = function(text, speed)
  30.     if speed ~= nil and speed ~= 0 then
  31.         local alt = true
  32.         for i=1, string.len(text) do
  33.             write(string.sub(text,i,i))
  34.             if alt then
  35.             sleep(speed)
  36.             end
  37.             alt = not alt
  38.         end
  39.         p("")
  40.     else
  41.         p(text)
  42.     end
  43. end
  44.  
  45.  
  46. -- Mini-Engine --
  47.  
  48.  
  49.  
  50. -- Vars --
  51.  
  52. function save()
  53.     local file = fs.open(dir.."/saves/sv.lua", "w")
  54.     file.write(textutils.serialize(data))
  55.     file.close()
  56. end
  57.  
  58. function load()
  59.     if fs.exists(dir.."/saves/sv.lua") then
  60.         local file = fs.open(dir.."/saves/sv.lua", "r")
  61.         data = textutils.unserialize(file.readAll())
  62.         file.close()
  63.     end
  64. end
  65.  
  66. function exists(thing)
  67.     if thing ~= nil then
  68.         return true
  69.     end
  70.     return false
  71. end
  72.  
  73. load()
  74.  
  75. if not exists(data) then data = {} end
  76.  
  77. if not exists(data.player) then data.player = {} end
  78. if not exists(data.player.cash) then data.player.cash = 0 end
  79. if not exists(data.player.generate) then data.player.generate = 1 end
  80.  
  81. if not exists(data.settings) then data.settings = {} end
  82. if not exists(data.settings.selectedtextcolor) then data.settings.selectedtextcolor = colors.white end
  83. if not exists(data.settings.textcolor) then data.settings.textcolor = colors.gray end
  84. if not exists(data.settings.backgroundcolor) then data.settings.backgroundcolor = colors.black end
  85. if not exists(data.settings.animatetext) then data.settings.animatetext = true end
  86.  
  87. if not exists(data.genStats) then data.genStats = {} end
  88. if not exists(data.genStats.scale) then data.genStats.scale = 1 end -- use this to scale money generation
  89. if not exists(data.genStats.costScale) then data.genStats.costScale = 500 end
  90. if not exists(data.genStats.generators) then data.genStats.generators = {} end
  91.  
  92. if not exists(data.genStats.generators.starter) then
  93.     data.genStats.generators.starter = {}
  94.     for i=1, 10 do
  95.         data.genStats.generators.starter[i] = {}
  96.         data.genStats.generators.starter[i].name = "Weak Generator "..i
  97.         data.genStats.generators.starter[i].status = false -- create 10 disabled generators
  98.         data.genStats.generators.starter[i].value = i*data.genStats.scale -- scales each generator's earn rate
  99.         data.genStats.generators.starter[i].cost = i*data.genStats.costScale -- scales each generator's cost
  100.     end
  101. end
  102.  
  103. if not exists(data.genStats.generators.inheritor) then
  104.     data.genStats.generators.inheritor = {}
  105.     for i=1, 10 do
  106.         data.genStats.generators.inheritor[i] = {}
  107.         data.genStats.generators.inheritor[i].name = "Rusty Generator "..i
  108.         data.genStats.generators.inheritor[i].status = false -- create 10 disabled generators
  109.         data.genStats.generators.inheritor[i].value = i*data.genStats.scale -- scales each generator's earn rate
  110.         data.genStats.generators.inheritor[i].cost = i*data.genStats.costScale*3 -- scales each generator's cost
  111.     end
  112. end
  113.  
  114. if not exists(data.genStats.generators.noteworthy) then
  115.     data.genStats.generators.noteworthy = {}
  116.     for i=1, 10 do
  117.         data.genStats.generators.noteworthy[i] = {}
  118.         data.genStats.generators.noteworthy[i].name = "Dusty Generator "..i
  119.         data.genStats.generators.noteworthy[i].status = false -- create 10 disabled generators
  120.         data.genStats.generators.noteworthy[i].value = i*data.genStats.scale -- scales each generator's earn rate
  121.         data.genStats.generators.noteworthy[i].cost = i*data.genStats.costScale*6 -- scales each generator's cost
  122.     end
  123. end
  124.  
  125. menu = {}
  126. debug = false
  127. menu.debug = {}
  128. for i=1, 25 do
  129.     menu.debug[i] = "Debug "..i
  130. end
  131.  
  132. function reloadMenu()
  133.     menu = {}
  134.     menu.main = {"Generate Cash", "Generators", "Settings", "Save and Exit"}
  135.     menu.settings = {"Selected Text Color", "Text Color", "Background Color", "Animate Text", "Reset Game", "Back"}
  136.     if debug then menu.settings[#menu.settings+1] = "III Debug III" end
  137.    
  138.     menu.generatorlist = {"Starter", "Inheritor", "Noteworthy", "Back"}
  139.     menu.generators = {}
  140.  
  141.     menu.generators.starter = {}
  142.     for i=1, #data.genStats.generators.starter do
  143.         menu.generators.starter[i] = data.genStats.generators.starter[i].name
  144.         if data.genStats.generators.starter[i].status then
  145.             menu.generators.starter[i] = menu.generators.starter[i].." Owned"
  146.         else
  147.             menu.generators.starter[i] = menu.generators.starter[i].." $ "..data.genStats.generators.starter[i].cost.." ("..data.genStats.generators.starter[i].value..")"
  148.         end
  149.     end
  150.     menu.generators.starter[#menu.generators.starter+1] = "Back"
  151.    
  152.     menu.generators.inheritor = {}
  153.     for i=1, #data.genStats.generators.inheritor do
  154.         menu.generators.inheritor[i] = data.genStats.generators.inheritor[i].name
  155.         if data.genStats.generators.inheritor[i].status then
  156.             menu.generators.inheritor[i] = menu.generators.inheritor[i].." Owned"
  157.         else
  158.             menu.generators.inheritor[i] = menu.generators.inheritor[i].." $ "..data.genStats.generators.inheritor[i].cost.." ("..data.genStats.generators.inheritor[i].value..")"
  159.         end
  160.     end
  161.     menu.generators.inheritor[#menu.generators.inheritor+1] = "Back"
  162.    
  163.     menu.generators.noteworthy = {}
  164.     for i=1, #data.genStats.generators.noteworthy do
  165.         menu.generators.noteworthy[i] = data.genStats.generators.noteworthy[i].name
  166.         if data.genStats.generators.noteworthy[i].status then
  167.             menu.generators.noteworthy[i] = menu.generators.noteworthy[i].." Owned"
  168.         else
  169.             menu.generators.noteworthy[i] = menu.generators.noteworthy[i].." $ "..data.genStats.generators.noteworthy[i].cost.." ("..data.genStats.generators.noteworthy[i].value..")"
  170.         end
  171.     end
  172.     menu.generators.noteworthy[#menu.generators.noteworthy+1] = "Back"
  173. end
  174.  
  175. reloadMenu()
  176.  
  177. local currentmenu, prevmenu, selected, updat, running = menu.main, {}, 1, true, true
  178.  
  179. -- Vars --
  180.  
  181.  
  182.  
  183. -- Functions --
  184.  
  185. function splash()
  186.     term.setBackgroundColor(colors.black)
  187.     term.setTextColor(colors.lime)
  188.     clr() cp(1,1)
  189.     slowtext(.02, "Menu Tycoon  by  JDG Brian")
  190.     sleep(.5) cp(1,2) term.setTextColor(colors.gray)
  191.     slowtext(.01, "Version "..version) sleep(1) clr()
  192. end
  193.  
  194. function colorselect()
  195.     local run, update, select = true, true, 1
  196.     term.setBackgroundColor(data.settings.backgroundcolor)
  197.     while run do
  198.         if update then
  199.             update = false clr() cp(1,1)
  200.             term.setTextColor(data.settings.selectedtextcolor)
  201.             for i=1, string.len(cols[select])/2 do write(" ") end
  202.             print(string.char(30))
  203.             term.setTextColor(colors[cols[select]])
  204.             print(cols[select])
  205.             term.setTextColor(data.settings.selectedtextcolor)
  206.             for i=1, string.len(cols[select])/2 do write(" ") end
  207.             print(string.char(31))
  208.             print("Press 'q' to exit")
  209.         end
  210.         a,i = os.pullEvent("key")
  211.         if i == keys.w or i == keys.up then
  212.             if select == 1 then select = #cols else select = select - 1 end update = true
  213.         elseif i == keys.s or i == keys.down then
  214.             if select == #cols then select = 1 else select = select + 1 end update = true
  215.         elseif i == keys.e or i == keys.enter then
  216.             clr() return colors[cols[select]]
  217.         elseif i == keys.q then
  218.             clr() run = false
  219.         end
  220.     end
  221.     return false
  222. end
  223.  
  224.  
  225. function runMenuCommand(command)
  226.     command = string.lower(string.gsub(command, " ", "")) -- removes all spaces and lowers everything
  227.     local list = {
  228.         iiidebugiii = function()
  229.             prevmenu[#prevmenu+1] = currentmenu
  230.             currentmenu = menu.debug
  231.             error(#currentmenu)
  232.             selected = 1
  233.         end,
  234.        
  235.         generatecash = function() -- main generation
  236.             data.player.cash = data.player.cash + data.player.generate sleep(.1)
  237.         end,
  238.        
  239.         saveandexit = function() -- save and exit program
  240.             save()
  241.             running = false
  242.         end,
  243.        
  244.         settings = function()
  245.             prevmenu[#prevmenu+1] = currentmenu
  246.             currentmenu = menu.settings
  247.             selected = 1
  248.         end,
  249.        
  250.         animatetext = function()
  251.             data.settings.animatetext = not data.settings.animatetext
  252.             term.setBackgroundColor(data.settings.backgroundcolor)
  253.             term.setTextColor(data.settings.selectedtextcolor)
  254.             clr() cp(1,1)
  255.             write("Animate Text: ")
  256.             if data.settings.animatetext then term.setTextColor(colors.lime) else term.setTextColor(colors.red) end
  257.             print(tostring(data.settings.animatetext)) sleep(1)
  258.             term.setBackgroundColor(data.settings.backgroundcolor)
  259.             clr()
  260.         end,
  261.        
  262.         resetgame = function()
  263.             term.setBackgroundColor(colors.black) term.setTextColor(colors.red)
  264.             clr() cp(1,1) write("type 'confirm' to erase data: ")
  265.             term.setTextColor(colors.white)
  266.             sleep(.2)
  267.             if string.lower(read()) == "confirm" then
  268.                 if fs.exists(dir.."/saves/") then
  269.                     fs.delete(dir.."/saves/")
  270.                 end
  271.                 print("All save data deleted!") sleep(1) running = false
  272.             else
  273.                 term.setBackgroundColor(data.settings.backgroundcolor)
  274.                 clr()
  275.             end
  276.         end,
  277.        
  278.         generators = function() -- main list of generators
  279.             prevmenu[#prevmenu+1] = currentmenu
  280.             currentmenu = menu.generatorlist
  281.             selected = 1
  282.         end,
  283.        
  284.         starter = function() -- starter list of generators
  285.             prevmenu[#prevmenu+1] = currentmenu
  286.             currentmenu = menu.generators.starter
  287.             selected = 1
  288.         end,
  289.        
  290.         inheritor = function()
  291.             prevmenu[#prevmenu+1] = currentmenu
  292.             currentmenu = menu.generators.inheritor
  293.             selected = 1
  294.         end,
  295.        
  296.         noteworthy = function()
  297.             prevmenu[#prevmenu+1] = currentmenu
  298.             currentmenu = menu.generators.noteworthy
  299.             selected = 1
  300.         end,
  301.        
  302.         back = function() -- go back a menu
  303.             if #prevmenu == 0 then
  304.                 running = false
  305.             else
  306.                 currentmenu = prevmenu[#prevmenu]
  307.                 prevmenu[#prevmenu] = nil
  308.                 selected = 1
  309.             end
  310.         end,
  311.        
  312.         selectedtextcolor = function()
  313.             local tmp = colorselect()
  314.             if tmp ~= false then
  315.                 data.settings.selectedtextcolor = tmp clr()
  316.             end
  317.         end,
  318.        
  319.         textcolor = function()
  320.             local tmp = colorselect()
  321.             if tmp ~= false then
  322.                 data.settings.textcolor = tmp clr()
  323.             end
  324.         end,
  325.        
  326.         backgroundcolor = function()
  327.             local tmp = colorselect()
  328.             if tmp ~= false then
  329.                 data.settings.backgroundcolor = tmp
  330.                 term.setBackgroundColor(tmp)
  331.                 clr()
  332.             end
  333.         end,
  334.     }
  335.     if list[command] ~= nil then list[command]() end
  336.     if data.settings.textcolor == data.settings.backgroundcolor and data.settings.selectedtextcolor == data.settings.backgroundcolor then
  337.         data.settings.backgroundcolor = colors.black
  338.         data.settings.selectedtextcolor = colors.white
  339.         data.settings.textcolor = colors.gray
  340.     end
  341. end
  342.  
  343. function purchase(id)
  344.     if currentmenu == menu.generators.starter then
  345.         if data.player.cash >= data.genStats.generators.starter[id].cost and data.genStats.generators.starter[id].status == false then
  346.             data.player.cash = data.player.cash - data.genStats.generators.starter[id].cost
  347.             data.genStats.generators.starter[id].status = true
  348.             data.player.generate = data.player.generate + data.genStats.generators.starter[id].value
  349.             reloadMenu()
  350.             currentmenu, prevmenu, selected = menu.main, {}, 1
  351.         end
  352.     elseif currentmenu == menu.generators.inheritor then
  353.         if data.player.cash >= data.genStats.generators.inheritor[id].cost and data.genStats.generators.inheritor[id].status == false then
  354.             data.player.cash = data.player.cash - data.genStats.generators.inheritor[id].cost
  355.             data.genStats.generators.inheritor[id].status = true
  356.             data.player.generate = data.player.generate + data.genStats.generators.inheritor[id].value
  357.             reloadMenu()
  358.             currentmenu, prevmenu, selected = menu.main, {}, 1
  359.         end
  360.     elseif currentmenu == menu.generators.noteworthy then
  361.         if data.player.cash >= data.genStats.generators.noteworthy[id].cost and data.genStats.generators.noteworthy[id].status == false then
  362.             data.player.cash = data.player.cash - data.genStats.generators.noteworthy[id].cost
  363.             data.genStats.generators.noteworthy[id].status = true
  364.             data.player.generate = data.player.generate + data.genStats.generators.noteworthy[id].value
  365.             reloadMenu()
  366.             currentmenu, prevmenu, selected = menu.main, {}, 1
  367.         end
  368.     end
  369. end
  370.  
  371. -- Functions --
  372.  
  373.  
  374.  
  375. -- Main --
  376.  
  377. function t_reserve()
  378.     while true do
  379.         sleep(1)
  380.     end
  381. end
  382.  
  383. function t_menus()
  384.     local nprev = #prevmenu
  385.     local displayedmenu, scroll = {}, 0
  386.     while running do
  387.         if updat then
  388.             updat = false
  389.            
  390.             local spd
  391.             if #prevmenu ~= nprev and data.settings.animatetext then
  392.                 spd = .00001
  393.                 scroll = 0
  394.                 displayedmenu = {}
  395.                 clr()
  396.             elseif #prevmenu ~= nprev and not data.settings.animatetext then
  397.                 spd = 0 clr()
  398.             else
  399.                 spd = 0
  400.             end nprev = #prevmenu
  401.            
  402.             term.setBackgroundColor(data.settings.backgroundcolor)
  403.             cp(1,h) term.setTextColor(colors.white) write("$ ") term.setTextColor(colors.lime)
  404.             if string.len(data.player.cash) >= 10 then
  405.                 write("Infinity and Beyond")
  406.             elseif string.len(data.player.cash) >= 9 then
  407.                 write(string.sub(data.player.cash, 1,1).."T ($"..data.player.cash..")")
  408.             elseif string.len(data.player.cash) >= 8 then
  409.                 write(string.sub(data.player.cash, 1,1).."B ($"..data.player.cash..")")
  410.             elseif string.len(data.player.cash) >= 7 then
  411.                 write(string.sub(data.player.cash, 1,1).."M ($"..data.player.cash..")")
  412.             elseif string.len(data.player.cash) >= 6 then
  413.                 write(string.sub(data.player.cash, 1,3).."K ($"..data.player.cash..")")
  414.             else
  415.                 write(data.player.cash)
  416.             end
  417.             cp(1,h-1) term.setTextColor(colors.white) write("^ ") term.setTextColor(colors.yellow) write(data.player.generate)
  418.             cp(1,1) term.setTextColor(colors.cyan) write("Menu Tycoon I")
  419.             cp(w-string.len("v."..version),1) term.setTextColor(colors.gray) write("v."..version)
  420.            
  421.             cp(1,3)
  422.             for i=1, #currentmenu do
  423.                 if selected == i then
  424.                     term.setTextColor(data.settings.selectedtextcolor)
  425.                     print("> "..currentmenu[i], spd)
  426.                 else
  427.                     term.setTextColor(data.settings.textcolor)
  428.                     print(currentmenu[i].."  ", spd)
  429.                 end
  430.             end
  431.             term.setTextColor(colors.white)
  432.         end
  433.        
  434.         a,i = os.pullEvent("key")
  435.         if i == keys.up or i == keys.w then
  436.             if selected == 1 then selected = #currentmenu else selected = selected - 1 end updat = true
  437.         elseif i == keys.down or i == keys.s then
  438.             if selected == #currentmenu then selected = 1 else selected = selected + 1 end updat = true
  439.         elseif i == keys.e or i == keys.enter then
  440.             if selected == #currentmenu then
  441.                 runMenuCommand(currentmenu[selected]) updat = true
  442.             elseif prevmenu[#prevmenu] == menu.generatorlist then
  443.                 purchase(selected) updat = true
  444.             else
  445.                 runMenuCommand(currentmenu[selected]) updat = true
  446.             end
  447.         elseif i == keys.q then
  448.             runMenuCommand("Back") updat = true
  449.         end
  450.     end
  451. end
  452.  
  453. splash() res, er = pcall(function() parallel.waitForAny(t_reserve, t_menus) end)
  454. if not res then
  455.     sleep(1)
  456.     term.setTextColor(colors.white)
  457.     term.setBackgroundColor(colors.black)
  458.     clr() cp(1,1)
  459.     print("Game has Crashed. :(")
  460.     print("")
  461.     print("Game Version: "..version)
  462.     print("Crash Report: "..er)
  463.     print("")
  464.     sleep(2)
  465.     print("Press any key to continue...") os.pullEvent("char")
  466. end
  467. term.setTextColor(colors.white) term.setBackgroundColor(colors.black) clr() cp(1,1) print("MT1 by JDG Brian") sleep(.1)
  468.  
  469. -- Main --
Advertisement
Add Comment
Please, Sign In to add comment