Update 'Controller/CropController.lua'

This commit is contained in:
manuel 2023-01-13 09:59:02 +00:00
parent 43cdf10b5b
commit 984bcb2e9e

View File

@ -4,9 +4,45 @@ function CropController:new(t)
t = t or {}
setmetatable(t, self)
self.__index = self
t.matrix = {}
return t
end
function CropController:getMatrix()
local s, matrixString = self:doAction(self.slaveID, "getMatrix")
local matrix
if (s == true) then
self.matrix = self:toMatrix(matrixString)
end
end
function CropController:initMonitor()
self.monitor = peripheral.find("monitor")
self.monitor.setBackgroundColour(colours.black)
self.monitor.clear()
self.monitor.setTextScale(0.5)
self.monitor.setTextColour(colours.white)
term.redirect(self.monitor)
end
function CropController:displayMatrix()
assert(type(self.matrix) == "table")
assert(type(self.matrix[1]) == "table")
local width = #self.matrix
local length = #self.matrix[1]
for i = 1, width do
for j = 1, length do
term.setCursorPos(i,j)
if(self.matrix[i][j] >= 0) then
term.setTextColour(colours.white)
term.write(self.matrix[i][j])
else
term.setTextColour(colours.blue)
term.write("W")
end
end
end
end
function CropController:toMatrix(str)
local matrix = {}