How to Make a Tic-Tac-Toe Game in Scratch – Easy Scratch Tutorial for Beginners

How to Make a Tic-Tac-Toe Game in Scratch - Easy Scratch Tutorial for Beginners

Introduction – Tic-Tac-Toe Game in Scratch

Hello everyone, welcome to Kodex Academy. Today, we are going to build the all-time favourite logic game in Scratch: Tic‐Tac‐Toe. In this game two players take turns making X and O on a 3×3 grid. The first one to get three in a row — across, down or diagonally — is the winner. But be careful: if you don’t think ahead, your opponent might block your move.

By the end of this tutorial you will have your very own interactive Tic-Tac-Toe game that you can play with your friends right inside Scratch.

Here’s the full YouTube video link: How to make Tic Tac Toe Game in Scratch | Easy Scratch Tutorial for Beginners ❌⭕ | Kodex Academy
Feel free to play it, follow along and then use this blog post as your written reference.

Why build Tic-Tac-Toe Game in Scratch?

  • Scratch is a drag-and-drop visual programming environment that is perfect for beginners and for learning game logic.
  • A Tic-Tac-Toe game covers many key ideas: sprites and costumes, variables, lists (or arrays), cloning or duplicates, detecting win-conditions, turn-taking logic, broadcasting messages, and more.
  • Once you build it, you can easily enhance it (see later) to multi-player, AI opponent, scoring, custom graphics, animations, sound effects, etc.

Overview – Tic-Tac-Toe Game in Scratch

We’ll build the game in the following major steps:

  1. Setup stage and backdrop
  2. Create the square sprite(s) for the 3×3 grid
  3. Create costumes for “empty”, “player1” (X or yellow‐cat face), “player2” (O or white cat face)
  4. Use cloning or duplicates to populate the 9 grid positions
  5. Create variables: player, counter, maybe number
  6. Use a list to record which cell is filled by which symbol (or number)
  7. Code the click logic: on sprite click → switch costume depending on player, change player variable, update list and counter.
  8. Code win-condition logic: check all 8 winning combinations (3 rows, 3 columns, 2 diagonals) for either symbol. If a symbol wins → broadcast message → backdrop switch / show result. Also detect draw when counter reaches 9.
  9. Add enhancements: sound effects, graphic effects, resetting, animations.

Step-by-Step Tutorial (with code blocks) – Tic-Tac-Toe Game in Scratch

Below we break down each step with code samples and explanations.

1. Setup the stage and backdrop

  • In Scratch choose a backdrop (for example “Stripes” as in the video).
  • On the green-flag event, set the backdrop and initialise the game. Example code in the Stage or a control sprite:
when green flag clicked
    switch backdrop to [Stripes v]
    broadcast [initGame v]
  • Optionally hide lists/variables you don’t want to see.

2. Create the grid sprite

  • Create one sprite (e.g. a square) which will act as a cell of the Tic-Tac-Toe board.
  • Go to its Costumes tab:
    • Costume 1: blank (say “Empty”) – a white square, light outline.
    • Costume 2: yellow cat face (representing X / player1) – perhaps paste the cat face and colour appropriately.
    • Costume 3: white cat face (representing O / player2) – adjust as per video transcript.
  • Rename the costumes: e.g. Empty, YellowCat, WhiteCat.

3. Populate 9 cells (via cloning or duplicates)

Option A – Using clones (recommended for cleaner code):

when I receive [initGame v]
    go to x: (-100) y: ( 100)   // top-left cell (adjust coordinates)
    set costume to [Empty v]
    show
    go to front
    repeat (2)  // create two additional in this row
        create clone of [myself v]
        change x by (100)     // adjust spacing
    end
    // then after row one, go to next row:
    create clone of [myself v]
    change y by (-100)
    set x to -100
    repeat (2)
        create clone of [myself v]
        change x by (100)
    end
    // repeat similarly for third row or use nested loops

Option B – Duplicate sprite manually 9 times (as done in the transcript):

  • After placing first cell, duplicate it twice for the row, then duplicate the row sprites twice and shift down for the other rows.

4. Variables and list

  • Create variable player (for all sprites).
  • Create variable counter (for all sprites) – counts how many cells have been filled.
  • Create list board (for all sprites) – will hold 9 items, each representing the state of a cell: e.g. “Y” for yellowcat, “W” for whitecat, or blank.
  • Create variable number (for sprite only) – to identify which cell (1-9) the clone represents.
when I receive [initGame v]
    delete all of [board v]
    set [counter v] to [0]
    set [player v] to [1]         // player1 starts
    set [number v] to ( … )      // assign number 1-9 per sprite
    add [ ] to [board v]         // add blank for each of the 9

5. On cell click logic

In the cell sprite:

when this sprite clicked
    if <(item (number) of [board v]) = [ ]> then   // only if empty
        if <(player) = [1]> then
            switch costume to [YellowCat v]
            replace item (number) of [board v] with [Y]
            set [player v] to [2]
        else
            switch costume to [WhiteCat v]
            replace item (number) of [board v] with [W]
            set [player v] to [1]
        end
        change [counter v] by (1)
        play sound [coin v] until done
        change color effect by (25)    // optional effect
        broadcast [checkWin v]
    end

6. Check win / draw logic

In a separate sprite (or the same sprite using when I receive [checkWin]):

when I receive [checkWin v]
    // define combinations as list of lists or coded manually
    // Example for player Y:
    if <((item (1) of board) = [Y] and (item (2) of board) = [Y] and (item (3) of board) = [Y]) or
        ((item (4) of board) = [Y] and … ) or
        …> then
        broadcast [YWin v]
    end
    // do same for player W:
    if <… (for W) …> then
        broadcast [WWin v]
    end
    // check draw
    if <(counter) = [9]> then
        broadcast [Draw v]
    end

Then handle the results:

when I receive [YWin v]
    wait (0.5) secs
    switch backdrop to [Y Wins v]
    play sound [connect v]
    stop [all v]

when I receive [WWin v]
    wait (0.5) secs
    switch backdrop to [W Wins v]
    play sound [connect v]
    stop [all v]

when I receive [Draw v]
    wait (0.5) secs
    switch backdrop to [Draw v]
    play sound [boing v]
    stop [all v]

7. Reset / start new game

On green flag:

when green flag clicked
    broadcast [initGame v]

And in initGame, include logic to hide or reset all clones/sprites, back to blank, reset variables/list etc.

Enhancement Features & Their Code

Here are some ways to enhance the basic game and make it more fun, interactive, and polished — along with code snippets.

a) Highlight winning line

Once a player wins, highlight the three cells of the winning line (e.g., change color, glow, animate).

// When Y wins (in checkWin), also store the winning indices, e.g. winCells = [1,2,3]
broadcast [highlight v]
when I receive [highlight v]
    if <(item (number) of [winCells v]) = [yes]> then
       repeat (10)
           change color effect by (25)
           wait (0.1) secs
       end
    end

You’ll need winCells list or variable to hold the indices of the winning line.

b) Two-player vs. Computer mode

Add the option to play against computer instead of two human players. Use lists or logic to compute computer move (e.g., random open cell).

when I receive [computerTurn v]
    wait (0.5) secs
    set [validMoves v] to [ ]       // list of open cells
    repeat (9)
        if <(item (n) of [board v]) = [ ]> then
            add (n) to [validMoves v]
        end
        change [n v] by (1)
    end
    set [choice v] to (pick random (1) to (length of validMoves))
    set [cellNumber v] to (item (choice) of validMoves)
    // broadcast a custom message like “move cell #cellNumber”
    broadcast [moveCell_(cellNumber) v]

Then in the cell sprite:

when I receive [moveCell_#]
    if <(number) = (#)> then
        // mimic click logic: switch costume, update board, etc.
    end

For a more advanced AI (minimax) you can refer to the instructables logic above.

c) Scoreboard & Rematch

Add variables scorePlayer1, scorePlayer2, scoreDraws. Update when a game ends. Add a “Play Again” button sprite to restart with green flag or its own custom message.

when I receive [YWin v]
    change [scorePlayer1 v] by (1)
    // show scoreboard update
    wait (2) secs
    broadcast [resetGame v]

when I receive [resetGame v]
    broadcast [initGame v]

d) Sound and Graphic Effects

  • On each cell click: play sound [coin v] until done
  • On win: play sound [connect v]
  • On draw: play sound [boing v]
  • On hover (optional):
when green flag clicked
    forever
        if <(mouse down?) and (touching [mySprite v])> then
            change size by (10)   // a quick zoom effect
            wait (0.1) secs
            change size by (-10)
        end
    end

e) Custom Symbols, Themes, Animations

  • Replace “X” and “O” (or yellow cat/white cat) with custom images (e.g., superheroes, animals) for each player.
  • Create animated costumes (e.g., when you switch to player symbol, add “pop” animation: costume changes quickly or scale up/scale down).
  • Use intro/backdrop transitions: e.g., start screen, title animation, then switch to board.

Game Play and Scenarios Covered

We have covered multiple scenarios:

  • Two-player local game in Scratch (player1 vs player2)
  • Game logic: winner detection + draw detection
  • User interface / visuals: customizing symbols (yellow cat / white cat), animations
  • Game enhancement: scoreboard, reset/rematch, sound/visual effects
  • Variant: Single-player vs computer (AI) mode
  • Theme variation: custom symbols, mobile layout, cloud variables (multiplayer) for advanced users
  • Educational scenario: teaching variables, lists, conditionals, branching logic in Scratch

Conclusion: Build, Play, and Learn with Scratch!

Creating a Tic-Tac-Toe game in Scratch is more than just a fun coding project — it’s an excellent way to learn core programming concepts like logic, loops, variables, lists, events, and conditions, all within a visual and beginner-friendly platform. By following this Scratch game tutorial, you’ve not only built a classic two-player logic game but also learned how to make your projects more engaging with animations, sound effects, and win detection logic.

With your completed Tic-Tac-Toe game, you can now:

  • Challenge your friends in a friendly two-player match 🎮
  • Experiment with new features such as AI opponents, scoring, or colorful themes 🎨
  • Use what you’ve learned to create your own games in Scratch, like Connect Four, Snake, or even your own story-based adventures 🚀

Remember, every great programmer started with a simple game — and today, you’ve built one yourself! Keep exploring, keep experimenting, and continue growing your coding creativity with Scratch programming games.

Call to Action

  1. Don’t forget to check out the full video tutorial: How to make Tic Tac Toe Game in scratch | Easy Scratch Tutorial for Beginners ❌⭕ | Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links

Recent Posts

How to Make a Health Bar Animation in Scratch | Healthy vs Junk Food Game Tutorial (Full Step-by-Step Guide)

How to Make a Health Bar in Scratch | Healthy vs Junk Food Game | Scratch Animation | Kodex Academy Creating fun and engaging games in Scratch not only helps kids learn coding, but also encourages...

How to Make a Basketball Game in Scratch | Full Tutorial (Moving Hoop + Jumping Ball + Score)

Are you ready to create an exciting basketball game in Scratch with a moving hoop, jumping player, and real-time scoring? This step-by-step Scratch game tutorial is perfect for beginners who want to...

How to Make 3D Shapes in Scratch – Draw Cubes, Pyramids & Cylinders Using Pen Extension

If you’ve ever wondered how to make 3D shapes in Scratch or create 3D geometry using code, you’re about to dive into a creative world of math, animation, and programming fun. Learn how to make...

How to Make Flappy Bird Game in Scratch | Coin Collection Game in Scratch | Scratch Coding for Beginners

Have you ever wondered how people create fun games like Flappy Bird without writing a single line of code? With Scratch programming, anyone — from complete beginners to young creators — can build...

How to Make Day & Night Animation in Scratch (Step-By-Step Full Tutorial)

If you’ve ever wondered how to make day and night animation in Scratch or wanted to bring your stories and games to life with realistic sky transitions, this tutorial is perfect for you! Scratch is...

How to Make a Shooting Game in Scratch | Jet Shooting Game Tutorial (Step-By-Step Guide)

Introduction - Jet Shooting Game in Scratch Scratch Tutorial Game | Scratch Game Tutorial Easy | Scratch Programming Games | Jet Shooting Game in Scratch Want to build your first arcade-style...

Top 5 Animations in Scratch | How to Make Your Animations Smooth in Scratch

In this step-by-step guide, we explore the Top 5 animations in Scratch games that will make your projects smoother, interactive, and fun to play. You’ll learn: ✅ How to make a sprite jump ✅ How to...

How to Make a Tic-Tac-Toe Game in Scratch – Easy Scratch Tutorial for Beginners

We are going to build the all-time favourite logic game in Scratch: Tic‐Tac‐Toe. In this game two players take turns making X and O on a 3×3 grid. The first one to get three in a row — across, down or...

How to Make a Real-Time Wall Clock in Scratch | Step-by-Step Scratch Tutorial

If you’ve ever wondered how to make a real-time wall clock in Scratch, you’re in the right place! In this step-by-step Scratch tutorial, we’ll show you how to build a fully functional analog clock...

How to Make a 3-Level Platformer Game in Scratch | Mario-Style Hen Adventure Game

Have you ever wanted to build your own Mario-style platformer game in Scratch? This step-by-step guide will walk you through how to make a 3-level platformer game in Scratch — featuring a jumping hen...

How to Make a Math Racing Game in Scratch | Game Concepts and Complete Tutorial

In this tutorial, you’ll learn to build a Math Racing Game in Scratch. Players solve math problems to move their character forward; wrong answers benefit the opponent. It’s a race of speed, accuracy...

How to make Memory Skill Game in Scratch | Card Matching Game in Scratch – Part 2 | Step-by-Step Coding

In this tutorial you'll learn how to make memory skill game in Scratch / card matching game in Scratch. This is a great beginner‑to‑intermediate project for scratch tutorial game, scratch programming...

How to make a Card Matching Game in Scratch | Memory Skill Game in Scratch – Part 1 | Step-by-Step Coding

In this Scratch tutorial, we'll walk you through how to make a card matching game in Scratch, also known as a memory game or skill game. This is a popular beginner project that introduces essential...

Create a Quiz Game in Scratch | Spelling Test in Scratch | Picture Identification in Scratch

Want to make learning spelling fun, visual, and interactive? In this Scratch tutorial, you'll learn how to make a spelling quiz game in Scratch using picture identification, text-to-speech, and...

How to make a Double Jump Game in Scratch | Platformer game in Scratch | Step by Step Coding

How to make a Double Jump Game in Scratch. Scratch is a fantastic platform for beginners to learn programming by making games, animations, and interactive stories. Among the many kinds of games...

How to Use Variables in Scratch | Variable Blocks in Scratch | Complete Tutorial

Introduction: Variable Blocks in Scratch Whether you’re just getting started with Scratch programming or looking to take your projects to the next level, understanding variables and lists is...

How to Make Earth Revolve Around the Sun in Scratch: A Complete Tutorial & Enhancements

Animating Earth revolving around the Sun is a classic beginner/intermediate Scratch animation project. It combines trigonometry (sine & cosine), variables, loops, and visual scripting. Kids can learn...

How to Make a Game in Scratch | Snake Game in Scratch | Step-by-Step Game Coding

In this tutorial, we’ll build a Snake Grid style game in Scratch step by step (very similar to the Kodex Academy example). By doing this, you’ll cover many of the core Scratch building blocks. We will...
Scroll to Top