Text Based Adventure Game Dev Diary: Items

Text Based Adventure Game Dev Diary: Items

Nov 10, 2018. | By: Lewis Bond
1 min

Text Based Adventure Game

Interacting With Items

For interacting with my items I had one way of doing it and implemented that. It involved having all the item interaction in the player cpp but my lecturer James said it wasn’t a very object oriented approach so I decided to switch it up. I put the data needed for the items in txt files similarly to my rooms. I then read the data in from the files and set up each item using them.

Code

    name = file.returnTxtData(0);
    // any extra data stored in the item class;
    // any extra data stored in the item class;
    // any extra data stored in the item class;
    // any extra data stored in the item class;

The code example sample is how I did it. I used the file system I created to read the data from the file and stored it all in a vector. The ‘file.returnTxtData(0)’ then returns the data located at the part of the vector asked for which is the ‘0’. This then returns the data which should be the item name if the txt file was set-up right.

PREVIOUS BLOG POSTTEXT BASED ADVENTURE - POST MORTEM

About

Those who can do and those who can't teach games design.

Our Bunker



United Kingdom.