1 min
Within my text-based adventure game I stored the data of my locations an items in text files. In order to then read in the text files into my game I wrote the implementation below. In this implementation the text files are read first into a buffer which is then streamed into a string stream. Each line of the string stream is then used as one of the arguments passed into the constructor of my Locations class. These lines are for the names of the location.
void GameScene::createLocationData()
{
Directions directions[MAP_SIZE][4] = {Directions::NONE};
createLocationDirectionData(directions);//Creates a vector of location directions
std::stringstream locations_ss;
std::string locations_line;
getFile("/data/Files/Location Data/Locations.txt", locations_ss);
int loc_count = 0;
while(getline(locations_ss, locations_line))
{
if(locations_line.back() == '\n' || locations_line.back() == '\r')
{
locations_line.resize(locations_line.size() - 1);
}
setNewLine(locations_line);
Location* new_loc = new Location(locations_line, directions[loc_count], loc_count
, loc_count != 32 && loc_count != 38 && loc_count != 43);
locations[loc_count] = new_loc;
++loc_count;
}
Subscribe to this blog via RSS.
C++ 30
Directx12 11
Mario kart 11
Commercial games development 15
Unity 15
Low-level programming (19) C++ (30) Text based adventure (5) Ex-machina (9) Game engine programming (11) Directx12 (11) Mario kart (11) Land of gold (5) Audio visual production (1) Commercial games development (15) Unity (15) Don't walk by (15)