Methods for storing level data (hierarchy of data) for a java game



Like 90% of the beginner programmers here, I am working on a relatively comprehensive Java game which emulate's a puzzle game called "Chocolate Fix" by ThinkFun (I'm doing it for the challenge) Here is a link to how the game works


Each level has a Solution and Multiple Clues. Each Solution and Clue has to have data for a 3x3 grid. At the moment I have a 36,000 line XML document which I automatically generated with a series of nested for-loops. The XML Document structure looks like this:



<Level Difficulty="Beginner" id="0">
<Solution>
<Piece x="0" y="0">
<Color>P</Color>
<Shape>C</Shape>
</Piece>
<Piece x="0" y="1">
<Color>T</Color>
<Shape>C</Shape>
</Piece>
<Piece x="0" y="2">
<Color>B</Color>
<Shape>C</Shape>
</Piece>
<Piece x="1" y="0">
<Color>B</Color>
<Shape>S</Shape>
</Piece>
<Piece x="1" y="1">
<Color>T</Color>
<Shape>T</Shape>
</Piece>
<Piece x="1" y="2">
<Color>P</Color>
<Shape>S</Shape>
</Piece>
<Piece x="2" y="0">
<Color>P</Color>
<Shape>T</Shape>
</Piece>
<Piece x="2" y="1">
<Color>B</Color>
<Shape>T</Shape>
</Piece>
<Piece x="2" y="2">
<Color>T</Color>
<Shape>S</Shape>
</Piece>
</Solution>
<Clues>
<Clue id="3">
<Piece c="0" r="0">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="1" r="0">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="2" r="0">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="0" r="1">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="1" r="1">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="2" r="1">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="0" r="2">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="1" r="2">
<Color></Color>
<Shape></Shape>
</Piece>
<Piece c="2" r="2">
<Color></Color>
<Shape></Shape>
</Piece>
</Clue>
</Clues>
</Level>


My questions regarding holding this data are as follows:



  • Is there a better method to store this kind of nested data?

  • I need to use this in my program and at the moment I am using JAXB Unmarshalling to move the data into multiple ArrayLists (one for Levels > Level > Solution > etc.) then creating thousands of Piece objects which can take on multiple shapes, colors, and positions.

  • I have heard about some other options which I don't know very much about: SQLite, Java Maps, and even custom written text documents with level data.


I would just like some advice/suggestions on how to best store then implement the level data then use it in the game. I don't entirely know what caching is, but would that even be an option.


Thanks in advanced and I am more than open to changing how I program (I want to avoid bad habits and learn to be efficient with data).


No comments:

Post a Comment