This is a solution to the Connect Four game challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the game rules
- Play a game of Connect Four against another human player (alternating turns on the same computer)
- View the optimal layout for the interface depending on their device's screen size
- See hover and focus states for all interactive elements on the page
- Bonus: See the discs animate into their position when a move is made
- Bonus: Play against the computer
- Solution URL: GitHub Repository
- Live Site URL: Live Demo
- Semantic HTML5 markup
- CSS custom properties
- CSS Modules
- CSS Grid
- Mobile-first workflow
- SolidJS - JS library
- Vite - Build tool
- TypeScript - For type safety
- SolidJS Router - Client-side routing
This project helped me explore SolidJS's reactive primitives and signals. I implemented a complete Connect Four game with:
- Game Logic: 6x7 board matrix with win detection for horizontal, vertical, and diagonal connections
- Turn Timer: 30-second countdown per turn with automatic forfeit
- Score Tracking: Persistent scores throughout multiple rounds
- Winning Animation: Visual highlighting of winning disc sequences
Key implementation highlights:
const checkWin = (board: Cell[][], row: number, col: number, player: number): boolean => {
// Check all four directions: horizontal, vertical, and both diagonals
// Returns true if 4 or more consecutive pieces are found
}// Timer management with SolidJS effects
createEffect(() => {
if (gameState() !== 'playing' || !isTimerActive()) return
const timer = setInterval(() => {
setTimeLeft(prev => {
if (prev <= 1) {
const otherPlayer = currentPlayer() === 1 ? 2 : 1
handleWin(otherPlayer)
return 30
}
return prev - 1
})
}, 1000)
return () => clearInterval(timer)
})Future enhancements to focus on:
- AI Opponent: Implement minimax algorithm for computer player
- Disc Animations: Add smooth drop animations when pieces are placed
- Sound Effects: Audio feedback for moves and wins
- Online Multiplayer: Real-time gameplay between remote players
- Accessibility: Enhanced keyboard navigation and screen reader support
- Frontend Mentor - @yourusername
- GitHub - @yourusername
