TicTacToe Game
Interactive TicTacToe game with modern UI — React, CSS
Problem
Create an engaging, interactive TicTacToe game that demonstrates React fundamentals while providing a smooth, modern user experience. The game needed to be responsive, accessible, and visually appealing with clear game state management.
Approach
- Built with React functional components and hooks for state management
- Implemented game logic with clean, maintainable code structure
- Designed responsive UI with modern CSS styling and animations
- Added accessibility features for inclusive gameplay
- Created intuitive game flow with clear visual feedback
Solution
Developed a fully functional TicTacToe game with React that features turn-based gameplay, win detection, game reset functionality, and a clean, modern interface. The game includes visual indicators for current player, game status, and smooth transitions between game states.
Technical Stack
React, CSS3, JavaScript ES6+, HTML5, Git version control
Key Features
- Turn-based gameplay with X and O players
- Automatic win detection for rows, columns, and diagonals
- Draw detection when no winner is possible
- Game reset functionality to start new games
- Responsive design that works on all screen sizes
- Visual feedback for current player and game status
- Accessible keyboard navigation and screen reader support
Code Snippet
// Game state management with React hooks
const [board, setBoard] = useState(Array(9).fill(null));
const [xIsNext, setXIsNext] = useState(true);
const handleClick = (i) => {
if (calculateWinner(board) || board[i]) {
return;
}
const newBoard = board.slice();
newBoard[i] = xIsNext ? 'X' : 'O';
setBoard(newBoard);
setXIsNext(!xIsNext);
};
const calculateWinner = (squares) => {
const lines = [
[0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
[0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
[0, 4, 8], [2, 4, 6] // diagonals
];
for (let i = 0; i < lines.length; i++) {
const [a, b, c] = lines[i];
if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
return squares[a];
}
}
return null;
};
Development Process
- Started with basic React component structure and game board layout
- Implemented core game logic with state management using useState hook
- Added win detection algorithm for all possible winning combinations
- Styled the game board and pieces with modern CSS
- Enhanced user experience with visual feedback and animations
- Tested responsiveness across different screen sizes
- Optimized code for performance and maintainability
Results
- Successfully created a fully functional TicTacToe game
- Demonstrated React fundamentals and best practices
- Achieved responsive design that works on mobile and desktop
- Implemented clean, readable code structure
- Created an engaging user experience with smooth interactions
- Built a solid foundation for future React projects
Learning Outcomes
- Gained hands-on experience with React hooks and state management
- Learned to structure React components for maintainability
- Practiced responsive CSS design principles
- Understood game logic implementation in JavaScript
- Developed skills in creating interactive user interfaces