kamilosxd678

Odjazdy Electric Touch

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