Hello All
I’ve been stuck on this part of a tic-tac-toe game for a while now.
I am trying to have it where after a compartment is filled w/ “X” or an “O” that compartment becomes inactive and if clicked on again the touch id stays the same.
Any help will be appreciated.
Thanks.
d = display w10 = d.contentWidth \* .1 h10 = d.contentHeight \* .1 w20 = d.contentWidth \* .2 h20 = d.contentHeight \* .2 w40 = d.contentWidth \* .4 h40 = d.contentHeight \* .4 w60 = d.contentWidth \* .6 h60 = d.contentHeight \* .6 w80 = d.contentWidth \* .8 h80 = d.contentHeight \* .8 ----DRAW LINES FOR BOARD local lline = d.newLine(w40,h20,w40,h80 ) lline.strokeWidth = 5 local rline = d.newLine(w60,h20,w60,h80 ) rline.strokeWidth = 5 local bline = d.newLine(w20,h40,w80,h40 ) bline.strokeWidth = 5 local tline = d.newLine(w20,h60,w80,h60 ) tline.strokeWidth = 5 --PLACE BOARD COMPARTMENT DIMENSIONS IN TABLE board ={ {"tl", 1, w20, h40, w40, h20,0,0, true}, {"tm",2, w40,h40,w60,h20,0,0, true}, {"tr",3, w60,h40,w80,h20,0,0, true}, {"ml", 4, w20, h60, w40, h40,0,0, true}, {"mm",5, w40,h60,w60,h40,0,0, true}, {"mr",6, w60,h60,w80,h40,0,0, true}, {"bl", 7, w20, h80, w40, h60,0,0, true}, {"bm",8, w40,h80,w60,h60,0,0, true}, {"br",9, w60,h80,w80,h60,0,0, true} } -- local idx = 0 --FILL COMPARTMENT W/ COLOR & "X"/"O" WHEN TOUCHED local function fill (event) if event.phase == "began" then --MANAGE TOUCH ID if event.x \> w20 and event.x \< w80 then if event.y \> h20 and event.y \< h80 then idx = idx + 1 event.id = idx if event.id \>= 2 then idx = 0 end end end --------------------------------------- --MANAGE TURNS for t = 1, 9 do if event.x \> board[t][3] and event.x \< board [t][5] then if event.y \< board[t][4] and event.y \> board[t][6] then if event.id == 1 and board[t][8] == 0 then board[t][7] = 1 board[t][8] = 1 elseif event.id == 2 and board[t][8] == 0 then board[t][7] = 2 board[t][8] = 1 end end end end end ------------------------------------------ --FILL COMPARTMENT WITH X/O for i = 1, 9 do if board[i][7] == 1 then r = d.newRect(board[i][3],board [i][6],w20,h20) r:setFillColor(1,1,0) r.anchorX=0 r.anchorY=0 t = d.newText("X",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) elseif board[i][7] == 2 then r = d.newRect(board[i][3],board [i][6],w20,h20) r:setFillColor(1,0,0) r.anchorX=0 r.anchorY=0 t = d.newText("O",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) end end end Runtime:addEventListener("touch", fill)