Mastermind PWA

A modern, mobile-first implementation of the classic Mastermind board game as a Progressive Web App. Play anywhere, anytime - even offline!

๐ฎ Features
- Progressive Web App: Install on any device and play offline
- Mobile-First Design: Optimized for touch interactions and mobile screens
- Accessibility: Color-blind friendly mode with patterns and symbols
- Customizable Difficulty: Choose from 6, 7, or 8 colors
- Responsive Design: Adapts to any screen size and orientation
- Game Statistics: Track your performance over time
- Modern UI: Clean, intuitive interface with smooth animations
๐ Tech Stack
- Framework: SvelteKit 2.x
- UI: Svelte 5.x
- Build Tool: Vite
- Testing: Vitest
- TypeScript: For type safety and better developer experience
- PWA: Service worker for offline functionality and caching
- CSS: Custom CSS with responsive design principles
๐๏ธ Architecture
Project Structure
src/
โโโ lib/
โ โโโ components/ # UI components
โ โโโ stores/ # Svelte stores for state management
โ โโโ styles/ # Global styles and animations
โ โโโ types/ # TypeScript type definitions
โ โโโ utils/ # Game logic and utility functions
โโโ routes/ # SvelteKit routes
โ โโโ +layout.svelte # Main layout
โ โโโ +page.svelte # Game page
โ โโโ settings/ # Settings page
โโโ app.html # HTML template
Core Components
- GameBoard: Main game container managing overall game state
- GuessRow: Individual row for player guesses
- ColorPicker: Touch-friendly color selection interface
- FeedbackPegs: Displays black/white peg feedback
- GameControls: Game control buttons and status display
- HelpModal: Instructions and game rules
State Management
The game uses Svelte stores for state management:
- gameStore: Main store for game state
- gameStatus: Current game status (playing, won, lost)
- currentGuess: Current guess being built
- secretCode: The secret code to guess
- availableColors: Colors available based on difficulty
๐ ๏ธ Getting Started
Prerequisites
- Node.js 18.x or higher
- npm 9.x or higher
Installation
Clone the repository:
git clone https://github.com/yourusername/mastermind-pwa.git
cd mastermind-pwa
Install dependencies:
npm install
Start the development server:
npm run dev
Open your browser and navigate to:
http://localhost:5173
Building for Production
npm run build
The built application will be in the build
directory.
Preview Production Build
npm run preview
Deployment to GitHub Pages
This project is configured for automatic deployment to GitHub Pages using GitHub Actions:
- Push your changes to the
main
branch
- GitHub Actions will automatically build and deploy the app
- Your app will be available at
https://yourusername.github.io/mastermind-pwa
You can also manually trigger a deployment from the Actions tab in your GitHub repository.
๐งช Testing
Run the test suite:
npm test
Run tests in watch mode:
npm run test:watch
๐ฑ PWA Features
Offline Support
The app works fully offline once loaded, using a service worker to cache assets and game state.
Installation
Users can install the app on their devices:
- Mobile: Use "Add to Home Screen" from the browser menu
- Desktop: Click the install icon in the address bar
Updates
The app checks for updates when online and notifies users when a new version is available.
๐จ Game Rules
- The computer generates a secret code of 4 colors.
- You have 10 attempts to guess the code.
- After each guess, you receive feedback:
- Black peg: Correct color in the correct position
- White peg: Correct color but in the wrong position
- Use logic and deduction to solve the code before running out of attempts!
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add some amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
Development Guidelines
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PRs
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Original Mastermind board game by Mordecai Meirowitz
- SvelteKit team for the amazing framework
- All contributors and open source projects that made this possible
Project Link: https://github.com/yourusername/mastermind-pwa
Made with โค๏ธ and Svelte