Help with reading/writing int to text file

Hi all wonder if you can give me a bit of help. I've created a windows application version of conway's game of life in c#. I want to be able to save and load a grid pattern that the user paints on the grid. I think i have the grid pattern being saved correctly into a text file with this code:
[code]
void saveMyData()
{
StreamWriter fWriter = File.CreateText(@C:TempmyData.txt);

int cellRow = 0;
while (cellRow < this.maxRow)
{
int cellCol = 0;
while (cellCol < this.maxCol)
{
int cellStatus = 0;
if (this.cellLife[cellCol, cellRow] == true)
{
cellStatus = 1;
}
if (this.cellLife[cellCol, cellRow] == false)
{
cellStatus = 0;
}
fWriter.WriteLine(cellStatus);
cellCol++;
}
cellRow++;
}
fWriter.Close();
}
[/code]

However doing the opposite and loading this data back in and re-painting the grid pattern saved in the text file, is proving to be rather tricky! I have this piece of code which i believes reads in the text file, but where i'm struggling is to paint the grid pattern from this data, so any help would be much appreciated!

[code]
void loadMyData()
{
string text;

StreamReader s = File.OpenText(@C:TempmyData.txt);
do
{
text = s.ReadLine();
}
while (text != null);
int numVal = Int32.Parse(text);
if (numVal == 0)
{
this.cellLife[1, 1] = true;
}
s.Close();

}
[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories