Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# My base class which is the ground on which every class is buit on
- local BaseClass = {}
- function BaseClass.new()
- local self = {}
- return setmetatable(self, {__index = BaseClass})
- end
- BaseClass.__call = function(...)
- return BaseClass.new(...)
- end
- setmetatable(BaseClass,BaseClass)
- function BaseClass.getType()
- return "BaseClass"
- end
- --# My square class which allows to draw squares
- local SquareClass = {__index = BaseClass, col = colors.lime}
- function SquareClass.new(sX,sY,length,height,col)
- local self = BaseClass()
- self.l = length
- self.height = height
- self.col = col
- self.sx = sX
- self.sy = sY
- return setmetatable(self, {__index = SquareClass})
- end
- function SquareClass.getType()
- return "SquareClass"
- end
- function SquareClass:setLength(length)
- self.length = length
- return self
- end
- function SquareClass:setWidth(width)
- self.width = width
- return self
- end
- function SquareClass:getLength()
- return self.length
- end
- function SquareClass:getWidth()
- return self.height
- end
- function SquareClass:draw(t)
- if t == "fill" then
- term.setBackgroundColor(self.col)
- for i = self.sy, self.height do
- term.setCursorPos(self.sx,i)
- for j = self.sx, self.length do
- term.write(" ")
- end
- end
- elseif t == "outline" then
- for i = self.sy, self.height do
- if i == self.sy or i == self.height then
- term.setBackgroundColor(self.col)
- for j = self.sx, self.length do
- term.write(" ")
- end
- else
- for j = self.sx, self.length do
- if j == self.sx or j == self.l then
- term.setBackgroundColor(self.col)
- term.write(" ")
- else
- term.setBackgroundColor(colors.black)
- end
- end
- end
- end
- end
- end
- function SquareClass.__call(...)
- return SquareClass.new(...)
- end
- setmetatable(SquareClass, SquareClass)
- local sq = SquareClass(3,3,3,3,null)
- sq:draw("fill")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement