Tic Tac Toe
What it is
An online tic-tac-toe game. You log in with a nickname, see who else is in the lobby (players already in a game are marked), pick an opponent and play. The one who picks plays X and starts. When the game ends, both players can press Play Again for a rematch or go back to the lobby, and the other player is told either way.
You can play it in the browser, against the same server the Windows clients use.
How it's built
A C++ client with SFML and SFGUI, and a C++ server, both talking ENet (reliable UDP) through the packet layer of kazilib, my own C++ library.
- The server decides: clients only send the cell they clicked. The server keeps the board, checks the eight winning lines, detects a draw and sends the result to both players.
- A tiny protocol: every packet starts with a one-byte message id (log in, player list, select player, position, winner, play again, opponent left and so on), and new ids are only appended so older clients keep working.
- The same client in a browser: compiled to WebAssembly with Emscripten. SFML's window runs on SDL3, its old OpenGL drawing is emulated on WebGL2, and SFGUI's renderer runs on WebGL2.
- ENet over a WebSocket: the web client keeps its ENet code; a small layer carries it over one WebSocket. The server has a gateway thread that hands each browser to the game as an ordinary ENet peer, so one server process serves native and web players together.
- Tests: a headless protocol test plays two clients through a whole session, and scripted tests drive the real windows, press buttons and take screenshots. A browser test plays two tabs against the live page.
Why I made it
The web version started as an experiment: make the game work in a browser entirely within tictactoe, porting SFML, SFGUI and ENet as needed, and then decide from the result whether to use the same approach in my other C++ projects.
Timeline
I wrote the game by hand in June 2016; in 2026 I moved it onto SFML 3.1 and kazilib and, with AI help, built the web client, the Linux server and the deployment.
Technologies
- C++
- SFML
- WebAssembly
- ENet
- WebSocket