Advertisement
moomoomoo309

FamilyFeudBoard

Jan 27th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. Width=18 --Width of the box in the middle
  2. HSpaceBetween=6 --Space between boxes
  3. Margin=2 --Margins from the middle of the box
  4. insideColor=colors.black --Color in the box
  5. outsideColor=colors.blue --Color out of the box
  6.  
  7. local function draw(color,width) --Draws color in a line
  8.   for i=0,width do
  9.     x2,y2=m.getCursorPos()
  10.     m.setBackgroundColor(color)
  11.     m.write(" ") --Moves the cursor position and makes the monitor update properly
  12.     if color==insideColor then
  13.       table.insert(boxArea,{x=x2,y=y2}) --Stores coordinates of box in a table
  14.     end
  15.   end
  16. end
  17. local function drawLine(color) --Draws a whole line of the monitor a certain color
  18.   local _,y2=m.getCursorPos()
  19.   m.setCursorPos(1,y2)
  20.   draw(color,x)
  21. end
  22. local function drawBoard() --Draws the board
  23.   boxArea={}
  24.   m=peripheral.find("monitor")
  25.   if not m then
  26.     notMonitor=true
  27.     m=term
  28.   end
  29.   x,y=m.getSize()
  30.   m.clear()
  31.   m.setCursorPos(1,1)
  32.   numBoxes=0
  33.   for i=1,y do
  34.     m.setCursorPos(1,i)
  35.     if (i-1)%6==0 then --Space between the boxes
  36.       drawLine(colors.blue)
  37.     elseif (i-1)%6==5 then
  38.       numBoxes=numBoxes+2
  39.       drawLine(colors.blue)
  40.     elseif (i-1)%6==1 or (i-1)%6==4 then --Top and bottom of the box
  41.       draw(outsideColor,Margin+1)
  42.       draw(insideColor,Width-2)
  43.       draw(outsideColor,HSpaceBetween+2)
  44.       draw(insideColor,Width-2)
  45.       draw(outsideColor,Margin+1)
  46.     elseif (i-1)%6==2 or (i-1)%6==3 then --Middle part of the box
  47.       draw(outsideColor,Margin)
  48.       draw(insideColor,Width)
  49.       draw(outsideColor,HSpaceBetween)
  50.       draw(insideColor,Width)
  51.       draw(outsideColor,Margin)
  52.     end
  53.   end
  54. end
  55.  
  56. drawBoard()
  57.  
  58. while true do
  59.   local tx,ty=0,0
  60.   if not notMonitor then --If it's a monitor
  61.     eventType,tx,ty=os.pullEvent("touch")
  62.   else
  63.     eventType,mouseButton,tx,ty=os.pullEvent("mouse_click")
  64.   end
  65.   for i=1,#boxArea do
  66.     m.setCursorPos(1,1)
  67.     if tx==boxArea[i].x and ty==boxArea[i].y then --Did you touch a box?
  68.       local boxNum=(math.ceil(ty*(numBoxes/2)/y)-1)*2+1 --Divides monitor into sections, checking which portion of the monitor it is in. If it has 6 boxes, it checks if it's in the first, second, or last third.
  69.       if tx>x/2 then --If it's on the right side...
  70.         boxNum=boxNum+1
  71.       end
  72.       m.setCursorPos(1,1)
  73.       m.write("You touched box number "..boxNum.." ")
  74.       break
  75.     elseif i==#boxArea then --If it checked all the coordinates and you definitely didn't touch a box...
  76.       m.setCursorPos(1,1)
  77.       m.write("You touched empty space       ")
  78.     end
  79.   end
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement