In this project, you will develop a program that plays Tic-Tac-Toe as well as you do.
On this first page, you use clones to display a Tic-Tac-Toe board and let two human players enter moves.
The project is spread out over different units because there's a lot to do, and because some steps require techniques you haven't learned yet. On this page, you'll learn about cloning a sprite (like copying it, only better). In the future, you'll extend the project to detect wins and ties and, ultimately, to let the computer be one of the players.
One approach to building this game is to use multiple sprites; each square of the board is a separate sprite. Each sprite knows where it is on the board, and, once positioned, the sprites never move. The player clicks one of the nine squares, and that sprite changes its costume to display the move.
You will use clones to create the 3×3 Tic-Tac-Toe board.
A clone is a copy of a sprite that shares information with its parent sprite (the original sprite). For example, clones have copies of any scripts from the parent, and if the parent's script is changed, then the clones' scripts change too. However, changes you make to a clone are not shared with the parent, so you can do things like move each clone to a different position.
Clones start with the same position, costumes, and scripts of their parent. But clones made by a program...
(There can also be permanent clones, which are created differently, but they're not used in this project.)
stamp
Pen block, which just leaves a picture of the sprite on the stage.create a clone
block takes an input because it can copy any sprite. In this project, there's only one sprite at the beginning, so your choices are either myself or Square (the sprite's name), which in this case, means the same thing.when I am clicked
demonstration script from exercise 3.when
⚑ clicked
block toward the bottom of the scripting area to the script just below it.makeBoard
block is empty. You'll write it in the next problem.true
when it's X's turn to play or false
when it's O's turn.
not
to switch between them and you can use if
to test the variable. (Recall that if
requires a true
/false
input.)makeBoard
to set up nine clones in three rows of three.show
the original sprite before cloning it, so that the clones will be visible. After cloning nine times to create the board, hide
the original sprite so it does not interfere with the game as a tenth square.makeBoard
.
when I am clicked
script that will make each clone wear the proper costume when clicked: X or O depending on whose turn it is.You can leave comments in the project file to remind yourself of things you might want to do later.