Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Build an Online Dots Boxes Game Like a Pro using socket io
New

Build an Online Dots Boxes Game Like a Pro using socket io

Build Dots and Boxes from scratch: game logic, a computer opponent, and real-time play over WebSockets
Created byAmir shahbabaee
Last updated 9/2026
English

What you'll learn

  • Build a complete Dots and Boxes game in React and TypeScript, from an empty folder to two browsers playing over a network
  • Model a game's domain with TypeScript unions, template literal types and narrowing, so that illegal states fail to compile
  • Decide what belongs in state and what should be derived, and understand why storing the same fact twice creates bugs
  • Lift state out of a component and turn it into one that is told what to show and reports events upward
  • Write your game rules as pure functions with no React, then run that exact same code in the browser and on a Node server
  • Build a computer opponent in stages: random moves, taking free boxes, avoiding moves that give boxes away, then difficulty levels
  • Use useEffect correctly for timers and WebSockets, including cleanup and why React StrictMode runs your effects twice
  • Build a WebSocket server with rooms, shareable join codes, and an authoritative game state that no browser can fake
  • Handle the real problems of multiplayer: disconnects, held seats, reconnect tokens and a game that survives a refresh
  • Send Set and Map safely over JSON, and see why sending them raw silently loses your entire game state
  • Refactor a 440-line component into focused pieces, and recognise the signals that a file has outgrown itself
  • Lay out a game board with one CSS grid and Tailwind v4 design tokens, with no positioning maths anywhere

Course content

4 sections • 47 lectures • 7h 40m total length
  • 01 - Applications2:59

    NodeJS website: https://.nodejs.org

    Visual Studio Code website: https://code.visualstudio.com

  • 02 - VSCode Extensions2:19

    ESLint:

    https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint


    Prettier - Code formatter:

    https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode


    Tailwind CSS IntelliSense:

    https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss

  • 03 - Init project and setup package.json10:38
  • 04 - Typescript config10:43
  • 05 - Vite config4:18

Requirements

  • Basic knowledge of HTML, CSS, and JavaScript, React
  • A code editor such as Visual Studio Code
  • Node.js installed on your computer
  • No prior game development or Socket IO experience is required

Description

Most React courses stop at a to-do list. This one doesn't.

You'll build Dots and Boxes — the pen-and-paper game where you join dots, close squares, and take another turn when you do — from an empty folder to a finished app where two people play each other in two browsers over a real server.

No boilerplate you don't understand, no cloning a starter repo. Every file is one you wrote and can explain.

We build it in three parts.

Part 1 — the game. You'll draw the board as a single CSS grid (no positioning maths anywhere), model lines and boxes as TypeScript types, and implement the rules — including the one that makes Dots and Boxes a real game: close a box and you go again. By the end you have a complete two-player game with scores, a winner, and a draw case that most implementations get wrong.

Part 2 — the computer. You'll build an opponent in stages, and each stage is measurable. First one that moves at random. Then one that takes any box it can reach — which beats random 1000 games to 0. Then one that stops handing you boxes, which beats that one 9 times out of 10. Those three become your Easy, Medium and Hard, and you'll see exactly why each is stronger than the last.

Part 3 — two browsers, one game. You'll write a WebSocket server in TypeScript with rooms and shareable four-letter join codes, move the game state onto it so neither player can cheat, and sync moves in real time. Then the hard parts nobody shows you: what happens when someone refreshes, why Set and Map silently vanish when you send them as JSON, and how to hold a player's seat and let them prove it's theirs when they come back.

What makes this course different

Every decision gets a reason. When we name a line after the dot it starts at, you'll see three lessons later why that turns box detection into four lookups. When we pull the rules out of the component, you'll see in Part 3 why that's the only reason the browser and the server can't disagree.

You'll also see the mistakes. Bugs get made on camera and fixed — a colour with no contrast, an effect that fires twice, a state object that arrives empty. Watching something break and then understanding why teaches more than watching it work first time.

The steps are short and each one ends with something you can run.

What you need

Comfortable with JavaScript, and you've seen a React component before. You don't need to know TypeScript — we introduce it where it earns its place — and you don't need any backend or WebSocket experience.

What you finish with

A game you can send to a friend and actually play, and a much clearer sense of where state belongs, what to derive rather than store, and how a front end and a server share one source of truth.


Who this course is for:

  • React developers who want to build a complete real-world game project.
  • Beginners looking to gain hands-on experience with game development
  • Web developers interested in learning real-time multiplayer using Node.js and Socket IO
  • Anyone who enjoys coding and wants to create their own online multiplayer games from scratch.