public int Start(List <IStep> steps) { flakes.Add(SnowFlake.BuildFlake(flakes)); flakes.Add(SnowFlake.BuildFlake(flakes)); _steps = steps; t1 = new Thread(Render); t1.Start(); return(ModelHelper.period * NbrOfCycle * 2); }
public void Render() { for (int cycle = 0; cycle < NbrOfCycle; cycle++) { flakes.Add(SnowFlake.BuildFlake(flakes)); List <SnowFlake> incrementY = new List <SnowFlake>(); bool[,] datas = new bool[40, 16]; for (int j = 0; j < 16; j++) { for (int i = 0; i < 40; i++) { var elligible = flakes.Where(f => f.PositionX == i); if (elligible.Any()) { var elligible2 = elligible.Where(f2 => { int min = f2.PositionY - f2.TTL; int max = f2.PositionY; return(j > min && j <= max); }); if (elligible2.Any()) { datas[i, j] = true; incrementY.AddRange(elligible2); } } } } incrementY.ToList().ForEach(i => i.PositionY++); List <SnowFlake> dead = flakes.Where(f => f.PositionY > 16).ToList(); dead.ForEach(d => flakes.Remove(d)); var line1 = HelperMatriceListConvertor.ConvertToList(datas); _steps.ForEach(x => x.Apply(line1)); Thread.Sleep(ModelHelper.period * 2); } }
public static SnowFlake BuildFlake(List <SnowFlake> l) { SnowFlake f = new SnowFlake(); f.PositionY = 0; bool trouve = false; do { int x = randomX.Next(0, 39); var contains = l.Where(z => z.PositionX == x); if (!contains.Any()) { f.PositionX = x; trouve = true; } } while (!trouve); f.TTL = randomTTL.Next(2, 5); return(f); }