A command-line treasure hunt management system in C, featuring a hub-monitor architecture to manage hunts, treasures, and user scores.
This system allows administrators to manage treasure hunts by adding, viewing, listing, and removing treasures, as well as calculating user scores. It uses:
- Hub: Central controller that starts/stops the monitor and sends commands.
- Monitor: Waits for commands from the hub and executes treasure operations.
- Treasures: Stored in per-hunt
treasures.datfiles. - Scores: Calculated per user based on collected treasures.
The architecture is as follows:
+-------+ commands +---------+
| Hub | ----------------------> | Monitor |
+-------+ +---------+
^ |
| v
+------------------- Treasure Files (treasures.dat)
- Start and stop the monitor process.
- Add, list, view, and remove treasures.
- Remove entire hunts.
- List all treasure hunts.
- Calculate scores per user.
- Logs all actions for each hunt.
.
├── hub.c # Hub process code
├── treasure_monitor.c # Monitor process code
├── treasure_manager.c # Treasure management functions
├── calculate_score.c # Score calculation utility
├── hub.h # Hub header
├── treasure_manager.h # Treasure manager header
├── monitor_command.txt # Command file (created at runtime)
└── README.md
- Clone the repository:
git clone https://github.com/yourusername/treasure-hunt.git
cd treasure-hunt- Compile all components:
gcc -o hub hub.c treasure_manager.c -Wall
gcc -o treasure_monitor treasure_monitor.c treasure_manager.c -Wall
gcc -o calculate_score calculate_score.c treasure_manager.c -WallEnsure all executables (
hub,treasure_monitor,calculate_score) are in the same directory.
- Start the hub:
./hub- Use hub commands to control the monitor and manage hunts/treasures.
Hub commands:
| Command | Description |
|---|---|
start_monitor |
Starts the monitor process |
stop_monitor |
Stops the monitor process |
list_hunts |
Lists all active treasure hunts |
list_treasures <hunt> |
Lists treasures in a specific hunt |
view_treasure <hunt> <id> |
Displays details of a specific treasure |
calculate_score |
Calculates scores for all users in all hunts |
exit |
Exits the hub (monitor must be stopped first) |
Monitor commands are handled internally; users do not interact with it directly.
- Start the monitor:
> start_monitor
Monitor started (PID: 12345).
- Add a treasure to a hunt (handled by monitor via command):
> add_treasure hunt:001
Enter Treasure ID: 1
Enter Username: alice
Enter Latitude: 12.345
Enter Longitude: 67.890
Enter Clue: Under the old oak
Enter Value: 100
Treasure added to hunt hunt:001.
- List treasures:
> list_treasures hunt:001
ID: 1 | User: alice | GPS: (12.3450, 67.8900) | Value: 100
- View user scores:
> calculate_score
alice: 100
- Stop the monitor before exiting hub:
> stop_monitor
[Monitor] Stopping...
Monitor terminated.
> exit