2 mins
I am reading in the room information from a txt file. I have set up a the txt file to contain the information about the room in the format as follows:
Description Example
{ {
-The name of the room name:OPERATIONS ROOM
-The room id number roomID:11
-If it has a an item has item:1
-The name of the item item:BANANA
-If the room is safe safe:0
-The warning message of the room safety message:IT'S DANGEROUS IN THERE
-If the room needs an item to access it accessible:1
-Item required for access item/action required:-
-The requirement message of the room accesibility message:-
} }
[ [
-If he player can exit north north:27
-If he player can exit east east:-1
-If he player can exit south south:-1
-If he player can exit west west:4
] ]
All this information from each txt file will be stored into a 2 dimensional vector in the room class which stores all the data read in from a file.
With ‘has item’, ‘safe’ and ‘accessible’ all bools so when read in from a file they have to be 1 or 0 so they can be converted into true or false.
With ‘north’, ‘south’, ‘east’ and west’ if the number next to it is -1 then it means the user can head in that direction from that room and and if it is greater than 0 then then the player can head in that direction and it updates the current room using the number. What it will do is go to element in the vector and change all the variables of that room to the data at that point in the vector. This is shown in th code below. I am setting the room name to equal the data that point in the vector.
In the code snippet below, ‘value’ is the variable that is passed in when the room is updated and it goes to that element of the of vector and the 0 represents the first element of the vector at the point value.
room_name = name_of_vector[value].at(0);
In my room class a I have variables which will contain infromation about the room. After the data has been read in all these variables are set to whatever data has been read in.
std::string room_name = " ";
int room_id = 0;
bool has_item = false;
std::string item_name = " ";
bool safe = true;
std::string message = " ";
bool access = false;
std::string item_required = " ";
std::string requirement_message = " ";
int dir[4] = {0, 0, 0, 0};
I’ve decide to use vectors as it allows me to create more txt files and add to the txt and means less editting in my cpp files.
Subscribe to this blog via RSS.
Low level programming dev diary 28
Text based adventure dev diary 6
Level design developer diary 3
Game engine programming dev diary 14
Audio-visual production dev diary 7
Audio-Visual Production: Particle System Mesh Spawning Issues
Posted on 20 Feb 2020Low level programming dev diary (28) Text based adventure dev diary (6) Level design developer diary (3) Post mortem (4) Ex-machina dev diary (11) Game engine programming dev diary (14) Network game dev diary (11) Audio-visual production dev diary (7)