(invisible) Map for Text adventure

Lowang

Member
Hi yall,

this might be an easy one for veterans, but I´m struggling to find the right method to create a map operating in the background.
The basic idea is a simple text adventure, so "Go North" stuff, no real graphics involved.

I just need a quick suggestion what method to use to easily navigate the map.
Currently I´m comtemplating if 2d arrays are the way to go, basically imitating a map grid like battleship.
But not sure if this is really viable, any suggestions?

Thanks in advance
 

chamaeleon

Member
I'd use structs for nodes/locations, as well as a struct within the node to indicate what directions can be used for movement from that location. Just some regular graph implementation, really. Alternatively, a one-dimensional array containing all locations, and each location having a struct that contains direction to array index for the destination location.
 

Lowang

Member
I'd use structs for nodes/locations, as well as a struct within the node to indicate what directions can be used for movement from that location. Just some regular graph implementation, really. Alternatively, a one-dimensional array containing all locations, and each location having a struct that contains direction to array index for the destination location.
Uh damn, forgot that structs where introduced.
Thanks, I´ll give it a look :)
 

chamaeleon

Member
Uh damn, forgot that structs where introduced.
Thanks, I´ll give it a look :)
ds_maps would work just as well, but I like structs due to them being garbage collected when not referenced, instead of the required manual cleanup of ds data structures.
 

NightFrost

Member
The best thing to do would be to uniquely identify each room in the adventure. The rooms can then simply point at each other by identifier when you need to store where each direction leads. The identifier might be an enumerator, or a bunch of macros. Or just numbers but that of course would be harder to keep track of. Then the very basic data that defines a room could be written as a struct like:
GML:
{
    description : "Description here.",
    north : enumerator for connection or -1,
    east : enumerator for connection or -1,
    south : enumerator for connection or -1,
    west : enumerator for connection or -1
}
Each struct would be stored to an array to a position by their enumerator identifier. So if you had a two-room map the whole setup would be something like:
GML:
enum Room {
    First,
    Second
}

Rooms[Room.First] = {
    Description : "The first room.",
    North : -1,
    East : Room.Second,
    South : -1,
    West : -1
}

Rooms[Room.Second] = {
    Description : "The second room.",
    North : -1,
    East : -1,
    South : -1,
    West : Room.First
}
Naturally, you'd want to write some constructors and functions to better manage their creation and access instead of just writing a huge struct list, the above is for illustrative purposes only. With this arrangement, when you need to list exits of current room, you just read the struct from the array and check with directions are not marked -1, and allow a move to given room when attempted.
 
Top