Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor");
- local bg1 = colors.gray;
- local bg2 = colors.lightGray;
- local bgclick = colors.red;
- local bgsuccess = colors.green;
- -- term.redirect(monitor);
- peripheral.find("modem", rednet.open);
- function gethost()
- while true do
- local tmphost = rednet.lookup("elevator", "elevator.api");
- if (type(tmphost) == "number") then
- return tmphost;
- end
- end
- end
- local host = gethost();
- print("start");
- function iam()
- -- host = rednet.lookup("elevator", "elevator.api");
- rednet.send(host, "iamelevator");
- end
- iam();
- monitor.setCursorPos(1, 1);
- monitor.setTextScale(0.5, 0.5);
- monitor.setBackgroundColor(colors.gray);
- monitor.clear();
- -- FLOOR CLASS
- Floor = { name = "floor", click = "none", x = 0, y = 0, width = 5, };
- function Floor:new (o, name, click, x, y)
- o = o or {}
- setmetatable(o, {__index = self});
- -- o.__index = self;
- o.name = name or "floor";
- o.click = click or "none";
- o.x = x or 0;
- o.y = y or 0;
- o.width = string.len(name);
- return o;
- end
- function Floor:render(col)
- monitor.setBackgroundColor(col);
- monitor.setCursorPos(self.x, self.y);
- monitor.write(self.name, colors.white, col);
- end
- function Floor:clicked (x, y)
- return (x >= self.x and x <= (self.x + self.width) and y == self.y);
- end
- -- FLOOR CLASS
- local floors = {};
- floors[1] = Floor:new(nil, "top", "requesttop", 1, 1);
- floors[2] = Floor:new(nil, "engine", "requestpower", 10, 1);
- floors[3] = Floor:new(nil, "-", "elevatorstop", 1, 3);
- floors[4] = Floor:new(nil, "+", "elevatorstart", 10,3);
- floors[5] = Floor:new(nil, "/\\", "elevatorup", 1, 5);
- floors[6] = Floor:new(nil, "\\/", "elevatordown", 10, 5);
- floors[7] = Floor:new(nil, "<|>", "dooropen", 1, 7);
- floors[8] = Floor:new(nil, ">|<", "doorclose", 10, 7);
- for it, val in pairs(floors) do
- print("it: " .. tostring(it));
- val:render(bg2);
- end
- while true do
- iam();
- event, side, xPos, yPos = os.pullEvent( "monitor_touch" );
- monitor.setBackgroundColor(bg1);
- monitor.clear();
- for it, val in pairs(floors) do
- val:render(bg2);
- if val:clicked(xPos, yPos) then
- -- rednet.send(7, "dooropen");
- rednet.send(host, val.click);
- val:render(bgclick);
- end
- end
- -- monitor.clear();
- -- monitor.setCursorPos(1, 1);
- -- monitor.write("Clicked: " .. tostring(objects[1]:clicked(xPos, yPos)));
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement