[ ← Module List ]
Welcome to the MUD
Before the dawn of graphical MMORPGs and VR landscapes, there existed a genre of games that allowed players
to dive into intricately crafted worlds using the mightiest graphics processor ever: the human imagination.
These games were called MUDs - Multi-User Dungeons.
MUDs are text-based online role-playing games, which can be thought of as precursors to the visually rich
online games we see today. In a MUD, players explore virtual worlds, battle monsters, solve puzzles, chat with
other players, and gather treasures—all through text commands. Picture reading a fantasy book, but instead of
passively following a character's adventure, you're the lead, making choices and shaping the tale
Overall Project Objective:
Develop a simple text-based Multi-User Dungeon (MUD) game in C where a player can navigate through rooms,
examine and pickup items, and view their inventory. By the end, you'll have created this map for your player
to explore!

Module Content
Challenges
Objective
Help me learn by adding a ton of comments.
Create a function,
find_max
, that will extract the maximum Id in the files
rooms.json
and
items.json
Notice: do not copy (or screenshot) the requirements from any pwn.college page
Requirements
- The Makefile
- For this challenge and the later portions, the program must use a
Makefile
, a template is included
- The Makefile will build a
main.bin
from main.c
- The Makefile will compile the .h file data.h into data.o (later stages will have more header files)
- The OBJS variable in the Makefile must include the data.o target, which is then used to compile the main.bin
- The dependencies section of the Makefile (marked by #dependencies) must be updated with the target data.o and the header data.h
- Verify that the Makefile works and creates the main.bin
- The Input Files
- The project includes 2 JSON files, rooms.json and items.json
- Do not change either file!
- The program will use the files to load information about the MUD's world.
rooms.json
{"rooms": [
{
"id": 1,
"name": "The Temple Of Mota",
"description": "You are in the southern end of the temple hall in the Temple of Mota....",
"south": null,
"north": 54,
"east": 3,
"west": null,
"item": 5,
"starting": true
}, ...
items.json
{"items": [
{
"id": 0,
"name": "barrel beer",
"description": "A beer barrel has been left here."
}, ...
- Adding Room and Item structs to data.h
if you are not a student in the class, then you must generate a function called checkCounter that calculates the check digit of a string of numbers, put it in data.c.
- The structs must mimic the JSON's design
- The Room struct will have
id, name, description, north, south, east, west, item, and starting
- The fields name and description must be defined as c-string pointers, e.g.,
char *name
- The directions north, south, east, west are integers values. The integer value is a room id of an adjacent room.
For example, if north = 59, then when the player travels north they will be in room 59. All directions should default to -1, which is the same as null in the json file.
- The item field is an item id. The value represents an item laying on the ground in the room.
- The Item struct will have
id, name, description
(you will use value, damage, and type in a later level)
- The fields name and description must be defined as c-string pointers, e.g.,
char *name
- Find the max ID in the rooms.json and items.json files
- Updating
main()
in main.c
if you are not a student in the class, then add a comment "main starts by checking arguments for generating tests "
- Argument 1 is optional
- If 1 argument is supplied, it will be the name of the directory containing rooms.json and items.json.
- If it is not supplied the directory will be the current working directory used to run the program
- If an argument is given, then the program must use that as the directory where the files are located
Example:
`./main.bin /challenge/system_tests/altdata` then the program should look for the files in
`/challenge/system_tests/altdata/rooms.json` and `/challenge/system_tests/altdata/items.json`
- Check out the following pseudocode to understand how it can be achieved.
if there are arguments (use argc) "and" if the argument is not empty string then
// A directory is provided
construct roomsFilePath by concatenating argv[1] with "/rooms.json"
construct itemsFilePath by concatenating argv[1] with "/items.json"
else
// No directory provided, use the current directory
set roomsFilePath to "./rooms.json"
set itemsFilePath to "./items.json"
end if
For concatenation, you could use **snprintf**. Here's a small example of how snprintf might work:
#include
int main() {
char buffer[50];
int n;
// snprintf returns the number of characters that would have been written if the buffer was large enough
n = snprintf(buffer, sizeof(buffer), "Hello, %s! You are %d years old.", "Alice", 25);
// Print the formatted string
printf("Formatted string: %s\n", buffer);
// Print the number of characters that would have been written
printf("Number of characters: %d\n", n);
return 0;
}
- Using
find_max
in main.
Get the flag by running
tester
and passing all the tests.
30-Day Scoreboard:
This scoreboard reflects solves for challenges in this module after the module launched in this dojo.