Explore Upcoming Workshops Near You and Ignite Your Passion for Innovation. Reserve a Seat today!

Making A Tic-Tac-Toe Game In Scratch
Build a future with Moonpreneur
DEVELOP TECHNICAL, SOFT, &
ENTREPRENEURIAL SKILLS
AGE 7-15 YEARS
CLAIM YOUR $10 ROBLOX/AMAZON/MINECRAFT GIFT
CARD BY ATTENDING A FREE TRIAL CLASS
BOOK A FREE ROBOTICS TRIAL
Select Your Subject of Choice

    Please enter name

    Please enter email


    Existing knowledge in programming/robotics

    *No credit card required.

    Making a Tic-Tac-Toe Game in Scratch

    |

    Update: This article was last updated on 5th March 2025 to reflect the accuracy and up-to-date information on the page.

    Create Tic Tac Toe in Scratch

    “Ever thought about how awesome it would be to create your own Tic-Tac-Toe game? Just imagine playing a game that you programmed yourself! In this tutorial, we’ll walk you through the process of creating an interactive Tic-Tac-Toe game in Scratch—step by step!”

    Hello and welcome to this tutorial on how to make a Tic-Tac-Toe game in Scratch. Tic-Tac-Toe is a fun game we’ve all played before, and in this video, we’ll be creating a version of it using Scratch. Scratch is a visual programming language that makes it easy for anyone to create interactive projects, games, and animations.

    Before we begin, let us tell you that if your child wants to do block coding, Moonpreneur is providing pre-robotics free classes for kids aged 6-8. But you must hurry because the offer is temporary! So avail of a free trial class for your kid ASAP.

    1. We must set the scene for our Tic-Tac-Toe game

    Create Grid

    To do this, we’ll need to create a 3×3 grid using sprites. We’ll use one sprite for each cell of the grid. First, we’ll create a new sprite named “grid.” Then, we’ll use a different color for the lines to stand out from the background.

    2. Create Sprites (X-O)

    Now that we have our grid established, we will create sprites for O and X. We will create two sprites that are different for X and O. We also need to add a variable for tracking whose turn it is.

    We must render the grid. To achieve this, we must make clones, so we will make a variable named clone number and assign it a value of zero. We will then do this nine times and increment the clone number by one each time until we have made nine clones. We will also make another variable named clone ID that will assist us in assigning the X and Y positions to each clone.

    Create Sprite X
    Create Sprite O

    3. Make a variable named “clone ID”

    Clone Id

    We now make a variable named clone ID and assign it the clone number. This way, every clone will have a different clone ID. We will assign the X and Y positions of every clone through two lists named X and Y.”

    We will then conceal these lists and place them in the X and Y positions of every clone by utilizing the clone ID. This will place every clone in its corresponding position.

    So, if you’re facing any problems coding for the Tic-Tac-Toe game, don’t hesitate to sign up for Moonpreneur’s Pre-robotics trial classes today. With their help, you can become a coding master and create your games.

    Clone Id

    4. Add some Interactivity

    Interactivity

    Now that we have our game board established, it‘s time to add some interactivity. We’ll begin by making an event that happens when the player clicks on a cell in the grid. We’ll use the when sprite clicked” block for this.

    When the player clicks on a cell, we’ll check if it’s empty. If it is, we’ll place an X or O in the cell, depending on whose turn it is. We’ll also need to update the turn variable.

    After we have the overall interactivity in place, we will need to add some logic to determine a winner. We will look at whether any row, column, or diagonal has three X or O in sequence. If there is a winner, we will show a message and stop the game.

    5. Add Some Sound Effects

    Sound Effect

    Now that our game is working, it’s time to add some finishing touches. We’ll start by adding some sound effects to make the game more fun. We’ll use Scratch’s built-in sound library to add sound effects for when the player clicks on a cell when a move is made, and when the game is won.

    6. Add Graphics

    Next, we’ll add some graphics to indicate whose turn it is. We’ll use a sprite to display an X or O, depending on whose turn it is. We’ll also add a message to indicate which player won the game.

    Lastly, well insert some code to restart the game when its finished. Well make a button that the player can press in order to restart the game, and then well set all of the variables and sprites back to their starting values.

    And there you have it! With a working Tic-Tac-Toe game created in Scratch, we hope this tutorial was informative and you learned something new.

    Why Learn to create Tic Tac Toe in Scratch?

    Developing a Tic-Tac-Toe game in Scratch is not only a cool project—its an excellent way for children to learn important skills in programming and problem-solving. Here’s why doing this game is good for young programmers:

    Critical  Thinking – What it takes to learn how to create Tic Tac Toe in Scratch is organizing the game logic effectively, i.e., turn management and winner check.

    Problem-Solving – Fixing bugs, e.g., invalid moves or missing winning states, encourages children to think logically.

    Creativity – With Scratch, children get to create their own board, X and O graphics, and animations, so their game stands ou

    Simple AI Concepts – If they wish to take it a step ahead, children can include a simple AI opponent, exposing them to simple artificial intelligence and decision-making logic.

    Through the process of creating Tic Tac Toe in Scratch, children develop confidence in their coding skills while enjoying themselves. So why not challenge your child to create their own version today?

    Conclusion

    Scratch is a great tool for anyone who wants to learn how to program, and making games is a fun way to practice your skills. So if you’re excited to take on the world of Scratch coding, join Moonpreneur’s Free Pre-Robotics Trial class to build more exciting games!

    Moonpreneur aims to revolutionize conventional education and future-proof the future generation through comprehensive learning solutions. Its Innovator Program is creating tomorrows workforce by empowering students with training in AI/ML, Robotics, Coding, IoT, and Apps, and facilitating entrepreneurship through experiential learning.

    Moonpreneur

    Moonpreneur

    Moonpreneur is an ed-tech company that imparts tech entrepreneurship to children aged 7 to 16. Its flagship offering, the Innovator Program, offers students a holistic learning experience that blends Technical Skills, Power Skills, and Entrepreneurial Skills with streams such as Robotics, Game Development, App Development, Advanced Math, and Book Writing & Publishing.
    Subscribe
    Notify of
    guest


    4 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    Richa
    Richa
    1 year ago

    On which other platforms can we create tic-tac-toe?

    Simran Chawla
    Editor
    1 year ago
    Reply to  Richa

    You can create tic-tac-toe on React as well, although it requires complex coding and is not as simple as scratch.

    Jane
    Jane
    1 year ago

    How do I add sound and animation effects in scratch???

    Simran Chawla
    Editor
    1 year ago
    Reply to  Jane

    To add sound and animation effects in Scratch, use “play sound” blocks for audio and incorporate motion and look blocks for animation in your code.

    RELATED ARTICLES

    YOU MAY ALSO LIKE

    Explore by Category

    MOST POPULAR

    GIVE A GIFT OF $10
    MINECRAFT GIFT
    TO YOUR CHILD

    JOIN A FREE TRIAL CLASS

    FREE EBOOK AND STORYBOOK

    Download "Treasure Hunt" - A Robotics Workbook for Kids (8-15 YEARS)
    Download Now

    Robotics Ebook And 3-Part Video Series

    Download Now