Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("back")
- -- Username
- local ufile = fs.open("disk/user.lua","r")
- local username = ufile.readLine()
- ufile.close()
- -- Money Read
- local mrfile = fs.open("disk/money.lua","r")
- local money = mrfile.readLine()
- mrfile.close()
- -- Coffe Read
- local cffile = fs.open("disk/coffe.lua","r")
- local cff = cffile.readLine()
- cffile.close()
- --[[ Local Variables ]]--
- local selectedItem = 1
- local inMainMenu = true
- local insubMenu = false
- -- Menu Methods --
- -- Deposit Start
- local function insufficientFunds(current, required)
- if current < required then
- print("You don't have enough money")
- sleep(2)
- disk.eject("right")
- os.reboot() -- the reboot will negate the need to return a value.
- -- I still recommend removing the reboots for this program.
- end
- return false -- you have sufficient funds
- end
- if money > 5 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- end
- function line()
- term.clear()
- term.setCursorPos(1,1)
- term.write(string.rep("-", 51)) -- Repeat string x amount of times
- term.setCursorPos(1,19)
- term.write(string.rep("-", 51))
- end
- function sugar()
- if tonumber(money) < 5 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- else
- m = money - 5
- local wfile = fs.open("disk/money.lua","w")
- wfile.write(m)
- wfile.close()
- c = cff - 1
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- rednet.broadcast("sugar","cof1")
- os.reboot()
- end
- end
- function blaze()
- if tonumber(money) < 10 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- else
- m = money - 10
- local wfile = fs.open("disk/money.lua","w")
- wfile.write(m)
- wfile.close()
- c = cff - 1
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- rednet.broadcast("blaze","cof1")
- os.reboot()
- end
- end
- function cream()
- if tonumber(money) < 10 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- else
- m = money - 10
- local wfile = fs.open("disk/money.lua","w")
- wfile.write(m)
- wfile.close()
- c = cff - 1
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- rednet.broadcast("cream","cof1")
- os.reboot()
- end
- end
- function golden()
- if tonumber(money) < 25 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- else
- m = money - 25
- local wfile = fs.open("disk/money.lua","w")
- wfile.write(m)
- wfile.close()
- c = cff - 1
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- rednet.broadcast("golden","cof1")
- os.reboot()
- end
- end
- function tear()
- if tonumber(money) < 30 then
- print("You don't have enougth money")
- make()
- sleep(2)
- disk.eject("right")
- os.reboot()
- else
- m = money - 30
- local wfile = fs.open("disk/money.lua","w")
- wfile.write(m)
- wfile.close()
- c = cff - 1
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- rednet.broadcast("tear","cof1")
- os.reboot()
- end
- end
- function Exit()
- inMainMenu = false
- disk.eject("right")
- os.reboot()
- end
- function make()
- rednet.broadcast("make","cof1")
- if redstone.getInput("bottom") == true then
- c = 6
- local cffile = fs.open("disk/coffe.lua","w")
- cffile.write(c)
- cffile.close()
- disk.eject("right")
- os.reboot()
- else
- term.clear()
- term.setCursorPos(1,1)
- term.write("---------------------------------------------------")
- term.setCursorPos(1,19)
- term.write("---------------------------------------------------")
- term.setCursorPos(15,9)
- print("Brewing Coffe")
- term.setCursorPos(15,10)
- sleep(3)
- make()
- end
- end
- if tonumber(cff) == 0 then
- make()
- end
- -- Menu Definitions--
- mainMenu = {
- [1] = {text = "Extra Sugar = 5$ (You can only use in the max 1)", handler = sugar},
- [2] = {text = "Strong = 10$ (You can only use in the max 1)", handler = blaze},
- [3] = {text = "Cream = 10$ (You can only use in the max 1)", handler = cream},
- [4] = {text = "Premium = 25$ (You can only use in the max 1)", handler = golden},
- [5] = {text = "Healthy = 30$ (You can only use in the max 1)", handler = tear},
- [6] = {text = "Make Coffe", handler = make},
- [7] = {text = "Cancel", handler = Exit},
- }
- -- Printing Methods --
- function printMenu( menu )
- for i=1,#menu do
- if i == selectedItem then
- print(">> "..menu[i].text)
- else
- print(" "..menu[i].text)
- end
- end
- end
- -- Handler Method --
- function onKeyPressed( key, menu)
- if key == keys.enter then
- onItemSelected(menu)
- elseif key == keys.up then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == keys.down then
- if selectedItem < #menu then
- selectedItem = selectedItem + 1
- end
- end
- end
- function onItemSelected(menu)
- menu[selectedItem].handler()
- end
- while inMainMenu do
- line()
- term.setCursorPos(1,2)
- print("Username: "..username)
- print("Current Money: "..money.. " Euros")
- print("Number of ingredients remaining: "..cff)
- term.setCursorPos(1,6)
- printMenu(mainMenu)
- event, key = os.pullEvent("key")
- onKeyPressed(key, mainMenu)
- end
Advertisement
Add Comment
Please, Sign In to add comment