Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Client program (run on each player's ComputerCraft computer)
- -- Find the monitor
- local monitor = peripheral.find("monitor")
- if not monitor then
- print("No monitor found!")
- return
- end
- local blockWidth, blockHeight = 7, 5
- local blocksHorizontal, blocksVertical = 8, 4
- local width, height = blocksHorizontal * blockWidth, blocksVertical * blockHeight
- local drawingData = {} -- Table to store drawing data
- -- Function to draw the received data on the monitor
- function drawOnMonitor()
- monitor.clear()
- for _, pixel in ipairs(drawingData) do
- local blockX, blockY, color = pixel[1], pixel[2], pixel[3]
- -- Calculate pixel coordinates
- local startX = (blockX - 1) * blockWidth + 1
- local startY = (blockY - 1) * blockHeight + 1
- -- Draw the block
- for dx = 0, blockWidth - 1 do
- for dy = 0, blockHeight - 1 do
- local x = startX + dx
- local y = startY + dy
- if x >= 1 and x <= width and y >= 1 and y <= height then
- monitor.setCursorPos(x, y)
- monitor.setBackgroundColor(color)
- monitor.write(" ")
- end
- end
- end
- end
- end
- -- Function to display the timer on the monitor
- function displayTimer(timeLeft)
- monitor.setCursorPos(1, height)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.write("Time left: " .. timeLeft)
- end
- -- Function to handle incoming messages from the server
- function handleServerMessages()
- rednet.open("top")
- while true do
- local senderId, message = rednet.receive()
- if message:find("DRAWING") then
- drawingData = textutils.unserialize(message:sub(9))
- drawOnMonitor()
- elseif message:find("TIMER") then
- local timeLeft = message:sub(7)
- displayTimer(timeLeft)
- end
- end
- end
- -- Notify the server that this client has joined
- rednet.open("top")
- rednet.broadcast("JOIN")
- handleServerMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement