Advertisement
Guest User

GUI

a guest
Nov 4th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. --# My base class which is the ground on which every class is buit on
  2.  
  3. local BaseClass = {}
  4.  
  5. function BaseClass.new()
  6.     local self = {}
  7.     return setmetatable(self, {__index = BaseClass})
  8. end
  9.  
  10. BaseClass.__call = function(...)
  11.     return BaseClass.new(...)
  12. end
  13.  
  14. setmetatable(BaseClass,BaseClass)
  15.  
  16. function BaseClass.getType()
  17.     return "BaseClass"
  18. end
  19.  
  20.  
  21. --# My square class which allows to draw squares
  22.  
  23. local SquareClass = {__index = BaseClass, col = colors.lime}
  24.  
  25. function SquareClass.new(sX,sY,length,height,col)
  26.     local self = BaseClass()
  27.     self.l = length
  28.     self.height = height
  29.     self.col = col
  30.     self.sx = sX
  31.     self.sy = sY
  32.     return setmetatable(self, {__index = SquareClass})
  33. end
  34.  
  35. function SquareClass.getType()
  36.     return "SquareClass"
  37. end
  38.  
  39. function SquareClass:setLength(length)
  40.     self.length = length
  41.     return self
  42. end
  43.  
  44. function SquareClass:setWidth(width)
  45.     self.width = width
  46.     return self
  47. end
  48.  
  49. function SquareClass:getLength()
  50.     return self.length
  51. end
  52.  
  53. function SquareClass:getWidth()
  54.     return self.height
  55. end
  56.  
  57. function SquareClass:draw(t)
  58.    
  59.     if t == "fill" then
  60.         term.setBackgroundColor(self.col)
  61.         for i = self.sy, self.height do
  62.             term.setCursorPos(self.sx,i)
  63.             for j = self.sx, self.length do
  64.                 term.write(" ")
  65.             end
  66.         end
  67.     elseif t == "outline" then
  68.         for i = self.sy, self.height do
  69.             if i == self.sy or i == self.height then
  70.                 term.setBackgroundColor(self.col)
  71.                 for j = self.sx, self.length do
  72.                     term.write(" ")
  73.                 end
  74.             else
  75.                 for j = self.sx, self.length do
  76.                     if j == self.sx or j == self.l then
  77.                         term.setBackgroundColor(self.col)
  78.                         term.write(" ")
  79.                     else
  80.                         term.setBackgroundColor(colors.black)
  81.                     end
  82.                 end
  83.             end
  84.         end
  85.     end
  86. end
  87.  
  88.  
  89. function SquareClass.__call(...)
  90.     return SquareClass.new(...)
  91. end
  92.  
  93. setmetatable(SquareClass, SquareClass)
  94.  
  95. local sq  = SquareClass(3,3,3,3,null)
  96. sq:draw("fill")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement