I am trying to make a text-only dungeon crawler game.

The general structure for the game is in place (ie. a 'Level' is a 16x16 grid of 'Rooms').

#pragma once
#include <string>

class RoomData
    bool isRoom;
    std::string title;
    std::string description;
    int items;
    int exits;

I can move around the map with my Player class. After a 'Move' is made, the console prints the title and description from the Room.

But so far, I have to hardcode the level design in my C++ code.

Armed with my current knowledge only, I am having to externally draw my map in art software and manually write notes for each cell (0,0 ; 0,1 ; etc) and then when I create my std::vector<Room> I manually fill it with all the necessary data. Even for 16x16 map size this takes a very long time and mistakes are hard to spot (if I miss a cell in the middle for example).

I want to use my RoomData class (above) and then I want to make my Level class take input from a Text File and automatically populate my vector with the rooms in order.

Please can someone help me find ways to do this, I honestly have been trying this forever over many projects but I always end up hardcoding.


1 Answer 1


I would recommend to use a standard markup format like XML, YAML or JSON for your files. There are plenty of C++ libraries available for each of them which make converting between text files and C++ objects a breeze.

You can use a text editor to edit those files. Most more advanced text editors have syntax highlighting rules for each of these which should catch the most egregious typos.

But when you intend to invest quite a lot of time into creating content for your game, then it might make sense to develop an own level editor as a separate UI application. Whether or not that's worth it depends on how much time it would cost you to develop it, which depends on how much you already know about UI development. And of course on how much time it would save you during the creation of all the content. This is a cost/benefit calculation you have to do by yourself, because I know neither your skillset nor the scope of your game.

  • \$\begingroup\$ Hi Phillip thanks for the speedy answer. I do intend to create a level editor. I have an idea exactly how I would like my text output to be formatted. Ie) separate variables by commas, and entire rooms by semi-colon. What first step should I make to creating my own tool for this? I want a very rudimental grid which I can click a cell and input some text fields. Perhaps I could even use Excel or similar lol. But I am very interested to learn the tool creation. Would it take me forever, because I'd love to learn it I have been tinkering making games for years but always end up hardcoding levels. \$\endgroup\$ Aug 19, 2021 at 14:32
  • \$\begingroup\$ I've only ever coded simple games. I feel it is time to move up into this. I guess I could use any language to build this tool. I suppose I can even use Unity and C#, so long as it outputs the text file properly \$\endgroup\$ Aug 19, 2021 at 14:35
  • \$\begingroup\$ @I_Keep_Trying There are plenty of UI frameworks for C++. And you are not even limited to C++. There is no reason why the level editor has to be written in the same language as the game. So the whole world of UI development technologies is open to you. There are so many technologies to choose from that I can not really give a definitive recommendation. The only recommendation I can give to you is to not create your own file format but use a library for an existing markup language. Writing string parsers for file formats is not much fun. \$\endgroup\$
    – Philipp
    Aug 19, 2021 at 14:35
  • 1
    \$\begingroup\$ I suppose you could create a level editor for an entirely different game in Unity, but I would really not recommend it. There are many more appropriate technologies for stuff like that. If you want to learn C#, then you could take a look at the Windows Presentation Framework. \$\endgroup\$
    – Philipp
    Aug 19, 2021 at 14:36
  • \$\begingroup\$ ok thanks phillip. I am gonna make it using Unity for starters :D ... But how about I just output as .txt. In past I was easily about to parse in the .txt and separate it using if statements. I also remember having trouble with JSON once or twice. But if you think JSON is more suitable than TXT ill keep that in mind when I delve in to make it (Also Ill check out Windows Presentation Framework) thing is in Unity I already now how to handle graphics, mouse input, text outputs etc \$\endgroup\$ Aug 19, 2021 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .