Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lights = {}
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function getNum(num)
- return math.floor((num+1)/2)
- end
- clear()
- write "Enter Difficulty (minimum of 3): "
- d = tonumber(read())
- if d < 3 then
- error("Please Enter a number greater than 3")
- end
- for i=1, d*d do
- lights[i] = "false"
- end
- for i=1, d/3+d%3 do
- lights[math.random(d*d)] = "true"
- end
- clear()
- function drawLights()
- for i=1, d do
- for a=1, d do
- term.setCursorPos((a*2)-1,i)
- if lights[(i*d)-(d-a)] == "false" then
- write("X")
- else
- write"O"
- end
- end
- end
- end
- drawLights()
- local function getCoor()
- return (y*d)-(d-x)
- end
- local function setLights(lightNum)
- if lights[lightNum] == "true" then
- lights[lightNum] = "false"
- else
- lights[lightNum] = "true"
- end
- end
- while true do
- event, mouse, x, y = os.pullEvent("mouse_click")
- term.setCursorPos(1,7)
- x = getNum(x)
- setLights(getCoor())
- if y ~= 1 then
- setLights(getCoor()-d)
- end
- if y < d then
- setLights(getCoor()+d)
- end
- if x < d then
- setLights(getCoor()+1)
- end
- if x ~= 1 then
- setLights(getCoor()-1)
- end
- drawLights()
- local test = false
- for i=1, #lights do
- if lights[i] == "false" then
- test = true
- end
- end
- if test == false then
- break
- end
- end
- term.setTextColor(colors.yellow)
- drawLights()
- os.pullEvent()
- clear()
Advertisement
Add Comment
Please, Sign In to add comment