Coding for Kids: Create a Tic Tac Toe Game in Scratch

Coding for Kids- Create a Tic Tac Toe Game in Scratch
Photo: Unsplash.com

When you have paper, pen and free time, what games come to your mind? Tic, tac, toe? That’s right! Tic Tac Toe, also known as Noughts and Crosses, is a timeless game that has been beloved and played for centuries.

But what if you could give this classic game a unique twist? Imagine the excitement when your kids are not just playing Tic Tac Toe but creating their digital version! With Scratch Programming, they can do just that!

Scratch Programming

Scratch is a free online platform developed by MIT that lets young people create their games, animations, and stories. It’s designed to be fun and easy to use, making it an excellent way for kids to learn how to code.

Tic Tac Toe

Before diving into building the game, refresh the rules for this game. The objective is to be the first to get three of your marks in a row, either horizontally, vertically, or diagonally.

Well, your kid can keep the game fresh and add a fun spin to this game, like making a 4×4 grid or using swords and shields rather than tick and cross on the board. 

Now, dive right in!

Set Up the Project

Create a new project on Scratch and use the “Paint” tool to draw a 3×3 grid on the stage. You can use any background for the gameplay and use different colored lines to make the grid.

This will be the game board where players place their ✔️ and ❌ or any other sprite you want to use instead. 

The next thing you need to do is click on “Choose a Sprite” and select or draw sprites for X and O. These will be the markers used by the players. You can also upload a picture of yourself and use your face for gameplay!!!

Set Up Variable

What possible variables are needed in this game? Turn? Winner? Board? That’s right!!! Good job!

Go to the “Variables” category and create the following variables:

  • Turn (to keep track of whose turn it is)
  • Board (a list to store the state of each cell on the board)
  • Winner (to determine if there’s a winner)

Add Code Blocks

First, you must initialize the game board. This will ensure that you can restart a new game at any time!

Coding for Kids: Create a Tic Tac Toe Game in Scratch

Imagine you put a ✔️ in the middle of the grid. Is it allowed that your opponent also places their ❌ in the middle? Obviously not! Then how should you check your game?

You need to apply the following code block:

Coding for Kids: Create a Tic Tac Toe Game in Scratch

Great job! The last thing you need to do is decide the winning criteria.

Add a Winning Criteria

This step is very simple. You know that a person can only win if they have placed their marks either horizontally, vertically or diagonally. This is the only check you must put on your grid, too!

Coding for Kids: Create a Tic Tac Toe Game in Scratch

All that is left to do is announce the winner; you can do that by displaying a broadcast!

Just put together the following code block:

Coding for Kids: Create a Tic Tac Toe Game in Scratch

And that’s it, voila! Your kids just created a fun and easy game by themselves and are ready to share their new creations with family and friends!

Conclusion

Scratch is a powerful tool that allows you to unleash your creativity and learn the basics of coding in a fun and engaging way. Begin your journey in scratch programming with Codingal’s coding courses for kids, where you can unlock your full potential and learn something new at every step.

Keep experimenting, keep learning, and most importantly, have fun with your coding journey! Codingal is here to support you every step of the way. Happy coding!

Published by: Nelly Chavez

Share this article

(Ambassador)

This article features branded content from a third party. Opinions in this article do not reflect the opinions and beliefs of Voyage New York.