0

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 through 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.

user558802
  • 51
  • 1
  • 6
  • What do you mean when you say "going from XML to real objects" ? Taking the info in an xml tree and making an object with it ? – dotminic Dec 30 '10 at 23:24
  • Exactly! What would be the routine to parse the XML and "dynamically" create the objects whilst at it. I know that it might sound as a fairly easy question, but i'm really looking for an efficient solution. – user558802 Dec 30 '10 at 23:28
  • 2
    Take a look at this question http://stackoverflow.com/questions/2570679/serialization-with-qt. You can easily adapt it to XML/whatever files if you want to. – Eugen Constantin Dinca Dec 31 '10 at 00:04

1 Answers1

0

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).

hmuelner
  • 8,093
  • 1
  • 28
  • 39