As a personnal work, i have to do a forest fire simulation in WPF.
I created all the map with a grid, and using an array. The Fire is added through a random number ( in the array when ex : case = " Forest "). The Fire is burning all the " forest case " and it depends on the wind ( N S E W, etc. ). Everything is working fine !
But i encounter a minor problem through the "fire loop". I mean, when i click on my button ' fire progress " ( which does the fire expansion ) all the forest case burns in a simultaneous way. ( the direction is correct, only the case with the right direction burns, the problem is not here ).
I wanted to cooldown this loop as each case after case will be burned, such as :
Case forest burns. Wait. Case forest 2 burns. And so on. And not all the cases in the right directions ( of the wind ).
I tried to use a dispatcher timer (TimeSpan ). But with no success. The only thing's working is the results of the loop is slowdown ( in seconds, milliseconds, days, whatever ). BUT all the cases changes in a same time. And not one by one.
Apologies if my english is not grammatically correct !
Here is my code :
private void DeclencherLeFeu()
{
TempsDuJeu = new DispatcherTimer();
TempsDuJeu.Interval = TimeSpan.FromSeconds(1);
TempsDuJeu.Tick += new EventHandler(OnTimerGameEvent);
TempsDuJeu.Start();
TempsQueMetLeFeuPourBrulerLaForet = new DispatcherTimer();
TempsQueMetLeFeuPourBrulerLaForet.Interval = TimeSpan.FromSeconds(8);
TempsQueMetLeFeuPourBrulerLaForet.Tick += new EventHandler(LesArbresSontCalcines);
TempsQueMetLeFeuPourBrulerLaForet.Start();
}
Note : LesArbresSontCalcines means in english that the trees are burned. It calls a function just as below :
private void LesArbresSontCalcines(object sender, EventArgs e)
{
for (int i = 0; i < 7; i++)
{
for (int j = 1; j < 10; j++)
{
if (MonTableau[i, j].Name == "Feu")
{
MonTableau[i, j].Source = new BitmapImage(new Uri(@"E:\tp999\wpfapplication13\wpfapplication13\ArbreMort1.gif", UriKind.RelativeOrAbsolute));
ImageBehavior.SetAnimatedSource(MonTableau[i, j], new BitmapImage(new Uri(@"E:\tp999\wpfapplication13\wpfapplication13\ArbreMort1.gif", UriKind.RelativeOrAbsolute)));
MonTableau[i, j].Name = "Noir";
}
}
}
}
Note : All the burning cases ( i use a fire.gif on the forest case ) are replacing with the ArbreMort1.gif (represents a blacked tree ).
In this part of my code, all the burning cases just change, in a same time, as a dead tree. And Not one by one.
I tried to do that the first burning case will be the first be darked ( with the ArbreMort1.gif) and so on till the ending burning case ( that will be the last to be transformed ).
How should i use this dispatcher timer ?
Thank you for your replies ! :)