Skip to content

Commit b452cc0

Browse files
committed
Merge branch 'main' of github.com:Mentra-Community/Hangman
2 parents 9a02e77 + 12bf794 commit b452cc0

13 files changed

Lines changed: 293 additions & 756 deletions

.github/workflows/deploy-main.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"on":
2+
push:
3+
branches:
4+
- main
5+
6+
name: Deploy to hangman
7+
jobs:
8+
porter-deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
- name: Set Github tag
14+
id: vars
15+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
16+
- name: Setup porter
17+
uses: porter-dev/setup-porter@v0.1.0
18+
- name: Deploy stack
19+
timeout-minutes: 30
20+
run: exec porter apply -f ./porter.yaml
21+
env:
22+
PORTER_APP_NAME: hangman
23+
PORTER_CLUSTER: "4689"
24+
PORTER_DEPLOYMENT_TARGET_ID: 4a24a192-04c8-421f-8fc2-22db1714fdc0
25+
PORTER_HOST: https://dashboard.porter.run
26+
PORTER_PR_NUMBER: ${{ github.event.number }}
27+
PORTER_PROJECT: "15081"
28+
PORTER_REPO_NAME: ${{ github.event.repository.name }}
29+
PORTER_TAG: ${{ steps.vars.outputs.sha_short }}
30+
PORTER_TOKEN: ${{ secrets.PORTER_APP_15081_4689 }}

README.md

Lines changed: 159 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,168 @@
1-
# Tic-Tac-Toe
1+
# Hangman for Smart Glasses
22

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.
44

5-
To initialize the FrequencyWords submodule for local development:
5+
## Overview
66

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+
}
1058
```
1159

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
4996
```
5097

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
55115

56116
## 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.

bun.lock

Lines changed: 92 additions & 499 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ WORKDIR /app
55
# Copy package files
66
COPY package.json bun.lock* ./
77

8-
# Copy scripts needed for startup
9-
COPY scripts/docker-startup.sh ./scripts/docker-startup.sh
10-
RUN chmod +x ./scripts/docker-startup.sh
118

129
# Install dependencies
1310
RUN bun install

docker/Dockerfile.dev

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker/docker-compose.cloud_template.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docker/docker-compose.dev.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

docker/docker-compose.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"description": "Hangman game for smart glasses with 526x100 bitmap display",
55
"main": "dist/index.js",
66
"scripts": {
7-
"build": "tsc",
8-
"start": "npm run build && node dist/index.js",
9-
"dev": "npm run build && node dist/index.js"
7+
"start": "bun src/index.ts",
8+
"dev": "bun src/index.ts"
109
},
1110
"keywords": [
1211
"hangman",

0 commit comments

Comments
 (0)