Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("right")
- monitor.clear()
- rednet.open("bottom")
- curfloor = -3
- db={}
- for i=1,19 do
- db[i]={}
- end
- function strsplit(s)
- words = {}
- i=1
- for word in string.gmatch(s, "([^,]+)") do
- words[i]=word
- i=i+1
- end
- return words
- end
- function detect(curfloor)
- os.startTimer(3)
- rednet.broadcast("ack",curfloor)
- t=1
- while t do
- event,id,message,protocol=os.pullEvent()
- if event=="rednet_message" and protocol =="ack" then
- x = tonumber(strsplit(message)[1])
- y = tonumber(strsplit(message)[2])
- db[y][x]=id
- print(x.." "..y.." "..id)
- elseif event=="timer" then
- t=0
- end
- end
- end
- function drawcomputers()
- for y=1,19 do
- for x=1,29 do
- if db[x][y] then
- monitor.setCursorPos(x,y)
- monitor.write(" ")
- end
- end
- end
- function drawFile(f,s)
- fails = fs.open(f,"r")
- for line=1,28 do
- row = fails.readLine()
- if row then
- for char=1,string.len(row) do
- sym = string.sub(row,char,char)
- if s == 1 then
- monitor.setCursorPos(char+24,line)
- else
- monitor.setCursorPos(char,line)
- end
- if sym == "#" then
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ")
- elseif sym == "r" then
- monitor.setBackgroundColor(colors.red)
- monitor.write(" ")
- elseif sym == "g" then
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- elseif sym == "b" then
- monitor.setBackgroundColor(colors.blue)
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.black)
- monitor.write(" ")
- end
- end
- end
- end
- if s == 0 then
- monitor.setCursorPos(1,1)
- monitor.write("Floor:")
- monitor.setCursorPos(13-string.len(f)/2,1)
- monitor.write(f)
- end
- end
- while true do
- drawFile(tostring(curfloor),0)
- drawFile("sidebar",1)
- event,side,x,y =os.pullEvent("monitor_touch")
- if x >25 and x<29 and y>1 and y<6 then
- if fs.exists(tostring(curfloor+1)) then
- curfloor = curfloor+1
- end
- end
- if x>25 and x<29 and y>6 and y<11 then
- if fs.exists(tostring(curfloor-1)) then
- curfloor = curfloor-1
- end
- end
- if x>25 and x<29 and y>11 and y<16 then
- detect(curfloor)
- drawComputers()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement