Of course it’s not a difficult question, but you’re asking someone to read through 200 lines of unformatted code they haven’t seen before, work out what it’s doing (there are a hundred ways you could implement tic-tac-toe) then work out exactly what you actually want it to do, which isn’t at all clear from the original post.
It is unfortunate the tutorial seems to be poorly done, simply skipping over key lines of code. Pretty amazed that’s an official Corona video really…
Here’s what that bit of code does:
[lua]
for i = 1, 9 do – loop through the nine squares
spots[i] = display.newRect( 0, 0, 90, 90) – create a new 90 x 90 square and add it to the spots table
spots[i]:setFillColor( 0.2, 0.2, 0.2 ) – set the colour to grey
spots[i].x = ( i - 1 ) % 3 * 100 + 60 – calculate the X position of the square (see below)
– i - 1 – if we are doing square one, use 0. if we are doing square 6, use 5.
– % 3 – get the remainder of (i-1) when divided by 3. This gives us our ‘column ID’
– 0 % 3 = 0. 1 % 3 = 1. 2 % 3 = 2. 3 % 3 = 0. 4 % 3 = 1. etc.
– * 100 – multiply the column ID by 100. So the first column will be 0, the last column 200.
– + 60 – finally add 60 to the calculation. Column 0 = 60. Column 1 = 160. Column 2 = 260
spots[i].y = math.floor( ( i - 1 ) / 3 ) * 100 + 140 – calculate the Y position of the square (see below)
– i - 1 – if we are doing square one, use 0. if we are doing square 6, use 5.
– / 3 – divide this number by 3. 1 / 3 = 0.333. 4 / 3 = 1.333.
– math.floor – round this number down to the nearest whole number.
– therefore, 0.333 = 0, 1.333 = 1
– this gives us our ‘row ID’
– * 100 – multiply the row ID by 100. Row 0 = 0. Row 2 = 200.
– + 140 – add 140 to the calculation. Row 0 = 140. Row 1 = 240. Row 2 = 340
spots[i].moveText = display.newText( i, spots[i].x, spots[i].y, native.systemFontBold, 80)
– create a text object in the same place as our square
spots[i].moveType = nil – pointless line…already nil
spots[i]:addEventListener( “touch”, handleMove ) – add a touch listener to this square, which will call handleMove function.
end
[/lua]