开发者

Qt - C++ : Using config file or XML to create objects

I am making a simple game. Consisting of several rooms where the user has to pick up an item (key, medicine, ...) in order to be able to proceed to the next room and eventually reach the reward in the final room.

The design is MVC based.

For now the Model consist of QList(Room*) and a Player*. The constructors for all the rooms, items in these rooms, the player,.. are now all hardcoded.

As an extension I would like to be able to load levels from a config or XML file.

When I now call the model singleton for the first time, it goes through the hardcoded constructors and builds up its model.

What I want is a routine that goes thro开发者_C百科ugh my XML and builds the level.

I just can't find any example of going from XML to real objects. All examples simply display data contained inside XML. There should be a more elegant way to do this then just run through the xml searching for random words.


Take a look at the question mentioned in the comment to your question or have a look at the QxNorm project which does all you want and more (persistence in a database).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜