android - Elegant way to store numerical data such as game moves -


i storing game data such sequence of moves in multi-dimensional array, defined as:

private final int[][] gamemoves = {{1},{2},{0},{3},{1,4},{1,4,5},{2,4}}  

the array of course bigger.

i feel there should more elegant way this, possibly storing data separately code using either xml file or sqlite database , retrieving in while-loop.

if using xml file, format , method of retrieval?

if using sqlite database, way data inside database before executing source code?

any examples appreciated.

if data never gets changed, there isn't reason persist it, if gets read frequently, since you'll taking performance hit in reading thereof. if anything, perhaps separate package containing game data objects each providing 'gamemoves', might winner.

or, if you're tied separation conceptual and/or requirement standpoint, json might way go, it's more directly tied multidimensional arrays xml file might be, , easier work db.

for example, json file might be:

[1, 2, 3, [45, 6, 7], 8, [9, 10]] 

you use json library parse minimal fuss:

jsonarray data = new jsonarray(textfromfile);  for(i = 0; < data.length; ++i) {     //read data } 

see http://developer.android.com/reference/org/json/jsonarray.html


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -