Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- grid-demo
- -- Grid testing.
- term.clear
- -- Variables
- button_lc = 1
- button_rc = 2
- exit_ = "q"
- w,h = term.getSize()
- -- 3x3 grid
- grid = {
- 0,0,0,0,0,0;
- 0,0,0,0,0,0;
- 0,0,0,0,0,0;
- }
- gridColumnWidth = 6
- -- Draw the grid
- function drawGrid()
- for i=1, #grid do
- term.setCursorPos(1,i)
- term.write( string.rep("*",gridColumnWidth) )
- end
- end
- drawGrid()
- function SetTile(n) grid[ n+#grid ] = 1 end
- function DetTile(n) grid[ n+#grid ] = 0
- term.setCursorPos( (w-string.len("Hold CTRL+T to exit.")) + 1, h )
- term.write("Hold CTRL+T to exit.")
- -- Main program
- while true do
- local event, button, x, y = os.pullEvent()
- if(event == "mouse_click") then
- if(button == button_lc) then
- if(x >= 1 and x <= gridColumnWidth and y >= 1 and y <= #grid) then
- SetTile(x)
- --drawGrid()
- term.setCursorPos(x,y)
- term.setTextColour(colours.white)
- term.setBackgroundColour(colours.white)
- term.write("D")
- end
- elseif(button == button_rc) then
- if(x >= 1 and x <= gridColumnWidth and y >= 1 and y <= #grid) then
- DetTile(x)
- --drawGrid()
- term.setCursorPos(x,y)
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- term.write("*")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement