Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- function printCentred( y, s )
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write( s )
- end
- local nOption = 1
- -- Display menu
- local function drawMenu()
- term.clear()
- term.setCursorPos(1,1)
- term.write( "Wok's Nuclear Reactor Control" )
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write( "1" )
- elseif nOption == 2 then
- term.write( "2" )
- else
- term.write( "3" )
- end
- sleep(0)
- end
- -- Display the frontend
- term.clear()
- local function drawFrontend()
- printCentred( math.floor(h/2) - 3, "" )
- printCentred( math.floor(h/2) - 2, "SELECT AN OPTION" )
- printCentred( math.floor(h/2) - 1, "" )
- printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Bring Reactors Online ]") or "Bring Reactors Online" )
- printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Take Reactors Offline ]") or "Take Reactors Offline" )
- printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Logout ]") or "Logout" )
- printCentred( math.floor(h/2) + 3, "" )
- end
- -- Call functions for display menu
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == 17 or key == 200 then
- -- Up
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 31 or key == 208 then
- -- Down
- if nOption < 3 then -- Change 3 by the number of option.
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 28 then
- -- Enter
- break
- end
- end
- end
- term.clear()
- -- Conditions
- if nOption == 1 then
- term.setCursorPos(1,1)
- print("Engaging reactors...")
- sleep(3)
- shell.run("r-on")
- print("Reactors Online.")
- shell.run("menu")
- elseif nOption == 2 then
- term.setCursorPos(1,1)
- print("Disengaging reactors...")
- sleep(2)
- print("Reactors Offline")
- shell.run("r-off")
- shell.run("menu")
- else
- term.setCursorPos(1,1)
- print("Logging out...")
- sleep(2)
- os.shutdown()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement