Skip to content

Repository files navigation

🧩 Zip Puzzle Game

A modern, web-based puzzle game inspired by LinkedIn's Zip puzzle. Connect numbered dots in sequence by drawing a continuous path that fills the entire grid.

🔗 GitHub Repository: https://github.com/k4l397/zip-puzzle-game 🎮 Play Online: https://k4l397.github.io/zip-puzzle-game/

Game Screenshot

🎮 How to Play

  1. Start the Game: Click "Start Playing" to generate a new puzzle
  2. Connect the Dots: Begin by clicking on dot number 1
  3. Draw Your Path: Drag to create a continuous line through the grid
  4. Follow the Sequence: Connect dots in numerical order (1 → 2 → 3...)
  5. Fill the Grid: Your path must pass through every cell exactly once
  6. Complete the Puzzle: Connect all dots and fill the entire grid to win!

Game Rules

  • ✅ Path must be continuous (no gaps)
  • ✅ Connect dots in ascending numerical order
  • ✅ Fill every cell in the grid exactly once
  • ✅ Only orthogonal moves allowed (no diagonals)
  • ✅ Drag backwards to undo mistakes
  • ❌ No overlapping or crossing paths

🚀 Features

Core Gameplay

  • Unlimited Puzzles: Procedurally generated using advanced algorithms
  • Multiple Grid Sizes: Choose from 3×3 to 8×8 grids
  • Intelligent Generation: Backtracking DFS ensures all puzzles are solvable
  • Smooth Interaction: Fluid drag-and-drop with undo functionality
  • Timer: Track your completion time with precision timing

User Experience

  • Touch-Friendly: Optimized for both desktop and mobile devices
  • Responsive Design: Adapts to any screen size
  • High Performance: 60fps canvas rendering with <2s load times
  • Accessibility: High contrast support and screen reader friendly
  • No Registration: Play immediately without accounts or data collection

Technical Excellence

  • Modern Web Stack: React 18 + TypeScript + Vite
  • Canvas API: Hardware-accelerated rendering for smooth gameplay
  • PWA Ready: Works offline with fast loading
  • Cross-Browser: Tested on Chrome, Firefox, Safari, Edge
  • Mobile Optimized: Touch events with 16ms response time

🛠️ Development

Prerequisites

  • Node.js 18+
  • npm or yarn package manager

Quick Start

# Clone the repository
git clone <repository-url>
cd zip-puzzle-game

# Install dependencies
npm install

# Start development server
npm run dev

# Open browser to http://localhost:5173

Available Scripts

npm run dev          # Start development server with hot reload
npm run build        # Build for production
npm run preview      # Preview production build locally
npm run lint         # Run ESLint for code quality
npm run test         # Run Playwright tests
npm run test:ui      # Run tests with UI mode
npm run test:debug   # Debug tests step by step

Project Structure

src/
├── components/          # React components
│   ├── Game/           # Main game container
│   ├── Grid/           # Canvas-based game board
│   └── Timer/          # Stopwatch functionality
├── hooks/              # Custom React hooks
├── utils/              # Utility functions
│   ├── puzzleGenerator.ts  # Puzzle generation algorithms
│   ├── pathValidator.ts    # Solution validation
│   └── canvasHelpers.ts    # Canvas rendering utilities
├── types/              # TypeScript type definitions
├── constants/          # Game configuration
└── App.tsx            # Root component

🧠 Algorithm Deep Dive

Puzzle Generation

The game uses a sophisticated backtracking Depth-First Search (DFS) algorithm to generate valid puzzles:

  1. Hamiltonian Path Generation: Creates a path visiting every grid cell exactly once
  2. Dot Placement: Strategically places numbered dots along the solution path
  3. Validation: Ensures puzzle is solvable and meets difficulty requirements
  4. Fallback System: Multiple generation strategies for reliability

Path Validation

Real-time validation ensures player moves are legal:

  • Continuity Check: Verifies path has no gaps
  • Orthogonal Movement: Enforces grid-aligned movement only
  • Dot Sequence: Validates dots are connected in numerical order
  • Boundary Check: Prevents movement outside grid bounds
  • Uniqueness: Ensures no cell is visited twice

🎨 Design System

Colors

  • Primary: #2563eb (Blue 600)
  • Success: #10b981 (Emerald 500)
  • Background: #f8fafc (Slate 50)
  • Grid: #e5e7eb (Gray 200)
  • Text: #1f2937 (Gray 800)

Typography

  • Primary: System font stack (-apple-system, BlinkMacSystemFont, 'Segoe UI')
  • Monospace: 'Courier New', Monaco, monospace (Timer display)

Responsive Breakpoints

  • Mobile: 320px - 767px
  • Tablet: 768px - 1023px
  • Desktop: 1024px+

🧪 Testing

Test Coverage

The project includes comprehensive testing with Playwright:

  • Unit Tests: Puzzle generation and validation logic
  • Integration Tests: Full game flow and user interactions
  • Cross-Browser: Chrome, Firefox, Safari, Edge
  • Mobile Testing: iOS Safari and Android Chrome
  • Accessibility: Screen reader and keyboard navigation
  • Performance: Load time and rendering benchmarks

Running Tests

# Run all tests
npm run test

# Run specific test file
npx playwright test tests/game-basic.test.ts

# Run with browser UI
npm run test:headed

# Debug mode
npm run test:debug

📱 Browser Support

Desktop

  • ✅ Chrome 90+
  • ✅ Firefox 88+
  • ✅ Safari 14+
  • ✅ Edge 90+

Mobile

  • ✅ iOS Safari 14+
  • ✅ Chrome Mobile 90+
  • ✅ Samsung Internet 15+

🚀 Deployment

Production Build

# Create optimized production build
npm run build

# Preview production build locally
npm run preview

Deployment Options

The built application is static and can be deployed to:

GitHub Pages: Automatic deployment via GitHub Actions (already configured) • Vercel: vercel --prodNetlify: Drag & drop dist/ folder • Any Static Host: Upload contents of dist/ folder

Performance Optimizations

  • Bundle Splitting: Automatic code splitting with Vite
  • Asset Optimization: Images and fonts optimized for web
  • Canvas Rendering: Hardware-accelerated graphics
  • Tree Shaking: Unused code automatically removed
  • Gzip Compression: ~64KB total JavaScript bundle

🔧 Configuration

Game Settings

Modify src/constants/config.ts to adjust:

export const GAME_CONFIG = {
  minGridSize: 3,        // Smallest grid size
  maxGridSize: 8,        // Largest grid size
  defaultGridSize: 4,    // Initial grid size
  cellSize: 60,          // Canvas cell size in pixels
  dotRadius: 20,         // Dot size
  pipeWidth: 8,          // Path thickness
  colors: {              // Color scheme
    grid: '#e5e5e5',
    dot: '#2563eb',
    pipe: '#1d4ed8',
    // ...
  }
};

Performance Tuning

export const TIMING_CONFIG = {
  updateInterval: 16,     // 60fps target
  generationTimeout: 5000, // Max puzzle generation time
  celebrationDuration: 2000
};

🤝 Contributing

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Code Standards

  • TypeScript: Strict mode enabled
  • ESLint: All rules must pass
  • Prettier: Consistent formatting
  • Tests: New features require test coverage

Commit Messages

Use conventional commits:

  • feat: New features
  • fix: Bug fixes
  • docs: Documentation updates
  • style: Code style changes
  • refactor: Code refactoring
  • test: Test additions/updates

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • LinkedIn: Original Zip puzzle inspiration
  • React Team: Amazing framework and ecosystem
  • Vite: Lightning-fast build tool
  • Playwright: Excellent testing framework
  • Community: Open source contributors and testers

📞 Support


🎯 Product Requirements Checklist

✅ Completed Features

  • Playable Web Game: Full-featured puzzle game in browser
  • Touch-Friendly: Optimized for mobile and tablet devices
  • Unlimited Puzzles: Procedural generation with randomization
  • Solvable Guarantee: Advanced algorithms ensure all puzzles work
  • Drag Interface: Natural path drawing with undo functionality
  • Timer Display: Precise completion time tracking
  • Cross-Platform: Desktop and mobile browser support
  • Valid Puzzles: Comprehensive validation system
  • Fluid UI: 60fps rendering with smooth interactions
  • Local Storage: Grid size preferences saved
  • Modern Stack: React + TypeScript + Vite architecture
  • Canvas Rendering: Hardware-accelerated graphics
  • Playwright Testing: Comprehensive E2E test coverage
  • Performance: <2s load time, 16ms touch response
  • Accessibility: High contrast and keyboard support

🎉 All PRD requirements successfully implemented!

Built with ❤️ using modern web technologies.

🌐 Live Demo

Play the game now: https://k4l397.github.io/zip-puzzle-game/

The game is automatically deployed to GitHub Pages via GitHub Actions whenever changes are pushed to the main branch.

About

Modern web-based Zip puzzle game with React + TypeScript + Canvas API. Features procedural puzzle generation, touch/mouse controls, and responsive design.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages