How to make Tic Tac Toe Game on Scratch [Easiest Version For Kids]

About Tic Tac Toe Game:

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.

Video Tutorial on How to make Tic Tac Toe Game on scratch

In this lesson, we will create Halloween version of Tic Tac toe with Pumpkins and Bats.

Lets sketch out the Tic Tac Toe Game:

  • Creating Tic Tac Toe Board
  • Keep Track of Moves:
  • Checking for a winning line
  • Checking for Ties

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

Tic Tac Toe Scratch Game Code:

Tic Tac Toe scratch game

Creating Tic Tac Toe Board

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.

Keep Track of Moves:

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

Checking For The Winner:

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.

Checking for Ties

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.

Download Tic Tac Toe Game on Scratch Project Files:

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.

scrat

View Comments

Recent Posts

Create Your Own Super Mario Game in Scratch (Easy Step-by-Step)

Here's a step-by-step tutorial to create a platformer game similar to Super Mario in Scratch:…

6 hours ago

Create a Fun Whack-a-Mole Game in Scratch: Step-by-Step Tutorial

Here's a step-by-step tutorial to create a Whack-a-Mole game in Scratch with code snippets: 1.…

7 hours ago

Spot The Difference Game in Scratch

About Game: In Spot The Difference Game, the player has to spot the difference between…

3 years ago

Memory game using Scratch| Step by step Scratch Tutorial

In this scratch tutorial, you will create a memory game in which you have to…

3 years ago

How to make Flappy Bird on Scratch | Coding For Kids

In this article, we are going to teach you how to program your owncustomized version…

3 years ago

How to make Shooting Game on Scratch (Duck Hunt Game)

About Duck Hunt Game: This is a remake of the classic video game Duck Hunt.…

3 years ago

This website uses cookies.