Advertisement
Guest User

Elevator client program

a guest
Dec 20th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. floor = 11
  2. rednet.open("back")
  3. serverID = 78
  4. floortable = {[1]="2", [2]="1", [3]="0", [4]="-1", [5]="-2", [6]="-3", [7]="-4", [8]="-5", [9]="-6", [10]="-7", [11]="-8"}
  5. banana = true
  6.  
  7. function gui()
  8.  local w,h = term.getSize()
  9.  local function printCentered(str, ypos)
  10.   term.setCursorPos(w/2 - #str/2, ypos)
  11.   term.write(str)
  12.  end
  13.  local function printRight(str, ypos)
  14.   term.setCursorPos(w - #str, ypos)
  15.   term.write(str)
  16.  end
  17.  
  18.  function drawHeader()
  19.   printCentered("ELEVATOR CONTROL", 1)
  20.   printCentered(string.rep("-", w), 2)
  21.   term.setCursorPos(1, 3)
  22.   term.write("Current floor:   ")
  23.   term.write(floor)
  24.  end
  25.  
  26.  function drawMain()
  27.   term.setCursorPos(1,4)
  28.   term.write("|  2 : balcony")
  29.   term.setCursorPos(1,5)
  30.   term.write("|  1 : 1st floor")
  31.   term.setCursorPos(1,6)
  32.   term.write("|  0 : lobby")
  33.   term.setCursorPos(1,7)
  34.   term.write("| -1: ")
  35.   term.setCursorPos(1,8)
  36.   term.write("| -2: ")
  37.   term.setCursorPos(1,9)
  38.   term.write("| -3: ")
  39.   term.setCursorPos(26,4)
  40.   term.write("| -4: ")
  41.   term.setCursorPos(26,5)
  42.   term.write("| -5: Train station")
  43.   term.setCursorPos(26,6)
  44.   term.write("| -6: ")
  45.   term.setCursorPos(26,7)
  46.   term.write("| -7: ")
  47.   term.setCursorPos(26,8)
  48.   term.write("| -8: ")
  49.  
  50.  term.setCursorPos(4,11)
  51.  term.write("Please enter destination floor: ")
  52.  end
  53.  drawHeader()
  54.  drawMain()
  55.  term.setCursorPos(42,11)
  56. end
  57.  
  58. function listen()
  59.  while true do
  60.   local sendID, obj, distance = rednet.receive()
  61.   if sendID == serverID then
  62.    if obj >= floor then
  63.     rs.setOutput("bottom", true)
  64.    else
  65.     rs.setOutput("bottom", false)
  66.    end
  67.   end
  68.  end
  69. end
  70.  
  71. function call()
  72.  while true do
  73.   if rs.getInput("left") == true then
  74.    rednet.send(serverID, "call")
  75.   end
  76.  end
  77. end
  78.  
  79. function input()
  80.  while true do
  81.   local input = read()
  82.   if input == "quit" then
  83.    banana = false
  84.    shell.quit()
  85.   end
  86.   for k,v in pairs(floortable) do
  87.    if v == input then
  88.     rednet.send(serverID, k)
  89.    else
  90.     term.setCursorPos(4,12)
  91.     term.write("Invalid floor number")
  92.    end
  93.   end
  94.  end
  95. end
  96.  
  97. function finish()
  98.  if rs.getInput("right") == true then
  99.   shell.exit()
  100.  end
  101. end
  102.  
  103. while banana == true do
  104.  gui()
  105.  parallel.waitForAny(listen, call, input, finish)
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement