I’m working on a windows phone 7 game and I have saved the levels in a text file and i want to load it into a 2D array but there is no content importer for txt files, I have used the isolated storage manager
protected void read_lvl()
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{ //Visualize the text data in a TextBlock text
while (!reader.EndOfStream)
{
//for each row
for (int i = 0; i < rows; i++)
{
//read in the line
string myLine = reader.ReadLine();
//take out the commas
string[] row = myLine.Split(',');
//convert to string to ints
//and feed back into array
int[] nRow = new int[row.Length];
for(int r=0; r<columns;r++){
nRow[r] =Convert.ToInt32(row[r]);
myreadArray[i, r] = nRow[r];
}
}
}
}
}
Which is fine for loading a saved game state etc
But I want to have multiple levels in multiple .txt files and have tried using this instead:
//stream from file
Stream stream = TitleContainer.OpenStream("myFile.txt");
//make a stream reader from the stream
using (StreamReader sreader = new StreamReader(stream))
But its throwing the same error : There are no importers which handle this file type.
what do?
Don’t know if this will help you but this is how I load game maps into my game (x and y are my grid coordinates):