views:

2960

answers:

2

Hello all,

I am currently working on a group project to build an Android game. I have been delegated the task of building a PC based level editor (which is all done).

All I have to do now is decide on the file format for the map that is outputted. At the moment it is just a standard text file with different numbers to represent different tiles; E.G 0=path 1=wall 2=enemy.

1 1 1 1 1 1 1 1
1 0 0 0 2 0 0 1
1 1 1 1 1 1 1 1

The actual Android game then takes this file and stores the values into a 2D Array. However those who are making the actual game are having difficulty opening a text file, and others have told me it has to be done using an XML file. I have now been asked to find a away to take in this input.

Could someone tell me how I would read the text file and put the values into a int array[][] ? Or if it is easier, use an XML file and tell me how to format that file and read the values into a int array[][]

Any help would be appreciated as I didn't learn how to use Android so I find this quite difficult.

Many thanks/

+1  A: 

I wouldn't use an xml for that.

I would choose between this two options: Check this first.

Text File

Add the file to /res/raw and read it from there.

Here you have an example code of how to read it.

Serialized structure

You might want to serialize all the int array[][] and save it in /res/raw.

Macarse
+1  A: 

Check out this tutorial on Using XmlResourceParser to Parse Custom Compiled XML. This involves creating custom XML placed in /res/xml and using XmlResourceParser to parse through the custom XML.

Hope that helps.

Jeffrey