data structure for dungeons
peter.l.berghold
plb at cbnewsi.ATT.COM
Wed Aug 23 00:34:18 AEST 1989
In article <Aug.20.16.38.37.1989.24164 at porthos.rutgers.edu> sofmac at porthos.rutgers.edu (Sofus Macskassy) writes:
>
>I am trying to build up a 3d dungeon, but can't figure out
>what kind of data structure to use. I don't want to use
>arrays, but would rather use some kind of linked list.
>If somebody knows a good and short structure, that uses
>minimal memory, I would appreciate it if they would mail
>me at sofmac at porthos.rutgers.edu
Your data structures would depend on what kind of data that you would be
includeing in each record. However, for sake of generalization, here is a
scheme that might work.
--------------- code starts here...
typedef struct Dimensions{
int height,width,length; /* Self explainatory */
} Dimensions;
typedef struct DungeonPiece {
enum type={corridor,room,door,..etc... you get the idea};
Dimensions dimensions;
struct DungeonPiece **MadeOf; /* All the pieces that make this peice*/
struct DungeonPiece *Next; /* Next room, corrideor, etc. */
} DungeonPiece;
typedef struct DungeonLevel {
struct DungeonLevel *NextLevel,*LastLevel;
DungeonPiece *FirstPiece;
} DungeonLevel;
|
-------------- code ends here...
In this manner your dungeon goes together as a linked list of pieces with
the last piece pointing to (DungeonPiece *)0. You could simplify the coding
of it by creating "black box" modules of code that operate on one data type
at a time and just handing off the neccesary information to them. If you have
access to a C++ compiler, the whole thing could be handled as "objects"....
Pete
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| _ /| || Peter L. Berghold, AT&T, HRSAG, UUCP: att!violin!plb |
| \`o_O' ||============================================================ |
| ( ) || Disclaimer: If you find an opinion in this posting somewhere|
| U || it is no doubt mine, and not my employers. I'm the only |
| Aachk! || person crazy enough to take this stand! |
| Phft! || |
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
More information about the Comp.lang.c
mailing list