Skip to content

rik72/flip-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Flipgame

A minimalistic mobile puzzle game built with HTML5 Canvas and touch gestures.

๐ŸŽฎ Game Overview

Flipgame is a level-based puzzle game designed exclusively for mobile devices. The user navigates a ball through various board layouts by dragging it along permitted paths, with the goal of reaching the end point of each level.

Key Features

  • Mobile-First Design: Optimized for touch interactions and mobile screens
  • Level-Based Progression: Solve puzzles to unlock new levels
  • Proportional Rendering: Balls, halos, and goal rings scale with board size for consistent visuals
  • Touch Gestures: Intuitive drag and tap controls
  • No Text UI: Clean, visual-only interface with level numbers displayed graphically
  • Progress Saving: Automatic save/load of game progress

๐Ÿ—๏ธ Architecture

The project follows a modular architecture with clear separation of concerns:

CONSTANTS โ†’ Utils โ†’ HtmlBuilder โ†’ DisplayManager โ†’ 
StorageManager โ†’ GameManager โ†’ App

Core Components

  • GameManager: Handles game logic, level management, and touch interactions
  • StorageManager: Manages game progress and settings persistence
  • DisplayManager: Renders game UI and manages display states
  • HtmlBuilder: Generates HTML components for the game interface
  • Utils: Provides utility functions for validation and calculations

๐Ÿš€ Getting Started

Prerequisites

  • Modern web browser with HTML5 Canvas support
  • Touch-enabled device (recommended) or mouse for desktop testing

Installation

  1. Clone the repository:
git clone <repository-url>
cd flipgame
  1. Open index.html in a web browser or serve locally:
# Using Python
python3 -m http.server 8099

# Using Node.js
npx serve .

# Using PHP
php -S localhost:8099
  1. Access the game at http://localhost:8099

Development

The project uses vanilla JavaScript with no build process required. Key files:

  • index.html - Main HTML structure
  • app.js - Main application controller
  • managers/game-manager.js - Game logic and mechanics
  • styles.css - Game styling and mobile optimizations
  • constants.js - Game configuration and messages

๐ŸŽฏ Game Mechanics

Core Gameplay

  1. Level Loading: Each level presents a unique board layout
  2. Ball Movement: Drag the white ball to move along permitted paths
  3. Goal Achievement: Reach the green end point to complete the level
  4. Board Manipulation: Use rotation and flip mechanics to find new solutions
  5. Progression: Complete levels to unlock new challenges

Board Types

  • Square Lattice: Traditional grid-based layouts with 90ยฐ rotation
  • Triangular Lattice: Hexagonal-based layouts with 60ยฐ rotation

Cell Types

  • Empty: Free movement space
  • Path: Permitted movement corridors
  • Teleport: Instant movement between points
  • Switch: Interactive elements that change board state
  • Collectible: Optional items that enhance gameplay

๐Ÿ“ฑ Mobile Optimization

Touch Handling

  • Touch Events: Optimized for mobile touch interactions with preventDefault + stopPropagation
  • Device Pixel Ratio: Canvas scaled for high-DPI displays without touch offset
  • Responsive Design: Adapts to different screen sizes and orientations
  • Performance: 60fps target for smooth gameplay

Accessibility

  • Touch Targets: Minimum 44px for all interactive elements
  • Visual Feedback: Clear visual indicators for all game states
  • Reduced Motion: Respects user preferences for motion sensitivity

๐ŸŽจ Customization

Adding New Levels

Levels are defined in the GameManager (grid-based). Balls and goal rings scale with gridSize. Use the following structure:

{
    board: {
        nodes: [
            "........",
            "........",
            "........",
            "........",
            "........",
            "........",
            "........",
            "........"
        ]
    },
    balls: [
        {
            start: [2, 2],
            end: [6, 6],
            color: 'white'
        }
    ]
}

Node Types (String-based)

  • . - Empty space
  • # - Path (movement allowed)
  • T - Teleport
  • S - Switch
  • C - Collectible

Ball Properties

  • start: [x, y] - Starting grid position
  • end: [x, y] - Goal grid position
  • color - Ball color (optional)

Note: Visual ball size scales with the board (gridSize * 0.375 base), touch feedback scales up to match the goal inner radius, and halo matches the goal outer radius.

Styling

The game uses CSS custom properties for easy theming:

:root {
    --background-color: #000000;
    --ball-color: #ffffff;
    --goal-color: #00ff00;
    --path-color: #666666;
}

๐Ÿ”ง Development Guidelines

Code Standards

  • Zero Duplication: No code or message duplication allowed
  • Constants First: All text and configuration in constants files
  • Modular Architecture: Clear separation of concerns
  • Mobile Performance: Optimize for 60fps on target devices

File Structure

flipgame/
โ”œโ”€โ”€ index.html              # Main HTML file
โ”œโ”€โ”€ app.js                  # Main application controller
โ”œโ”€โ”€ app-bridge.js           # Global bridge functions
โ”œโ”€โ”€ styles.css              # Game styling
โ”œโ”€โ”€ constants.js            # Constants

โ”œโ”€โ”€ utils.js                # Utility functions

โ”œโ”€โ”€ html-builder.js         # HTML component generation
โ”œโ”€โ”€ display-manager.js      # Display state management
โ”œโ”€โ”€ managers/
โ”‚   โ”œโ”€โ”€ storage-manager.js  # Data persistence

โ”‚   โ””โ”€โ”€ game-manager.js     # Game logic and mechanics
โ””โ”€โ”€ levels/                 # Level definitions (future)

๐Ÿ› Troubleshooting

Common Issues

  1. Canvas not rendering: Check browser console and verify devicePixelRatio scaling is applied
  2. Touch offset: Ensure touch coordinates use CSS pixels (not DPR-scaled)
  3. Performance issues: Check for background processes affecting frame rate
  4. Progress not saving: Verify localStorage is enabled in browser

Debug Mode

Enable debug logging by setting:

localStorage.setItem('flipgame_debug', 'true');

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Follow the coding standards and architecture guidelines
  4. Test on mobile devices
  5. Submit a pull request

๐ŸŽฏ Roadmap

  • Additional level types and mechanics

  • Sound effects and background music

  • Particle effects and animations

  • Level editor for custom puzzles

  • Progressive Web App (PWA) support

  • Social sharing and leaderboards

๐Ÿ“ž Support

For questions or issues, please check the documentation or create an issue in the repository.

About

Flip game (hoho).

Resources

License

Stars

Watchers

Forks

Packages

No packages published