Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Menu Tycoon 1 --
- -- JDG Brian --
- -- 2/20/2020 5:30 --
- dir = fs.getDir(shell.getRunningProgram())
- version = "1.0."..string.sub(tostring(fs.getSize(shell.getRunningProgram()))-1,-6)
- w,h = term.getSize()
- -- temp
- if not term.isColor() then return print("Requires Advanced Computer (soon any computer).") end
- local cols
- if term.isColor() then
- cols = {"white", "orange", "magenta", "lightBlue", "yellow", "lime", "pink", "gray", "lightGray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
- else
- cols = {"white", "gray", "lightGray", "black"}
- end
- -- Mini-Engine --
- clr = function() term.clear() end
- cp = function(x,y) term.setCursorPos(x,y) end
- slowtext = function(speed, text)
- for i=1, string.len(text) do
- write(string.sub(text, i,i))
- sleep(speed)
- end
- end
- local p = function(text) print(text) end
- local print = function(text, speed)
- if speed ~= nil and speed ~= 0 then
- local alt = true
- for i=1, string.len(text) do
- write(string.sub(text,i,i))
- if alt then
- sleep(speed)
- end
- alt = not alt
- end
- p("")
- else
- p(text)
- end
- end
- -- Mini-Engine --
- -- Vars --
- function save()
- local file = fs.open(dir.."/saves/sv.lua", "w")
- file.write(textutils.serialize(data))
- file.close()
- end
- function load()
- if fs.exists(dir.."/saves/sv.lua") then
- local file = fs.open(dir.."/saves/sv.lua", "r")
- data = textutils.unserialize(file.readAll())
- file.close()
- end
- end
- function exists(thing)
- if thing ~= nil then
- return true
- end
- return false
- end
- load()
- if not exists(data) then data = {} end
- if not exists(data.player) then data.player = {} end
- if not exists(data.player.cash) then data.player.cash = 0 end
- if not exists(data.player.generate) then data.player.generate = 1 end
- if not exists(data.settings) then data.settings = {} end
- if not exists(data.settings.selectedtextcolor) then data.settings.selectedtextcolor = colors.white end
- if not exists(data.settings.textcolor) then data.settings.textcolor = colors.gray end
- if not exists(data.settings.backgroundcolor) then data.settings.backgroundcolor = colors.black end
- if not exists(data.genStats) then data.genStats = {} end
- if not exists(data.genStats.scale) then data.genStats.scale = 1 end -- use this to scale money generation
- if not exists(data.genStats.costScale) then data.genStats.costScale = 500 end
- if not exists(data.genStats.generators) then data.genStats.generators = {} end
- if not exists(data.genStats.generators.starter) then
- data.genStats.generators.starter = {}
- for i=1, 10 do
- data.genStats.generators.starter[i] = {}
- data.genStats.generators.starter[i].name = "Weak Generator "..i
- data.genStats.generators.starter[i].status = false -- create 10 disabled generators
- data.genStats.generators.starter[i].value = i*data.genStats.scale -- scales each generator's earn rate
- data.genStats.generators.starter[i].cost = i*data.genStats.costScale -- scales each generator's cost
- end
- end
- if not exists(data.genStats.generators.inheritor) then
- data.genStats.generators.inheritor = {}
- for i=1, 10 do
- data.genStats.generators.inheritor[i] = {}
- data.genStats.generators.inheritor[i].name = "Rusty Generator "..i
- data.genStats.generators.inheritor[i].status = false -- create 10 disabled generators
- data.genStats.generators.inheritor[i].value = i*data.genStats.scale -- scales each generator's earn rate
- data.genStats.generators.inheritor[i].cost = i*data.genStats.costScale*4 -- scales each generator's cost
- end
- end
- if not exists(data.genStats.generators.noteworthy) then
- data.genStats.generators.noteworthy = {}
- for i=1, 10 do
- data.genStats.generators.noteworthy[i] = {}
- data.genStats.generators.noteworthy[i].name = "Dusty Generator "..i
- data.genStats.generators.noteworthy[i].status = false -- create 10 disabled generators
- data.genStats.generators.noteworthy[i].value = i*data.genStats.scale -- scales each generator's earn rate
- data.genStats.generators.noteworthy[i].cost = i*data.genStats.costScale*8 -- scales each generator's cost
- end
- end
- menu = {}
- function reloadMenu()
- menu = {}
- menu.main = {"Generate Cash", "Generators", "Settings", "Save and Exit"}
- menu.settings = {"Selected Text Color", "Text Color", "Background Color", "Reset Game", "Back"}
- menu.generatorlist = {"Starter", "Inheritor", "Noteworthy", "Back"}
- menu.generators = {}
- menu.generators.starter = {}
- for i=1, #data.genStats.generators.starter do
- menu.generators.starter[i] = data.genStats.generators.starter[i].name
- if data.genStats.generators.starter[i].status then
- menu.generators.starter[i] = menu.generators.starter[i].." Owned"
- else
- menu.generators.starter[i] = menu.generators.starter[i].." $ "..data.genStats.generators.starter[i].cost.." ("..data.genStats.generators.starter[i].value..")"
- end
- end
- menu.generators.starter[#menu.generators.starter+1] = "Back"
- menu.generators.inheritor = {}
- for i=1, #data.genStats.generators.inheritor do
- menu.generators.inheritor[i] = data.genStats.generators.inheritor[i].name
- if data.genStats.generators.inheritor[i].status then
- menu.generators.inheritor[i] = menu.generators.inheritor[i].." Owned"
- else
- menu.generators.inheritor[i] = menu.generators.inheritor[i].." $ "..data.genStats.generators.inheritor[i].cost.." ("..data.genStats.generators.inheritor[i].value..")"
- end
- end
- menu.generators.inheritor[#menu.generators.inheritor+1] = "Back"
- menu.generators.noteworthy = {}
- for i=1, #data.genStats.generators.noteworthy do
- menu.generators.noteworthy[i] = data.genStats.generators.noteworthy[i].name
- if data.genStats.generators.noteworthy[i].status then
- menu.generators.noteworthy[i] = menu.generators.noteworthy[i].." Owned"
- else
- menu.generators.noteworthy[i] = menu.generators.noteworthy[i].." $ "..data.genStats.generators.noteworthy[i].cost.." ("..data.genStats.generators.noteworthy[i].value..")"
- end
- end
- menu.generators.noteworthy[#menu.generators.noteworthy+1] = "Back"
- end
- reloadMenu()
- local currentmenu, prevmenu, selected, updat, running = menu.main, {}, 1, true, true
- -- Vars --
- -- Functions --
- function splash()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lime)
- clr() cp(1,1)
- slowtext(.02, "Menu Tycoon by JDG Brian")
- sleep(.5) cp(1,2) term.setTextColor(colors.gray)
- slowtext(.01, "Version "..version) sleep(1) clr()
- end
- function colorselect()
- local run, update, select = true, true, 1
- term.setBackgroundColor(data.settings.backgroundcolor)
- while run do
- if update then
- update = false clr() cp(1,1)
- term.setTextColor(data.settings.selectedtextcolor)
- for i=1, string.len(cols[select])/2 do write(" ") end
- print(string.char(30))
- term.setTextColor(colors[cols[select]])
- print(cols[select])
- term.setTextColor(data.settings.selectedtextcolor)
- for i=1, string.len(cols[select])/2 do write(" ") end
- print(string.char(31))
- print("Press 'q' to exit")
- end
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if select == 1 then select = #cols else select = select - 1 end update = true
- elseif i == keys.s or i == keys.down then
- if select == #cols then select = 1 else select = select + 1 end update = true
- elseif i == keys.e or i == keys.enter then
- clr() return colors[cols[select]]
- elseif i == keys.q then
- clr() run = false
- end
- end
- return false
- end
- function runMenuCommand(command)
- command = string.lower(string.gsub(command, " ", "")) -- removes all spaces and lowers everything
- local list = {
- generatecash = function() -- main generation
- data.player.cash = data.player.cash + data.player.generate sleep(.1)
- end,
- saveandexit = function() -- save and exit program
- save()
- running = false
- end,
- settings = function()
- prevmenu[#prevmenu+1] = currentmenu
- currentmenu = menu.settings
- selected = 1
- end,
- resetgame = function()
- term.setBackgroundColor(colors.black) term.setTextColor(colors.red)
- clr() cp(1,1) write("type 'confirm' to erase data: ")
- term.setTextColor(colors.white)
- sleep(.2)
- if string.lower(read()) == "confirm" then
- if fs.exists(dir.."/saves/") then
- fs.delete(dir.."/saves/")
- end
- print("All save data deleted!") sleep(1) running = false
- end
- end,
- generators = function() -- main list of generators
- prevmenu[#prevmenu+1] = currentmenu
- currentmenu = menu.generatorlist
- selected = 1
- end,
- starter = function() -- starter list of generators
- prevmenu[#prevmenu+1] = currentmenu
- currentmenu = menu.generators.starter
- selected = 1
- end,
- inheritor = function()
- prevmenu[#prevmenu+1] = currentmenu
- currentmenu = menu.generators.inheritor
- selected = 1
- end,
- noteworthy = function()
- prevmenu[#prevmenu+1] = currentmenu
- currentmenu = menu.generators.noteworthy
- selected = 1
- end,
- back = function() -- go back a menu
- if #prevmenu == 0 then
- running = false
- else
- currentmenu = prevmenu[#prevmenu]
- prevmenu[#prevmenu] = nil
- selected = 1
- end
- end,
- selectedtextcolor = function()
- local tmp = colorselect()
- if tmp ~= false then
- data.settings.selectedtextcolor = tmp clr()
- end
- end,
- textcolor = function()
- local tmp = colorselect()
- if tmp ~= false then
- data.settings.textcolor = tmp clr()
- end
- end,
- backgroundcolor = function()
- local tmp = colorselect()
- if tmp ~= false then
- data.settings.backgroundcolor = tmp
- term.setBackgroundColor(tmp)
- clr()
- end
- end,
- }
- if list[command] ~= nil then list[command]() end
- if data.settings.textcolor == data.settings.backgroundcolor and data.settings.selectedtextcolor == data.settings.backgroundcolor then
- data.settings.backgroundcolor = colors.black
- data.settings.selectedtextcolor = colors.white
- data.settings.textcolor = colors.gray
- end
- end
- function purchase(id)
- if currentmenu == menu.generators.starter then
- if data.player.cash >= data.genStats.generators.starter[id].cost and data.genStats.generators.starter[id].status == false then
- data.player.cash = data.player.cash - data.genStats.generators.starter[id].cost
- data.genStats.generators.starter[id].status = true
- data.player.generate = data.player.generate + data.genStats.generators.starter[id].value
- reloadMenu()
- currentmenu, prevmenu, selected = menu.main, {}, 1
- end
- elseif currentmenu == menu.generators.inheritor then
- if data.player.cash >= data.genStats.generators.inheritor[id].cost and data.genStats.generators.inheritor[id].status == false then
- data.player.cash = data.player.cash - data.genStats.generators.inheritor[id].cost
- data.genStats.generators.inheritor[id].status = true
- data.player.generate = data.player.generate + data.genStats.generators.inheritor[id].value
- reloadMenu()
- currentmenu, prevmenu, selected = menu.main, {}, 1
- end
- elseif currentmenu == menu.generators.noteworthy then
- if data.player.cash >= data.genStats.generators.noteworthy[id].cost and data.genStats.generators.noteworthy[id].status == false then
- data.player.cash = data.player.cash - data.genStats.generators.noteworthy[id].cost
- data.genStats.generators.noteworthy[id].status = true
- data.player.generate = data.player.generate + data.genStats.generators.noteworthy[id].value
- reloadMenu()
- currentmenu, prevmenu, selected = menu.main, {}, 1
- end
- end
- end
- -- Functions --
- -- Main --
- function t_reserve()
- while true do
- sleep(1)
- end
- end
- function t_menus()
- local nprev = #prevmenu
- while running do
- if updat then
- updat = false
- local spd
- if #prevmenu ~= nprev then spd = .00001 clr() else spd = 0 end nprev = #prevmenu
- term.setBackgroundColor(data.settings.backgroundcolor)
- cp(1,h) term.setTextColor(colors.white) write("$ ") term.setTextColor(colors.lime)
- if string.len(data.player.cash) >= 10 then
- write("Infinity and Beyond")
- elseif string.len(data.player.cash) >= 9 then
- write(string.sub(data.player.cash, 1,1).."T ($"..data.player.cash..")")
- elseif string.len(data.player.cash) >= 8 then
- write(string.sub(data.player.cash, 1,1).."B ($"..data.player.cash..")")
- elseif string.len(data.player.cash) >= 7 then
- write(string.sub(data.player.cash, 1,1).."M ($"..data.player.cash..")")
- elseif string.len(data.player.cash) >= 6 then
- write(string.sub(data.player.cash, 1,3).."K ($"..data.player.cash..")")
- else
- write(data.player.cash)
- end
- cp(1,h-1) term.setTextColor(colors.white) write("^ ") term.setTextColor(colors.yellow) write(data.player.generate)
- cp(1,1) term.setTextColor(colors.cyan) write("Menu Tycoon I")
- cp(w-string.len("v."..version),1) term.setTextColor(colors.gray) write("v."..version)
- cp(1,3)
- for i=1, #currentmenu do
- if selected == i then
- term.setTextColor(data.settings.selectedtextcolor)
- print("> "..currentmenu[i], spd)
- else
- term.setTextColor(data.settings.textcolor)
- print(currentmenu[i].." ", spd)
- end
- end
- term.setTextColor(colors.white)
- end
- a,i = os.pullEvent("key")
- if i == keys.up or i == keys.w then
- if selected == 1 then selected = #currentmenu else selected = selected - 1 end updat = true
- elseif i == keys.down or i == keys.s then
- if selected == #currentmenu then selected = 1 else selected = selected + 1 end updat = true
- elseif i == keys.e or i == keys.enter then
- if selected == #currentmenu then
- runMenuCommand(currentmenu[selected]) updat = true
- elseif prevmenu[#prevmenu] == menu.generatorlist then
- purchase(selected) updat = true
- else
- runMenuCommand(currentmenu[selected]) updat = true
- end
- elseif i == keys.q then
- runMenuCommand("Back") updat = true
- end
- end
- end
- splash() res, er = pcall(function() parallel.waitForAny(t_reserve, t_menus) end)
- if not res then
- sleep(1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- clr() cp(1,1)
- print("Game has Crashed. :(")
- print("")
- print("Game Version: "..version)
- print("Crash Report: "..er)
- print("")
- sleep(2)
- print("Press any key to continue...") os.pullEvent("char")
- end
- term.setTextColor(colors.white) term.setBackgroundColor(colors.black) clr() cp(1,1) print("MT1 by JDG Brian") sleep(.1)
- -- Main --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement