217 lines
6.1 KiB
Markdown
217 lines
6.1 KiB
Markdown
# Morse Code Practice Game 🎮
|
|
|
|
A terminal-based morse code practice game built with Deno. Improve your morse code translation skills through interactive gameplay with multiple difficulty levels and comprehensive statistics tracking.
|
|
|
|
## Features
|
|
|
|
- **Multiple Difficulty Modes**
|
|
- 🟢 Easy: Single letters (A-Z)
|
|
- 🟡 Medium: Letters + Numbers (A-Z, 0-9)
|
|
- 🟣 Hard: Letters + Numbers + Punctuation (.,?!-/()@)
|
|
- 🔵 Challenge: Common words (from 275k+ English word dictionary)
|
|
- 🔴 Expert: Random phrases (2-4 words generated from dictionary)
|
|
|
|
- **Interactive TUI Interface**
|
|
- Beautiful terminal UI with colors and tables
|
|
- Configurable time limits (3-60 seconds)
|
|
- Dynamic time option for words/phrases (time scales with length)
|
|
- Immediate feedback on answers
|
|
- Progress tracking with streak counter
|
|
- Detailed round-by-round results with translations
|
|
|
|
- **Statistics Tracking**
|
|
- Overall accuracy and performance metrics
|
|
- Mode-specific statistics
|
|
- Best streak tracking
|
|
- Historical game data
|
|
- Average time per round
|
|
- Average time per character (for words/phrases)
|
|
- Stats saved locally in project folder
|
|
|
|
- **Smart Feedback**
|
|
- Immediate feedback on answers
|
|
- Shows what your morse code translates to when incorrect
|
|
- Detailed results table with translations for all rounds
|
|
- Helps you learn from mistakes and track progress
|
|
|
|
- **Flexible CLI**
|
|
- Interactive menu mode (default)
|
|
- Quick play mode with command-line arguments
|
|
- Stats viewer
|
|
- Morse code translator (text ↔ morse)
|
|
- Built-in morse code reference
|
|
|
|
## Installation
|
|
|
|
Make sure you have [Deno](https://deno.land/) installed.
|
|
|
|
```bash
|
|
# Clone or download this repository
|
|
cd morse-game
|
|
|
|
# Make the script executable (optional)
|
|
chmod +x main.ts
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Interactive Mode (Default)
|
|
|
|
Run the game and navigate through the menu:
|
|
|
|
```bash
|
|
deno task start
|
|
# or
|
|
deno run --allow-read --allow-write --allow-env main.ts
|
|
```
|
|
|
|
The interactive menu provides access to:
|
|
- Start a new game
|
|
- View statistics
|
|
- Morse code reference chart
|
|
- Translator tool (convert between text and morse code)
|
|
- Reset statistics
|
|
- Exit
|
|
|
|
### Quick Play Mode
|
|
|
|
Start a game directly with custom settings:
|
|
|
|
```bash
|
|
# Play 5 rounds of letters mode with 20 seconds per round
|
|
deno task start play --mode letters --rounds 5 --time 20
|
|
|
|
# Play expert mode
|
|
deno task start play --mode phrases --rounds 10 --time 45
|
|
```
|
|
|
|
Options:
|
|
- `-m, --mode <mode>` - Game mode: `letters`, `alphanumeric`, `full`, `words`, or `phrases` (default: letters)
|
|
- `-r, --rounds <number>` - Number of rounds (default: 10)
|
|
- `-t, --time <seconds>` - Seconds per round (default: 30)
|
|
|
|
### View Statistics
|
|
|
|
```bash
|
|
deno task start stats
|
|
```
|
|
|
|
### Show Reference
|
|
|
|
Display a morse code reference chart:
|
|
|
|
```bash
|
|
deno task start reference
|
|
```
|
|
|
|
### Translator
|
|
|
|
Convert between text and morse code:
|
|
|
|
```bash
|
|
deno task start
|
|
# Then select "Translator" from the menu
|
|
```
|
|
|
|
The translator allows bidirectional conversion:
|
|
- Text → Morse Code
|
|
- Morse Code → Text
|
|
|
|
### Reset Statistics
|
|
|
|
```bash
|
|
deno task start reset
|
|
```
|
|
|
|
## How to Play
|
|
|
|
1. **Select a difficulty mode** - Choose from:
|
|
- Letters only (A-Z)
|
|
- Alphanumeric (A-Z, 0-9)
|
|
- Full character set (letters, numbers, punctuation)
|
|
- Words (randomly selected from English dictionary, 3-8 letters)
|
|
- Phrases (2-4 words randomly combined from dictionary)
|
|
2. **Configure your game** - Set the number of rounds (5-50) and time per round (3-60 seconds)
|
|
3. **Enable dynamic time (optional)** - For words/phrases, time can scale based on character count
|
|
4. **Translate to morse code** - You'll be shown a challenge from real English words
|
|
5. **Enter your answer** - Type the morse code using:
|
|
- `.` (dot) for short signals
|
|
- `-` (dash) for long signals
|
|
- Space to separate letters
|
|
- `/` to separate words
|
|
6. **Get instant feedback** - See if you got it right and what your input translates to if wrong
|
|
7. **Review your performance** - After all rounds, view detailed statistics including:
|
|
- Overall accuracy and time metrics
|
|
- Average time per character (for words/phrases)
|
|
- Complete results table showing what each morse input translates to
|
|
|
|
## Morse Code Basics
|
|
|
|
- Use `.` for dots and `-` for dashes
|
|
- Separate letters with spaces
|
|
- Use `/` for word boundaries
|
|
- Supported punctuation: `. , ? ! - / ( ) @`
|
|
- Example: `HELLO` = `.... . .-.. .-.. ---`
|
|
- Example: `SOS` = `... --- ...`
|
|
- Example: `HELLO WORLD` = `.... . .-.. .-.. --- / .-- --- .-. .-.. -..`
|
|
|
|
## Statistics
|
|
|
|
The game tracks:
|
|
- Total games played
|
|
- Total rounds completed
|
|
- Correct and incorrect answers
|
|
- Overall accuracy percentage
|
|
- Average time per round
|
|
- Best streak (consecutive correct answers)
|
|
- Per-mode statistics
|
|
|
|
Stats are saved to `./data/stats.json` in the project directory.
|
|
|
|
When you answer incorrectly, the game shows what your morse code input actually translates to, helping you understand and learn from your mistakes.
|
|
|
|
## Development
|
|
|
|
```bash
|
|
# Run in watch mode for development
|
|
deno task dev
|
|
|
|
# Run with specific permissions
|
|
deno run --allow-read --allow-write --allow-env main.ts
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
morse-game/
|
|
├── main.ts # CLI entry point and command parser
|
|
├── game.ts # Game logic and session management
|
|
├── morse.ts # Morse code translation utilities
|
|
├── stats.ts # Statistics tracking and persistence
|
|
├── ui.ts # TUI interface and menus
|
|
├── deno.json # Deno configuration and dependencies
|
|
└── README.md # This file
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- [@cliffy/command](https://jsr.io/@cliffy/command) - CLI framework
|
|
- [@cliffy/prompt](https://jsr.io/@cliffy/prompt) - Interactive prompts
|
|
- [@cliffy/ansi](https://jsr.io/@cliffy/ansi) - ANSI colors and formatting
|
|
- [@cliffy/table](https://jsr.io/@cliffy/table) - Table rendering
|
|
- [@std/path](https://jsr.io/@std/path) - Path utilities
|
|
- [@std/fs](https://jsr.io/@std/fs) - File system utilities
|
|
- [an-array-of-english-words](https://www.npmjs.com/package/an-array-of-english-words) - English word dictionary (275k+ words)
|
|
|
|
## License
|
|
|
|
MIT
|
|
|
|
## Contributing
|
|
|
|
Feel free to open issues or submit pull requests!
|
|
|
|
---
|
|
|
|
**73** (Best regards in morse code) 📡
|