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.
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.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 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.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.