Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local floors = {"Basement", "First Floor", "Roof"}
- function centerText(text, y)
- local width, height = term.getSize()
- local centerX = width/2
- local startX = math.ceil(centerX - string.len(text)/2)
- term.setCursorPos(startX, y)
- term.write(text)
- end
- function render(selected)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.white)
- term.clear()
- centerText("test",10)
- term.setCursorPos(2,2)
- term.setTextColor(colors.red)
- term.write("COSTCO ")
- term.setTextColor(colors.blue)
- term.write("CLUB")
- centerText("Select a Floor",5)
- term.setTextColor(colors.red)
- for i = 1, #floors do
- if i == selected then
- term.setTextColor(colors.black)
- centerText("> "..floors[i].." <", 6+2*i)
- term.setTextColor(colors.red)
- else
- centerText(floors[i], 6+2*i)
- end
- end
- end
- local floor = 1
- function goToFloor(n)
- diff = n - floor
- if diff < 0 then
- redstone.setOuput("back",false)
- else
- redstone.setOuput("back",true)
- end
- redstone.setOutput("right",false)
- repeat
- local id, msg = rednet.receive("ElevatorArrival")
- until tonumber(msg) == n
- redstone.setOutput("right",true)
- end
- local selectedFloor = 1
- function doInterface()
- while true do
- render(selectedFloor)
- local event, key = os.pullEventRaw("key")
- if key == keys.down then
- selectedFloor = selectedFloor + 1
- if selectedFloor > #floors then
- selectedFloor = 1
- end
- elseif key == keys.up then
- selectedFloor = selectedFloor - 1
- if selectedFloor < 1 then
- selectedFloor = #floors
- end
- elseif key == keys.enter then
- rednet.broadcast(selectedFloor, "ElevatorCall")
- end
- end
- end
- function doServer()
- while true do
- local id, msg = rednet.receive("ElevatorCall")
- goToFloor(tonumber(msg))
- end
- end
- function doFloor()
- term.clear()
- term.setCursorPos(1,1)
- term.write("What floor is this?")
- local val = tonumber(read())
- while true do
- os.pullEvent("redstone");
- rednet.broadcast(val,"ElevatorArrival")
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("1 for Interface, 2 for Server, 3 for Floor")
- result = read()
- if result == "1" then
- doInterface()
- elseif result == "2" then
- doServer()
- elseif result == "3" then
- doFloor()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement