Nuggets is a multi-player game where players explore a map, collect gold nuggets, and compete to become the wealthiest. The game consists of a server that hosts the game and at most 26 clients that connect to the server to play (with the addition of 1 spectator).
In Nuggets, players navigate through a maze-like map system represented by ASCII characters. The cave contains rooms (.), passages (#), walls (+, -, |), and gold nuggets (*). Players are identified by uppercase letters, and can see only a limited portion of the cave (what's in their line of sight). As players move around, they collect gold nuggets. The game ends when all gold has been collected, and the player with the most gold wins.
The repository is organized into several modules, each responsible for a specific aspect of the game:
nuggets/
├── client/ # Client implementation
├── server.c # Main server program
├── game/ # Game state module
├── grid/ # Grid and visibility module
├── player/ # Player module
├── spectator/ # Spectator module
├── support/ # Support modules (message passing, logging)
├── maps/ # Map files for the game
The main server program that coordinates the game, handles network communication, processes client messages, and maintains the game state.
Key features:
- Initializes the game with a map file
- Processes client messages (PLAY, KEY, SPECTATE, QUIT)
- Handles player movements and gold collection
- Updates clients with their views of the game
- Manages game termination and final scoring
The client connects to a Nuggets server, renders the game display, and handles user input.
Key components:
- Network communication with the server
- Display rendering using ncurses
- Input handling for player movements
- Game state management on the client side
Manages the overall game state, including players, spectators, the game grid, and gold distribution.
Key features:
- Game initialization and clean-up
- Player and spectator management
- Gold distribution and collection
- Visibility and display string generation
Represents the game map and handles visibility calculations.
Key features:
- 2D grid representation with cells
- Line-of-sight visibility calculations
- Memory of previously seen areas
- Loading maps from files
Manages player-specific functionality and state.
Key features:
- Player creation and movement
- Gold collection and tracking
- Player-specific view of the game map
- Network communication with client
Handles spectator functionality, allowing users to watch the game without participating.
Key features:
- Spectator creation and management
- Network communication with spectator client
- Complete view of the game map
Utility modules that's provided to us
Key components:
- Message passing for network communication
- Logging for debugging and error reporting
The game uses a simple text-based protocol for communication between the server and clients:
PLAY [name]- Request to join as a playerSPECTATE- Request to join as a spectatorKEY [k]- Send a keystroke commandQUIT- Request to leave the game
OK [letter]- Acknowledge player joinGRID [nrows] [ncols]- Send grid dimensionsGOLD [n] [p] [r]- Update gold statusDISPLAY\n[map]- Send display updateQUIT [message]- Notify of game end
make
./server [map] [seed]
Where:
mapis the path to a map fileseed(optional) is a random seed for gold distribution
./client hostname port [playername]
Where:
hostnameis the server's addressportis the server's portplayername(optional) is the player's name (if omitted, joins as spectator)
h- Move leftl- Move rightj- Move downk- Move upy- Move diagonally up-leftu- Move diagonally up-rightb- Move diagonally down-leftn- Move diagonally down-right- Uppercase versions (e.g.,
H,L) move in that direction until hitting a wall Q- Quit the game
In addition to the requirement spec, we also allow the following keys for simplicity. Note that capitalizing these WASD keys won't TP the player across the map.:
a- Move leftd- Move rights- Move downw- Move up
Q- Quit spectating
The game map is represented as a 2D grid of characters, where:
.represents an empty room space#represents a passage+,-,|represent walls*represents a gold nugget@represents the player's own position- Uppercase letters represent other players
Players can only see portions of the map that are within their line of sight, which is calculated using a line of sight algorithm. Areas that were previously seen but are no longer visible are remembered but shown differently (if it's a gold that wasn't picked up or another player, it'll be remembered as a normal game spot).
Gold is randomly distributed throughout the map in piles of random amounts. When a player moves onto a pile, they collect all the gold in that pile. The game ends when all gold has been collected.