Advertisement
Darking560

screen

Apr 2nd, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. mon = peripheral.wrap("left")
  2. rednet.open("bottom")
  3. mon.setTextScale(0.5)
  4.  
  5. local stair = -1
  6. local newstair
  7. local masterd = 1
  8. local newstair = 0
  9. local elevator = 7
  10.  
  11. button = {
  12.   [1] = {x = 7; y = 5; active = false; name = "-1"},
  13.   [2] = {x = 5; y = 5; active = true; name = " 0"},
  14.   [3] = {x = 11; y = 5; active = true; name = "-2"},
  15. }
  16.  
  17.  
  18. function waitClick()
  19.    event, a1, a2, a3 = os.pullEvent()
  20.    
  21.    if event == "rednet_message" then
  22.       newstair = tonumber(a2)
  23.       if newstair == stair then
  24.           for i = 2,3 do button[i].active = true
  25.                 print(i.." : "..tostring(button[i].active))
  26.           end
  27.           button[1].active = false
  28.       else
  29.           for i = 2,3 do button[i].active = false
  30.                 print(i.." : "..tostring(button[i].active))
  31.           end
  32.           button[1].active = true    
  33.       end
  34.       screen()
  35.    elseif event == "monitor_touch" then
  36.       local selectedButton = getButton(a2,a3)
  37.       if selectedButton == nil then
  38.           return
  39.       end
  40.       sleep(1.5)
  41.       rednet.send(elevator, button[selectedButton].name)
  42.       screen()
  43.    end
  44. end
  45.  
  46. function screen()
  47.    mon.clear()
  48.    mon.setCursorPos(5,1)
  49.    mon.write("Etage " .. newstair)
  50.    if newstair == stair then
  51.       mon.setCursorPos(1,2)
  52.       mon.write("~~~~~~~~~~~~~~~")
  53.           for i = 3,8 do
  54.              mon.setCursorPos(1,i)
  55.              mon.write("|")
  56.              mon.setCursorPos(15,i)
  57.              mon.write("|")
  58.           end
  59.           mon.setCursorPos(1,9)
  60.           mon.write("~~~~~~~~~~~~~~~")
  61.           mon.setBackgroundColor(colors.gray)
  62.           for i = 2,3 do  
  63.              mon.setCursorPos(button[i].x-2,button[i].y-1)
  64.              mon.write("     ")
  65.              mon.setCursorPos(button[i].x-2,button[i].y)
  66.              mon.write(" "..button[i].name.."  ")
  67.          mon.setCursorPos(button[i].x-2,button[i].y+1)
  68.              mon.write("     ")
  69.       end
  70.           mon.setBackgroundColor(colors.black)
  71.          
  72.         else
  73.           mon.setCursorPos(1,2)
  74.           mon.write("~~~~~~~~~~~~~~~")
  75.           for i = 3,8 do
  76.              mon.setCursorPos(1,i)
  77.              mon.write("|")
  78.              mon.setCursorPos(15,i)
  79.              mon.write("|")
  80.           end
  81.           mon.setCursorPos(1,9)
  82.       mon.write("~~~~~~~~~~~~~~~")
  83.           mon.setBackgroundColor(colors.red)
  84.           mon.setCursorPos(6,5)
  85.           mon.write(" Call")
  86.           mon.setBackgroundColor(colors.black)
  87.     end
  88. end
  89.  
  90. function getButton(xPos,yPos)
  91.   for i=1,3 do
  92.     if button[i].active == true then
  93.     bxPos = button[i].x
  94.     byPos = button[i].y
  95.     xMax = bxPos + 2
  96.     xMin = bxPos - 2
  97.     yMax = byPos + 1
  98.     yMin = byPos - 1
  99.     if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
  100.       return i
  101.     end
  102.     end
  103.   end
  104. end
  105.  
  106.  
  107. while true do
  108.   name = ""
  109.   waitClick()
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement