|
1 | | -# Tic-Tac-Toe |
| 1 | +# Hangman for Smart Glasses |
2 | 2 |
|
3 | | -### Local Development Setup |
| 3 | +A classic Hangman word-guessing game designed for smart glasses with a 526x100 pixel 1-bit bitmap display. Built using the Mentra SDK with voice-activated gameplay and real-time visual feedback. |
4 | 4 |
|
5 | | -To initialize the FrequencyWords submodule for local development: |
| 5 | +## Overview |
6 | 6 |
|
7 | | -```bash |
8 | | -# Initialize submodules |
9 | | -bun run submodule:init |
| 7 | +This application provides an immersive Hangman experience where players guess letters by speaking them aloud. The game features a curated collection of challenging words, progressive hangman drawing, and supports multiple simultaneous users. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Voice-Activated Gameplay**: Guess letters by speaking them (e.g., "A", "the letter B") |
| 12 | +- **Visual Feedback**: Real-time hangman drawing with 6-stage progression |
| 13 | +- **Smart Word Selection**: 136 carefully chosen words with varying difficulty |
| 14 | +- **Multi-User Support**: Each user maintains their own game session |
| 15 | +- **Session Persistence**: Games persist throughout user sessions |
| 16 | +- **Restart Functionality**: Say "play again" to start a new game |
| 17 | + |
| 18 | +## Game Mechanics |
| 19 | + |
| 20 | +### Word Guessing |
| 21 | +- Players guess letters one at a time using voice commands |
| 22 | +- Correct guesses reveal all instances of that letter in the word |
| 23 | +- Incorrect guesses add a body part to the hangman drawing |
| 24 | +- Game ends when either the word is completed or the hangman is fully drawn (6 wrong guesses) |
| 25 | + |
| 26 | +### Input Recognition |
| 27 | +The game accepts various voice input formats: |
| 28 | +- Single letters: "A", "B", "Z" |
| 29 | +- Formal phrases: "The letter A", "Letter B" |
| 30 | +- Case-insensitive recognition |
| 31 | + |
| 32 | +### Visual Display |
| 33 | +The 526x100 pixel display shows: |
| 34 | +- **Word Progress**: Letters and blanks (e.g., "H A _ _ M A _") |
| 35 | +- **Hangman Drawing**: Progressive 6-stage gallows and figure |
| 36 | +- **Guessed Letters**: Alphabetically sorted list of previous guesses |
| 37 | +- **End Game Messages**: Win/lose notifications with restart instructions |
| 38 | + |
| 39 | +## Technical Architecture |
| 40 | + |
| 41 | +### Core Components |
| 42 | + |
| 43 | +- **`src/index.ts`**: Main application server using Mentra SDK |
| 44 | +- **`src/words.ts`**: Curated word collection and random selection |
| 45 | +- **`src/bitmap.ts`**: 1-bit BMP generation and canvas utilities |
| 46 | +- **`src/font.ts`**: 5x7 pixel font rendering system |
| 47 | + |
| 48 | +### Game State Management |
| 49 | + |
| 50 | +```typescript |
| 51 | +interface HangmanGame { |
| 52 | + word: string; |
| 53 | + guessedLetters: Set<string>; |
| 54 | + wrongGuesses: number; |
| 55 | + state: GameState; |
| 56 | + maxWrongGuesses: number; |
| 57 | +} |
10 | 58 | ``` |
11 | 59 |
|
12 | | -This will: |
13 | | -1. Initialize the FrequencyWords submodule |
14 | | -2. Fetch all files from the repository |
15 | | -3. Make them available for local development |
16 | | - |
17 | | -### Docker and Production Setup |
18 | | - |
19 | | -We use a two-tier approach for FrequencyWords files in production: |
20 | | - |
21 | | -#### Primary: GitHub Actions + Submodules (for Porter) |
22 | | -When building through GitHub Actions (Porter deployment): |
23 | | -- The submodule is explicitly initialized with `submodules: 'recursive'` |
24 | | -- All FrequencyWords files are included directly in the Docker image |
25 | | -- No runtime downloads needed |
26 | | - |
27 | | -#### Fallback: Runtime Downloads (for manual builds) |
28 | | -If the Docker image is built manually without submodule initialization: |
29 | | -- Base directories are created during build |
30 | | -- Our startup script checks for missing files |
31 | | -- Any missing files are downloaded at runtime using Node.js |
32 | | -- No external tools required (uses built-in https module) |
33 | | - |
34 | | -### GitHub Actions Workflow for Porter |
35 | | - |
36 | | -Our Porter deployments use GitHub Actions with proper submodule handling: |
37 | | - |
38 | | -```yaml |
39 | | -jobs: |
40 | | - build-and-deploy: |
41 | | - runs-on: ubuntu-latest |
42 | | - steps: |
43 | | - - name: Checkout code with submodules |
44 | | - uses: actions/checkout@v3 |
45 | | - with: |
46 | | - submodules: 'recursive' # This ensures FrequencyWords is properly fetched |
47 | | - |
48 | | - # Build and push to registry, then deploy to Porter |
| 60 | +States: `PLAYING`, `WON`, `LOST`, `WAITING_RESTART` |
| 61 | + |
| 62 | +### Display Rendering |
| 63 | + |
| 64 | +The game renders a complete visual state for each user interaction: |
| 65 | +1. **Canvas Creation**: 526x100 boolean array |
| 66 | +2. **Word Rendering**: Shows progress with guessed letters revealed |
| 67 | +3. **Hangman Drawing**: Progressive illustration based on wrong guess count |
| 68 | +4. **UI Elements**: Guessed letters list and game status |
| 69 | +5. **BMP Conversion**: 1-bit bitmap generation for smart glasses display |
| 70 | + |
| 71 | +## Installation & Setup |
| 72 | + |
| 73 | +### Prerequisites |
| 74 | +- Node.js (v18 or higher) |
| 75 | +- Bun runtime |
| 76 | +- Mentra SDK API key |
| 77 | + |
| 78 | +### Environment Configuration |
| 79 | +Create a `.env` file with: |
| 80 | +```env |
| 81 | +PACKAGE_NAME=your-package-name |
| 82 | +AUGMENTOS_API_KEY=your-api-key |
| 83 | +PORT=80 |
| 84 | +``` |
| 85 | + |
| 86 | +### Installation |
| 87 | +```bash |
| 88 | +# Install dependencies |
| 89 | +bun install |
| 90 | + |
| 91 | +# Start development server |
| 92 | +bun run dev |
| 93 | + |
| 94 | +# Start production server |
| 95 | +bun run start |
49 | 96 | ``` |
50 | 97 |
|
51 | | -The workflow is designed to: |
52 | | -1. Properly fetch all FrequencyWords files during checkout |
53 | | -2. Include them in the Docker image during build |
54 | | -3. Ensure no runtime downloads are needed in production |
| 98 | +## Usage |
| 99 | + |
| 100 | +1. **Start Game**: Launch the application and begin speaking |
| 101 | +2. **Make Guesses**: Say individual letters to guess |
| 102 | +3. **Track Progress**: Watch the hangman drawing and word completion |
| 103 | +4. **Restart**: Say "play again" when the game ends |
| 104 | +5. **Health Check**: Visit `/health` endpoint to verify server status |
| 105 | + |
| 106 | +## Word Collection |
| 107 | + |
| 108 | +The game includes 136 challenging words featuring: |
| 109 | +- Varied lengths (4-12 letters) |
| 110 | +- Diverse vocabulary (common and uncommon words) |
| 111 | +- Strategic letter combinations |
| 112 | +- Words with unique spelling patterns |
| 113 | + |
| 114 | +Examples: ABRUPT, GALVANIZE, MYSTIFY, QUIXOTIC, RAZZMATAZZ, ZIGZAGGING |
55 | 115 |
|
56 | 116 | ## Development |
| 117 | + |
| 118 | +### Project Structure |
| 119 | +``` |
| 120 | +src/ |
| 121 | +├── index.ts # Main application server |
| 122 | +├── words.ts # Word collection and selection |
| 123 | +├── bitmap.ts # Canvas and BMP utilities |
| 124 | +├── font.ts # Pixel font rendering |
| 125 | +├── public/ |
| 126 | +│ └── tpa_config.json |
| 127 | +└── utils/ # Shared utilities |
| 128 | +``` |
| 129 | + |
| 130 | +### Bitmap Format |
| 131 | +- **Dimensions**: 526x100 pixels |
| 132 | +- **Color Depth**: 1-bit (black and white) |
| 133 | +- **Format**: Windows BMP with proper headers |
| 134 | +- **Encoding**: Row-padded to 32-bit boundaries |
| 135 | + |
| 136 | +### Font System |
| 137 | +- **Character Set**: A-Z, 0-9, punctuation |
| 138 | +- **Dimensions**: 5x7 pixels per character |
| 139 | +- **Scaling**: Configurable scale factor for larger text |
| 140 | +- **Spacing**: 1 pixel between characters by default |
| 141 | + |
| 142 | +## Deployment |
| 143 | + |
| 144 | +The application is containerized with Docker and can be deployed using the included configuration: |
| 145 | + |
| 146 | +```bash |
| 147 | +# Build and deploy |
| 148 | +docker build -t hangman-game . |
| 149 | +``` |
| 150 | + |
| 151 | +Includes Porter configuration for cloud deployment with automatic scaling and health monitoring. |
| 152 | + |
| 153 | +## API Endpoints |
| 154 | + |
| 155 | +- **`/health`**: Server health check |
| 156 | +- **Mentra SDK**: Handles session management and transcription streams |
| 157 | + |
| 158 | +## Contributing |
| 159 | + |
| 160 | +1. Follow the existing code style and patterns |
| 161 | +2. Test voice recognition thoroughly |
| 162 | +3. Ensure bitmap rendering accuracy |
| 163 | +4. Maintain session isolation between users |
| 164 | +5. Update word collection thoughtfully |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +ISC License - See LICENSE file for details. |
0 commit comments