0

I try to create a simple game and I wonder to what is the best solution to manage data in android. For example I have a simple game. A map of single a level is 2 dimensional array 3x3. On this map i have for example 3 kinds of objects: yellow circle, red circle, green circle. And I have more than 1000 levels. So what is the best solution to keep this level data?

1) I can create arrays for all levels in code:

String[][] level1 = new String[][]{{"y","b","g",}...}
...
String[][] level1000 = new String[][]{{"y","b","g",}...}

2) Or i can put it to some resource .xml file but how to keep it? In this resource file i can't create 2D array :/

Other question for this it is better to load all data at the beginning and put it to the some cache or load only when i needed data to the specific level?

What do you think?

cwiq
  • 105
  • 2
  • 15
miosz
  • 143
  • 1
  • 4
  • 13

1 Answers1

1

You can use json formatted text file. You can save it in raw folder and whenever you need you can call it. Json parsing is too easy and you can find easily specific level. See this link for information.

  • Ok it's a good idea, but what about performance? Beeter is load file from json or load some resources file.xml? – miosz May 18 '18 at 05:06
  • Json is much better than xml. There is an answer for more information. See [this](https://stackoverflow.com/a/10026513/7816750) – Batuhan Orhan May 18 '18 at 08:50