Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = peripheral.wrap( "right" )
- modem = peripheral.wrap( "top" )
- porta = 13815
- portb = 13816
- modem.open(porta)
- m.setTextScale(2)
- x,y = m.getSize()
- m.clear()
- direction = 0
- --H H H /\
- --H H H \/
- floors = {}
- for i=1,6 do
- floors[i]=false
- end
- floorsCount=5
- currentFloor=3
- floors[2]=true
- function setColors(X)
- if X == 0 then --blank
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors.black)
- elseif X==1 then --inactive
- m.setTextColor(colors.lightGray)
- m.setBackgroundColor(colors.gray)
- elseif X==2 then --active
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors.lightGray)
- elseif X==3 then --current
- m.setTextColor(colors.white)
- m.setBackgroundColor(700)
- end
- end
- function redraw()
- setColors(0)
- m.clear()
- cf = 1
- for j=1,2 do
- for i=1,5 do
- m.setCursorPos(i,j)
- if i%2 == 1 and cf<=floorsCount then
- if cf==currentFloor then
- setColors(3)
- elseif floors[cf] == true then
- setColors(2)
- else
- setColors(1)
- end
- m.write(cf)
- cf = cf+1
- else
- setColors(0)
- m.write(" ")
- end
- end
- end
- setColors(0)
- for i=6,9 do
- for j=1,2 do
- m.setCursorPos(i,j)
- m.write(" ")
- end
- end
- if direction == 1 then
- m.setCursorPos(7,1)
- m.write("/\\")
- elseif direction == -1 then
- m.setCursorPos(7,2)
- m.write("\/")
- else
- m.setCursorPos(7,1)
- m.write("||")
- m.setCursorPos(7,2)
- m.write("||")
- end
- end
- function sendCommand(X)
- print("SEND "..X)
- end
- function controlAction()
- q = 0
- floors[currentFloor] = false
- for i=1,floorsCount do
- if floors[i] then q = q+1 end
- end
- if q == 0 then
- direction = 0
- elseif direction == 0 then
- if q ~= 0 then
- nq = 1
- for i=1,floorsCount do
- if floors[i] then
- nq = i
- end
- end
- if nq<current then
- direction = 1
- else
- direction = -1
- end
- sendCommand(nq)
- end
- elseif direction == 1 then
- nq = 0
- for i=1,currentFloor do
- if floors[i] then
- nq = i
- end
- end
- if nq == 0 then
- for i=1,floorsCount do
- if floors[i] then
- nq = i
- end
- end
- end
- if nq<current then
- direction = 1
- else
- direction = -1
- end
- sendCommand(nq)
- elseif direction == -1 then
- nq = 0
- for i=floorsCount,currentFloor,-1 do
- if floors[i] then
- nq = i
- end
- end
- if nq == 0 then
- for i=1,floorsCount do
- if floors[i] then
- nq = i
- end
- end
- end
- if nq<current then
- direction = 1
- else
- direction = -1
- end
- sendCommand(nq)
- end
- end
- redraw()
- while true do
- event = {os.pullEvent()}
- if event[1] == "monitor_touch" then
- print("Touch at "..event[3]..":"..event[4])
- if event[3]%2 ~= 0 and event[3]<6 then
- num = (event[3]+1)/2+3*(event[4]-1)
- if num <= floorsCount then
- floors[num] = not floors[num]
- redraw()
- end
- end
- elseif event[1] == "modem_message" then
- print(event[5])
- end
- controlAction()
- redraw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement