Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- Ticket selling machine
- ---- Tickets are being sold as labeled floppys
- ---- and can be further used on station to get a train to a demanded destination
- -- os.pullEvent = os.pullEventRaw
- ---- Config
- -- Sides of components
- sides = {}
- sides[1] = "right" -- Monitor
- sides[2] = "back" -- Checking the payment
- sides[3] = "top" -- Sending the floppy
- sides[4] = "left" -- Floppy side
- -- Filenames
- files = {}
- files[1] = "infopanel" -- Monitor text
- files[2] = "stations" -- Station list
- -- Monitor on the right is being used as a information panel
- mon = peripheral.wrap(sides[1])
- ---- Functions
- -- Writing on information panel
- function writeInfo()
- monX, monY = mon.getSize()
- mon.clear()
- file = fs.open(files[1], "r")
- x = file.readLine()
- i = 1
- while not (x == nil) do
- if not(i > monY) then
- mon.setCursorPos(1,i)
- mon.write(x)
- i = i+1
- end
- x = file.readLine()
- end
- file.close()
- end
- -- Get ticket
- function getTicket(station)
- if not disk.isPresent(sides[4]) then
- rs.setOutput(sides[3], true)
- os.sleep(1)
- rs.setOutput(sides[3], false)
- elseif disk.getLabel(sides[4]) == "cmd:shutdown" then
- shell.exit()
- end
- write("Wybrano stacje " .. station .. "\n")
- disk.setLabel(sides[4], station)
- disk.eject(sides[4])
- end
- -- Stations validate
- function validateInput(input)
- if input == "cmd:shutdown" then
- return true
- end
- file = fs.open(files[2], "r")
- x = file.readLine()
- input = string.lower(input)
- while not (x == nil) do
- if x == input then
- return true
- end
- x = file.readLine()
- end
- return false
- end
- ---- Main program
- writeInfo()
- term.clear()
- term.setCursorPos(1,1)
- write("Prosze umiescic 1 sticky resin w skrzyni na dole\n")
- while true do
- if rs.getInput(sides[2]) then
- term.clear()
- term.setCursorPos(1,1)
- write("Prosze podac nazwe stacji docelowej:\n")
- input = read()
- while not validateInput(input) do
- write("Prosze podac PRAWIDLOWA nazwe stacji docelowej!\n")
- input = read()
- end
- getTicket(input)
- write("Dziekujemy za skorzystanie z naszych uslug! Zapraszamy ponownie! \n")
- write("Bilet powinien znajdowac sie w twoim ekwipunku!\n")
- write("W przypadku, gdy Twoj ekwipunek jest pelny bilet znajduje sie na ziemi\n")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- write("Prosze umiescic 1 sticky resin w skrzyni na dole\n")
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment