kamilosxd678

Odjazdy Electric

Jan 13th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.34 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.    else
  53.       sleep(1)
  54.       redstone.setBundledOutput("top", colors.pink)
  55.       sleep(1)
  56.       trainFetched = true
  57.    end
  58.  
  59.    redstone.setBundledOutput("top", 0)
  60.  
  61.    return trainFetched
  62. end
  63.  
  64. function addDeparture(name, timeLeft)
  65.    monitor.setBackgroundColor( colors.black )
  66.    monitor.setTextColor( colors.white )
  67.  
  68.    -- time
  69.    local nameTrimmed = ""
  70.    
  71.    if string.len(name) > 17 then
  72.       nameTrimmed = string.sub(name, 0, 17)
  73.    else
  74.       nameTrimmed = name
  75.    end
  76.    
  77.    monitor.setCursorPos(8, 9)
  78.    monitor.write("                 ")
  79.    monitor.setCursorPos(28, 9)
  80.    monitor.write("          ")
  81.    
  82.    monitor.setCursorPos(8, 9)
  83.    monitor.write(nameTrimmed)
  84.    monitor.setCursorPos(28, 9)
  85.    monitor.write(timeLeft)
  86. end
  87.  
  88. -- 47s
  89. function announceTrain(name)
  90.    local timeLeft = 5
  91.    local timeLeftText = string.format("%d s", timeLeft)
  92.    local ticketPrinter = peripheral.wrap("back")
  93.    ticketPrinter.createTicket(name, 1)
  94.    
  95.    ticketPhase = 0
  96.    
  97.    while (timeLeft ~= 0) do
  98.       timeLeftText = string.format("%d s", timeLeft)
  99.       addDeparture(name, timeLeftText)
  100.       timeLeft = timeLeft - 1
  101.       sleep(1)
  102.      
  103.       if ticketPhase == 0 then
  104.          redstone.setOutput("bottom", true)
  105.          ticketPhase = ticketPhase + 1
  106.       elseif ticketPhase == 1 then
  107.          redstone.setOutput("bottom", false)
  108.          ticketPhase = ticketPhase + 1
  109.       end
  110.    end
  111.    
  112.    addDeparture("-----------------", "----------")
  113.    
  114.    os.shutdown()
  115. end
  116.  
  117. function createMenu()
  118.    term.clear()
  119.    term.setCursorPos(1,1)
  120.    term.write("Witaj!")
  121.    term.setCursorPos(1,2)
  122.    term.write("Wybierz prosze numer stacji do ktorej chcesz jechac")
  123.    
  124.    for i=1, table.getn(stationNames) do
  125.       term.setCursorPos(1,2 + i)
  126.       term.write(string.format("%d. %s", i, stationFullNames[i]))
  127.    end
  128.    
  129.    term.setCursorPos(1, 3 + table.getn(stationNames))
  130.    term.setCursorBlink(true)
  131.    
  132.    local input = read()
  133.    input = tonumber(input)
  134.    
  135.    term.setCursorPos(1, 4 + table.getn(stationNames))
  136.    
  137.    local valueValid = false
  138.    
  139.    if input then
  140.       if input >= 1 and input <= table.getn(stationNames) then
  141.          valueValid = true
  142.       end
  143.    end
  144.    
  145.    term.setCursorPos(1, 4 + table.getn(stationNames))
  146.    
  147.    if valueValid then
  148.       term.write(string.format("Wybrales stacje %s", stationFullNames[input]))
  149.      
  150.       if fetchTrain() then
  151.          term.setCursorPos(1, 5 + table.getn(stationNames))
  152.          term.write("Prosze czekac. Twoj pociag niebawem przyjedzie")
  153.          announceTrain(stationNames[input])
  154.       else
  155.          sleep(5)
  156.       end
  157.    else
  158.       term.write("Wprowadziles niepoprawna wartosc")
  159.       sleep(5)
  160.    end
  161. end
  162.  
  163. function main()
  164.    writeDepartures()
  165.    writeTimeTable()
  166.  
  167.    --announceTrain("SlimeVille")
  168.    
  169.    while true do
  170.       os.queueEvent("randomEvent")
  171.       os.pullEvent()
  172.       createMenu()
  173.    end
  174.    
  175.    --if (fetchTrain() == true) then
  176.    --   announceTrain("Dupa")
  177.    --end
  178. end
  179.  
  180. main()
Advertisement
Add Comment
Please, Sign In to add comment