C++ project- making a text based game

So i'm attempting to make a text based game for a class project. I want to make a class for the rooms the player will enter. Each room will contain objects which are randomized using the rand() function. I will also likely randomize the number of doors in each room, and have pointers at each door pointing to the next room. (For example, each room can have 1 - 4 doors). I have a general idea of how to do this, but i'm not sure how to get started. Do i need to include the rand() function, as well as the pointers, inside the class? or should they be in my main code? Essentially i need help creating the room class. Thank you all very much! Getting started with programs is always the hardest part for me.
The most important part is having a plan. Do not yet think about pointers or rand() but rather how the game should be played. Is it a kind of game where you enter commands like "go east", "eat apple" or "show room" ?

In a real OO game you will end up with quite a few classes like Room, Item, Player ...
Do you have a good knowledge about the stl(containers, algorithms)?
Do you the basics about classes?

The best Object oriented game I saw was in Java.
https://www.bluej.org/objects-first/ under book projects, chapter 6
The syntax is similar to C++ so you can get an idea.

Another option is have a look at other projects here:
http://www.cplusplus.com/search.do?q=text+adventure
I've been thinking about it and i want to use commands like "go east" to go through the door on the east side. its an intro to c++ class so i have a the basics of classes down, although i don't know anything about containers or algorithms or stl.


I'm thinking about whether i should give the player a list of options for what they can do as they enter each room, such as interacting with objects, going through the east door etc. this doesn't feel like the most efficient way to go about it but i cant think of another way. Or maybe i can just give the player a list of commands in the beginning, kind of like a tutorial, so they know they know to use "go west" in any situation, or "interact with [object]" so that it will work with any object, or "examine room" to see whats in it.


Also a big thing i'm having trouble understanding is how to keep track of which door leads where, so that the door they just came through will lead to the same room. i know that pointers would have to be involved but not quite sure how to do it.
I know that pointers would have to be involved but not quite sure how to do it.

A collection of rooms forms the vertices of an undirected cyclic graph. The portals between them form the edges. Such graphs are often represented using adjacency lists.

Because managing ownership in an undirected graph of owning pointers is difficult, I would advise that you store every room in a single owning collection and represent the connections between rooms in adjacency lists.

Such a graph representation makes it easy to procedurally-generate rooms with any number of algorithms -- one simple way is to use, e.g., Prim's algorithm (modified to select a random edge instead of the minimum-weight edge)
https://en.wikipedia.org/wiki/Prim%27s_algorithm
Is there any chance you could give me an example of how to implement this? I've been looking into storing them in owning collections, as well as adjacency lists, but i'm not too sure what this would look like.
There are other ways to store the adjacent rooms. One would be to use a map or use an index where the number refers to either an id of the room stored somewhere else or the number could refer to an index in a vector of rooms.
Topic archived. No new replies allowed.