Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Width=18 --Width of the box in the middle
- HSpaceBetween=6 --Space between boxes
- Margin=2 --Margins from the middle of the box
- insideColor=colors.black --Color in the box
- outsideColor=colors.blue --Color out of the box
- local function draw(color,width) --Draws color in a line
- for i=0,width do
- x2,y2=m.getCursorPos()
- m.setBackgroundColor(color)
- m.write(" ") --Moves the cursor position and makes the monitor update properly
- if color==insideColor then
- table.insert(boxArea,{x=x2,y=y2}) --Stores coordinates of box in a table
- end
- end
- end
- local function drawLine(color) --Draws a whole line of the monitor a certain color
- local _,y2=m.getCursorPos()
- m.setCursorPos(1,y2)
- draw(color,x)
- end
- local function drawBoard() --Draws the board
- boxArea={}
- m=peripheral.find("monitor")
- if not m then
- notMonitor=true
- m=term
- end
- x,y=m.getSize()
- m.clear()
- m.setCursorPos(1,1)
- numBoxes=0
- for i=1,y do
- m.setCursorPos(1,i)
- if (i-1)%6==0 then --Space between the boxes
- drawLine(colors.blue)
- elseif (i-1)%6==5 then
- numBoxes=numBoxes+2
- drawLine(colors.blue)
- elseif (i-1)%6==1 or (i-1)%6==4 then --Top and bottom of the box
- draw(outsideColor,Margin+1)
- draw(insideColor,Width-2)
- draw(outsideColor,HSpaceBetween+2)
- draw(insideColor,Width-2)
- draw(outsideColor,Margin+1)
- elseif (i-1)%6==2 or (i-1)%6==3 then --Middle part of the box
- draw(outsideColor,Margin)
- draw(insideColor,Width)
- draw(outsideColor,HSpaceBetween)
- draw(insideColor,Width)
- draw(outsideColor,Margin)
- end
- end
- end
- drawBoard()
- while true do
- local tx,ty=0,0
- if not notMonitor then --If it's a monitor
- eventType,tx,ty=os.pullEvent("touch")
- else
- eventType,mouseButton,tx,ty=os.pullEvent("mouse_click")
- end
- for i=1,#boxArea do
- m.setCursorPos(1,1)
- if tx==boxArea[i].x and ty==boxArea[i].y then --Did you touch a box?
- 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.
- if tx>x/2 then --If it's on the right side...
- boxNum=boxNum+1
- end
- m.setCursorPos(1,1)
- m.write("You touched box number "..boxNum.." ")
- break
- elseif i==#boxArea then --If it checked all the coordinates and you definitely didn't touch a box...
- m.setCursorPos(1,1)
- m.write("You touched empty space ")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement