In Unit 1, you started building a tic-tac-toe game by writing the code to draw the game board. Now you'll take another step by sensing which cell a player wants to move into and centering the "X" or "O" in that cell.
that tests whether its first input is bigger than the second input and less than the third. You'll use this to test where the sprite is.
that uses your between? block to report true if the sprite is on the board and report false if the sprite is dragged completely off the board.which cell? that tells which cell the sprite has been dragged into. One way to do that is to build blocks that reports which column? and which row? the sprite is in and then figure out how to use them to report the exact cell.which row? and which column? blocks, but try to build them yourself first.-without-computation.png)
Remember: Your board isn't only for tic-tac-toe. You can draw nine-by-nine Sudoku boards, seven-by-seven Connect Four boards, and so on. So, these blocks will need the input n to specify how many rows and columns are in the grid.
which row? and which column? You might think of using lots of if statements, but since the number of rows can change, you don't know how many to use. One convenient way is to divide the total size of the game board by the size of each cell. To use that result, you need to round down. The
block can do it, but it rounds to the nearest integer, up or down. The function
always rounds down, making it easier to use. Likewise, the function
always rounds up. The floor and ceiling functions are in the same block as sqrt.
move to tile, you may want mod. You saw mod in Unit 1 Lesson 4, Expressions and Operations.
block that takes a tile number as input and moves your sprite to the center of that tile. Because the location of the tile (for example, tile 7) depends on how many tiles there are in a row, this block will also need an input that says how many tiles are in each row.when I am dropped script for the XO sprite so that when the sprite is dropped, it moves to the center of its tile before it is stamped.