A classic Tic-Tac-Toe game built with React, featuring an interactive game board, move history, and time travel functionality. This project demonstrates fundamental React concepts including components, state management, and event handling.
- About
- Features
- Demo
- Installation
- Usage
- Game Rules
- Project Structure
- Technologies Used
- Learning Objectives
- Available Scripts
- Contributing
- License
- Acknowledgments
This Tic-Tac-Toe game is based on the official React Tutorial and serves as an excellent introduction to React development. The game implements a complete interactive experience with move history and the ability to jump back to previous game states.
- Interactive Game Board: Click on squares to make your move
- Player Turn Indicator: Shows whose turn it is (X or O)
- Winner Detection: Automatically detects and announces the winner
- Move History: Complete history of all moves made during the game
- Time Travel: Jump back to any previous move in the game
- Game Reset: Start a new game at any time
- Responsive Design: Works on desktop and mobile devices
The game provides:
- A 3x3 grid where players take turns placing X's and O's
- Real-time game status updates
- A list of moves that allows players to review and jump to any point in the game
- Automatic winner detection with all possible winning combinations
- Node.js (version 14.0 or higher)
- npm (comes with Node.js)
-
Clone the repository
git clone https://github.com/AnderssonProgramming/tic-tac-toe.git cd tic-tac-toe
-
Install dependencies
npm install
-
Start the development server
npm start
-
Open your browser Navigate to http://localhost:3000 to play the game.
- Starting a Game: The game starts automatically with X going first
- Making Moves: Click on any empty square to place your mark
- Viewing History: Use the move list on the right to see all previous moves
- Time Travel: Click on any move in the history to jump back to that point
- Winning: The game will announce the winner when three marks align
- New Game: Click "Go to game start" to begin a fresh game
- The game is played on a 3×3 grid
- Players take turns, with X going first
- Players place their mark (X or O) in empty squares
- The first player to get 3 marks in a row (horizontally, vertically, or diagonally) wins
- If all 9 squares are filled and no player has 3 in a row, the game is a draw
tic-tac-toe/
├── public/
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
├── src/
│ ├── App.css
│ ├── App.js # Main game components
│ ├── App.test.js
│ ├── index.css
│ ├── index.js # Entry point
│ ├── logo.svg
│ ├── reportWebVitals.js
│ ├── setupTests.js
│ └── styles.css # Game-specific styles
├── package.json
├── README.md
└── LICENSE
Game
: The main component that manages game state and historyBoard
: Renders the 3x3 game board and handles move logicSquare
: Individual clickable squares on the board
- React 19.1.0: Frontend framework
- React DOM 19.1.0: DOM rendering
- React Scripts 5.0.1: Build tools and development server
- CSS3: Styling and layout
- HTML5: Structure and semantics
- @testing-library/react: Testing utilities
- @testing-library/jest-dom: Custom Jest matchers
- @testing-library/user-event: User interaction simulation
- web-vitals: Performance monitoring
This project demonstrates key React concepts:
- Components: Functional components with props
- State Management: Using
useState
hook - Event Handling: onClick events and user interactions
- Conditional Rendering: Dynamic UI updates based on game state
- Lists and Keys: Rendering move history with proper keys
- Immutability: Creating new arrays/objects instead of mutating existing ones
- Lifting State Up: Sharing state between components
In the project directory, you can run:
Runs the app in development mode.
Open http://localhost:3000 to view it in your browser.
The page will reload when you make changes.
Launches the test runner in interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
Note: this is a one-way operation. Once you eject
, you can't go back!
If you aren't satisfied with the build tool and configuration choices, you can eject
at any time.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- React Team: For the excellent React Tutorial that this project is based on
- Create React App: For providing the initial project setup and build tools
- React Community: For the comprehensive documentation and learning resources
- React Documentation
- React Tutorial - Tic-Tac-Toe
- Create React App Documentation
- React Hooks Documentation
Built with ❤️ using React