I'm doing a class project, creating a text based game, separate compilation must be used. The descriptions for each room must be kept in it's own class. Here is an example of what I have:

Room.h

#ifndef ROOM_H
#define ROOM_H
#include<iostream>
#include<string>

using namespace std;

class Room{
public:
    ///set the description of the current room
    void setRoomDescription(string descriptionParam);
    ///get the description of the current room 
    string getRoomDescription() const;

    void roomInfo() const;

    Room();

    Room(string descriptionParam);




private:
    string description;

};
#endif

Room.cpp

#include"Room.h"

void Room::setRoomDescription(string descriptionParam){
    description = descriptionParam;
}

string Room::getRoomDescription() const{
    return description;
}

Room::Room(string descriptionParam){
    description = descriptionParam;
}

void Room::roomInfo() const{
    cout<<getRoomDescription();
}

RoomDescription.cpp

#include "Room.h"

Room basement("You grudgingly open your eyes, only to find you still can't see."
            "A slight groan escapes your mouth as your head repeatedly throbs\nwith pain."
            " You slowly rise to your feet, groping the wall for support." 
            " Trying to remember how you got here only makes your head\nworse" 
            " but images of fire and men in masks quickly flash through your mind's eye."
            " Pulling a lighter out of your pocket you flick itto life. The small flame does little to better your view but a staircase with a door at the top has become visable.");

Room corridor1("\n"
        "You walk through the door and find yourself in a long corridor, the door closes and locks behind you."
        " Metal doors with small\nwindows line the walls."
        "As you wonder where the hell you are, one of the doors bang and the sound of screaming can be heard from\nbehind it."
        "Looking through the window you see a man in a straight jacket throwing himself against the walls whilst screaming to\nhimself."
        "As the man throws himself at the door again you jump back and decide to move on."
        " There are 3 other doors; one to your left, to your right and straight ahead."
        );

I want to be able to include the room description from the roomDescriptions class and use them in an array. Can anybody help??

Recommended Answers

All 2 Replies

And what's the problem?

Sorry, I'm not sure how to go about calling each description into the main.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.