In this tutorial, we will create your own version of Tic-Tac-Toe scratch game also known as Noughts and Crosses . Tic-Tac-Toe is normally played with two players. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of their marks on the board in a row, column, or diagonal, they win. When the board fills up with neither player winning, the game ends in a tie.
In this lesson, we will create Halloween version of Tic Tac toe with Pumpkins and Bats.
Lets start with a two player game, where each player takes a turn to put Pumpkin or a Bat into a box and if you get a line of Pumpkin’s or Bat’s you win!.
For this game we need 9 sprites – one for each box on the board. Name your sprite something which makes sense like, Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9. Each sprite contains three costumes: Blank, Pumpkin and Bat. The player clicks one of the nine squares, and that sprite changes its costume to display the move.
Program each sprite so that, If player clicked the sprite (Box), switch costume to ‘Pumpkin’ or ‘Bat’ and mark player played the box. After the player makes a move, the program checks whether they won or caused a tie, and then the game switches turns.
As each play is made it will be necessary for you to track what boxes have been played, not only to ensure a player doesn’t play that box again, but also because you need to know if there is a winning line.
Create variable called A1, A2, A3, B1, B2, B3, C1, C2, C3 to represent each sprite, to track which player played which box.
First, you must figure out how to represent the data in a variable. The data are either ‘Pumpkin’ for the player 1, ‘Bat’ for the player 2, or a -1 for a blank space. Data in the each variable represents the state of the board.
The variable A1, A2, A3, B1, B2, B3, C1, C2, C3 keep track of whether the each box in Board is empty or filled with an ‘Pumpkin’ or ‘Bat’.
There are eight possible ways to win at Tic-Tac-Toe: you can have a line across the top, middle, or bottom rows; you can have a line down the left, middle, or right columns; or you can have a line across either of the two diagonals.
To detect wins and ties, the program needs a way to test the state of the whole gameboard.
By default all the variables are set to -1 (i.e, for Blank Box).
Create a subprogram to detect a win.
For a player 1, there are eight ways to win and each corresponds to 3 ‘Pumpkin’s in a row or column or diagonal.
For example if A1 =A2=A3 for player 1, then switch costume to ‘Pumpkin wins’ Or else switch costume to ‘Bat wins’. Likewise check for all eight possible winning moves.
Our created subprogram’s parameters will store all of the possible winning triples so, when It receive message ‘check for winner’ it will check code for which combinations are valid.
What if game end with neither player has won?
i.e, when there are no more empty boxes but neither player has won, when that happens switch costume to tie.
To download the project files of the project How How to make Frogger Game on Scratch Click here. Also go through the another interesting scratch 3.0 project of Frogger Game on Scratch here.
Here's a step-by-step tutorial to create a platformer game similar to Super Mario in Scratch:…
Here's a step-by-step tutorial to create a Whack-a-Mole game in Scratch with code snippets: 1.…
About Game: In Spot The Difference Game, the player has to spot the difference between…
In this scratch tutorial, you will create a memory game in which you have to…
In this article, we are going to teach you how to program your owncustomized version…
About Duck Hunt Game: This is a remake of the classic video game Duck Hunt.…
This website uses cookies.
View Comments
i love my tic tac toe game! thanks for the tutorial
Hi; my kids and I want to know were you get the backdrops like the Santa or pumpkin one?
Mitch
I created the game template for you, so that kids can practice scratch games. Check it out here https://scratch.mit.edu/projects/548707875/
Thanks for visiting
Umm Is there a way to to stop re clicking the sprites