kamilosxd678

Odjazdy

Jan 5th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.80 KB | None | 0 0
  1. local monitor = peripheral.wrap( "left" )
  2.  
  3. local stationNames = {"RedwoodFactory", "SlimeVille", "EmeraldValley", "Coppertino"}
  4. local stationFullNames = {"Redwood Factory", "Slime Ville", "Emerald Valley", "Coppertino"}
  5.  
  6. function writeDepartures()
  7.    monitor.setCursorPos( 3, 2 )
  8.    monitor.blit("                                  ", "ffffffffffffffffffffffffffffffffff", "feeffeeeeffeeeffeeffeeeefeeeffeffe")
  9.    monitor.setCursorPos( 3, 3 )
  10.    monitor.blit("                                  ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffeffffefeffefeffe")
  11.    monitor.setCursorPos( 3, 4 )
  12.    monitor.blit("                                  ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffefffeffeffeffeef")
  13.    monitor.setCursorPos( 3, 5 )
  14.    monitor.blit("                                  ", "ffffffffffffffffffffffffffffffffff", "effefeffefeffefeeeeffefffeffefffef")
  15.    monitor.setCursorPos( 3, 6 )
  16.    monitor.blit("                                  ", "ffffffffffffffffffffffffffffffffff", "feeffeeefffeeffeffefeeeefeeeffffef")
  17. end
  18.  
  19. function writeTimeTable()
  20.    monitor.setBackgroundColor( colors.black )
  21.    monitor.setTextColor( colors.white )
  22.  
  23.    monitor.setCursorPos( 2, 8 )
  24.    monitor.write("Lp. | Kierunek          | Do odjazdu")
  25.    monitor.setCursorPos( 2, 9 )
  26.    monitor.write("1   | ----------------- | ----------")
  27.    monitor.setCursorPos( 2, 10 )
  28.    monitor.write("2   | ----------------- | ----------")
  29.    monitor.setCursorPos( 2, 11 )
  30.    monitor.write("3   | ----------------- | ----------")
  31.    monitor.setCursorPos( 2, 12 )
  32.    monitor.write("4   | ----------------- | ----------")
  33.    monitor.setCursorPos( 2, 13 )
  34.    monitor.write("5   | ----------------- | ----------")
  35.    monitor.setCursorPos( 2, 14 )
  36.    monitor.write("6   | ----------------- | ----------")
  37.    monitor.setCursorPos( 2, 15 )
  38.    monitor.write("7   | ----------------- | ----------")
  39.    monitor.setCursorPos( 2, 16 )
  40.    monitor.write("8   | ----------------- | ----------")
  41.    monitor.setCursorPos( 2, 17 )
  42.    monitor.write("9   | ----------------- | ----------")
  43.    monitor.setCursorPos( 2, 18 )
  44.    monitor.write("10  | ----------------- | ----------")
  45. end
  46.  
  47. function fetchTrain()
  48.    local trainFetched = false
  49.  
  50.    if (colors.test (redstone.getBundledInput("right"), colors.blue)) then
  51.       print("Pociag czeka na peronie odjazdow")
  52.    elseif (colors.test (redstone.getBundledInput("right"), colors.red)) then
  53.       redstone.setBundledOutput("top", colors.red)
  54.       trainFetched = true
  55.    elseif (colors.test (redstone.getBundledInput("right"), colors.lightBlue)) then
  56.       redstone.setBundledOutput("top", colors.lightBlue)
  57.       trainFetched = true
  58.    elseif (colors.test (redstone.getBundledInput("right"), colors.lime)) then
  59.       redstone.setBundledOutput("top", colors.lime)
  60.       trainFetched = true
  61.    else
  62.       print("Brak dostepnych pociagow :-(")
  63.    end
  64.    
  65.    sleep(4)
  66.    redstone.setBundledOutput("top", colors.pink)
  67.    sleep(1)
  68.  
  69.    redstone.setBundledOutput("top", 0)
  70.  
  71.    return trainFetched
  72. end
  73.  
  74. function addDeparture(name, timeLeft)
  75.    monitor.setBackgroundColor( colors.black )
  76.    monitor.setTextColor( colors.white )
  77.  
  78.    -- time
  79.    local nameTrimmed = ""
  80.    
  81.    if string.len(name) > 17 then
  82.       nameTrimmed = string.sub(name, 0, 17)
  83.    else
  84.       nameTrimmed = name
  85.    end
  86.    
  87.    monitor.setCursorPos(8, 9)
  88.    monitor.write("                 ")
  89.    monitor.setCursorPos(28, 9)
  90.    monitor.write("          ")
  91.    
  92.    monitor.setCursorPos(8, 9)
  93.    monitor.write(nameTrimmed)
  94.    monitor.setCursorPos(28, 9)
  95.    monitor.write(timeLeft)
  96. end
  97.  
  98. -- 47s
  99. function announceTrain(name)
  100.    local timeLeft = 47
  101.    local timeLeftText = string.format("%d s", timeLeft)
  102.    local ticketPrinter = peripheral.wrap("back")
  103.    ticketPrinter.createTicket(name, 1)
  104.    
  105.    ticketPhase = 0
  106.    
  107.    while (timeLeft ~= 0) do
  108.       timeLeftText = string.format("%d s", timeLeft)
  109.       addDeparture(name, timeLeftText)
  110.       timeLeft = timeLeft - 1
  111.       sleep(1)
  112.      
  113.       if ticketPhase == 0 then
  114.          redstone.setOutput("bottom", true)
  115.          ticketPhase = ticketPhase + 1
  116.       elseif ticketPhase == 1 then
  117.          redstone.setOutput("bottom", false)
  118.          ticketPhase = ticketPhase + 1
  119.       end
  120.    end
  121.    
  122.    addDeparture("-----------------", "----------")
  123. end
  124.  
  125. function createMenu()
  126.    term.clear()
  127.    term.setCursorPos(1,1)
  128.    term.write("Witaj!")
  129.    term.setCursorPos(1,2)
  130.    term.write("Wybierz prosze numer stacji do ktorej chcesz jechac")
  131.    
  132.    for i=1, table.getn(stationNames) do
  133.       term.setCursorPos(1,2 + i)
  134.       term.write(string.format("%d. %s", i, stationFullNames[i]))
  135.    end
  136.    
  137.    term.setCursorPos(1, 3 + table.getn(stationNames))
  138.    term.setCursorBlink(true)
  139.    
  140.    local input = read()
  141.    input = tonumber(input)
  142.    
  143.    term.setCursorPos(1, 4 + table.getn(stationNames))
  144.    
  145.    local valueValid = false
  146.    
  147.    if input then
  148.       if input >= 1 and input <= table.getn(stationNames) then
  149.          valueValid = true
  150.       end
  151.    end
  152.    
  153.    term.setCursorPos(1, 4 + table.getn(stationNames))
  154.    
  155.    if valueValid then
  156.       term.write(string.format("Wybrales stacje %s", stationFullNames[input]))
  157.      
  158.       if fetchTrain() then
  159.          term.setCursorPos(1, 5 + table.getn(stationNames))
  160.          term.write("Prosze czekac. Twoj pociag niebawem przyjedzie")
  161.          announceTrain(stationNames[input])
  162.       else
  163.          sleep(5)
  164.       end
  165.    else
  166.       term.write("Wprowadziles niepoprawna wartosc")
  167.       sleep(5)
  168.    end
  169. end
  170.  
  171. function main()
  172.    writeDepartures()
  173.    writeTimeTable()
  174.  
  175.    --announceTrain("SlimeVille")
  176.    
  177.    while true do
  178.       os.queueEvent("randomEvent")
  179.       os.pullEvent()
  180.       createMenu()
  181.    end
  182.    
  183.    --if (fetchTrain() == true) then
  184.    --   announceTrain("Dupa")
  185.    --end
  186. end
  187.  
  188. main()
Advertisement
Add Comment
Please, Sign In to add comment