A template repository for creating daily browser games like Wordle, Connections, or similar puzzle games. Features automatic deployment, state persistence, daily streaks, and responsive design.
Play the Live Demo of Four Nines, a daily puzzle game created from this template
- ๐ฎ Perfect for daily puzzle games
- ๐ Built-in dark/light theme
- ๐ Daily streak tracking
- ๐ Automatic state persistence
- ๐ฑ Mobile-first responsive design
- ๐ One-click GitHub Pages deployment
- ๐ Google Analytics 4 support
- ๐จ Clean, modern UI with Bootstrap
- ๐ Social sharing with result grids
- ๐ Stats comparison system
- Click "Use this template" to create your repository
- Enable GitHub Pages:
- Go to repository Settings > Pages
- Under "Build and deployment", select "GitHub Actions" as the source
- Configure analytics and sharing:
- Copy
.env.example
to.env
- Add your Google Analytics 4 ID
- Add your game preview image at
/public/game-preview.png
- Copy
- Your game will be live at
https://yourusername.github.io/your-repo-name
Look for TODO
comments in these files:
-
src/pages/Play.tsx
- Replace placeholder with your game logic
- Customize completion state display
-
src/pages/Home.tsx
- Update game title and introduction
- Customize welcome message
-
src/types/GameState.ts
- Add game-specific state properties
- Add game-specific settings
-
public/game-icon.svg
- Replace with your game icon
-
src/styles/global.css
- Customize colors and theme
- Add game-specific styles
-
src/components/InfoModal.tsx
- Update game instructions
- Add game features list
const { gameState, updateGameState } = useGameState();
// Update game state
updateGameState({
score: newScore,
todayCompleted: true,
});
- Automatically generates puzzle number from date
- Tracks completion status
- Prevents replaying completed puzzles
- Shows stats after completion
const { theme, toggleTheme } = useTheme();
// Share results with native share API or clipboard fallback
const shareText = generateShareText({
title: 'My Game',
dayNumber: puzzleNumber,
streak: 5,
stats: gameStats
});
await shareResults(shareText);
- Games played
- Win rate
- Current streak
- Best streak
- Daily completion status
-
Set up Google Analytics:
# .env VITE_GA_ID=G-XXXXXXXXXX
-
Track custom events:
gtag('event', 'puzzle_complete', { puzzle_number: puzzleNumber, streak: streak });
- Open Graph meta tags for rich previews
- Twitter card support
- Customizable share images
- Automatic puzzle numbering
All game state is automatically saved to localStorage. Common state properties:
todayCompleted
: Whether today's puzzle is completedstreak
: Daily visit streaklastPlayed
: Last played timestampgamesPlayed
: Total games completedwinRate
: Player's win rate
- Daily Puzzles
const getTodaysPuzzle = () => {
const today = new Date();
const puzzleIndex = Math.floor(today.getTime() / (24 * 60 * 60 * 1000));
return puzzles[puzzleIndex % puzzles.length];
};
- Progress Saving
updateGameState({
todayCompleted: true,
gamesPlayed: gamesPlayed + 1,
winRate: calculateWinRate(),
});
- Statistics
updateGameState({
gamesPlayed: gameState.gamesPlayed + 1,
winRate: (gamesPlayed - 1) / gamesPlayed,
maxStreak: Math.max(maxStreak, streak),
});
- Daily Reset
const isNewDay = () => {
const lastPlayed = new Date(gameState.lastPlayed);
const now = new Date();
return !isSameDay(lastPlayed, now);
};
- Share Results
const handleShare = async () => {
const text = generateShareText({
title: 'Game Title',
dayNumber: puzzleNumber,
streak,
stats: gameStats
});
await shareResults(text);
};
- GitHub Pages 404: Make sure GitHub Pages is enabled and set to deploy from GitHub Actions
- State Reset: The reset functionality clears ALL game progress
- Mobile Testing: Test touch interactions thoroughly
- Analytics Not Working: Verify your GA4 ID in
.env
file - Share Not Working: Some browsers restrict clipboard access to HTTPS
MIT License - feel free to use this template for any purpose.