Hello people!!
Hoping someone can help me out with this, i have a game of life program where a grid is draw using private string[,] paintSequence = new string[50, 50]; (note i tried switching to 2d string arrays, but this caused looooads of problems so switched it all back to int 2d arrays).
Anyhow, So now the user can draw onto the grid and run the programm (what is done to the value isnt realt relative), i then want them to be able to save (sort of working) and load old grids.
So need to save this string paintSequence to a text file, i've managed to save to a text file both vertically with breakspaces, and horizontillay as just nonsererated values (see below), problem is i cant retrieve a single dimension string into a multidimension array!! :-S
My save code i now have (after trying diffrent types) is:
private void button4_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamWriter ts = new StreamWriter(saveFileDialog1.FileName);
for (int a = 0; a < paintSequence.GetLength(0); a++)
{
for (int b = 0; b < paintSequence.GetLength(1); b++)
{
ts.Write(paintSequence[a, b]);
}
}
ts.Close();
}
}
As i said this saves as horizontal, so the output is similiar to below:
1111110000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Now all i want to do is pull back the values from the text file and place them back into the 2d array paintSequence, but i keep getting the error that string cannot be converted into int[,], which makes sense as it need two values to be inserted into the 2d int array paintSequence.
Does anyone have any clues or hints on how i can accomplished this, i have literally tried everything under the blue moon to get to this point!!
One more thing, i'm not sure if the conversion to the text file is correct as their doesnt appear to be any way for the computer to know which part of the code belongs in which part of the array, so 010101010 in the text file would show on my grid as first box empty, box below first full, box below second empty, box below third is full and so on.
NOTE: Just to clarify, all i really need to do is convert the 2d array to a text file, and then retrieve the text file and put it back into a 2d array.
additional code sniplets can be added if required, THANKS IN ADVANCE!!!
:-)
Omar