This project is a web-based implementation of the classic Tic Tac Toe game built by Adedara Adeloro using FastHTML, HTMX, and Tailwind CSS.
The build steps from the original project were simplifed to use CDNs for the FastHTML Gallery version. To check out the original project, click here
cls="grid grid-cols-3 grid-rows-3
creates a 3x3 grid for the Tic Tac Toe board. The app uses FastHTML to define routes and handle game logic on the server. Key routes include:
/
: The main page that renders the initial game board./on_click
: Handles player moves and updates the game state./restart
: Resets the game board.The game state is managed server-side using global variables:
button_states
: A 2D array storing snapshots of the board.current_state_index
: Tracks the current state of the game.winner_found_game_ended
: A flag to indicate if the game has ended.HTMX is used extensively to create a dynamic user interface
hx-get
attributes on buttons trigger GET server requests on click.hx-target
specifies where the response from the server should be put.hx-swap
determines how the new content should replace the old content. In this app outerHTML
is used to replace the entire element.