Ejemplo n.º 1
0
        public async void Generate()
        {
            int   x     = 0;
            int   y     = 0;
            ulong uniX  = 0;
            ulong uniY  = 0;
            int   count = 0;

            while (x < LifeSize & y < LifeSize)
            {
                Task <bool> t = GenerateLife();
                await       t;
                Universe    acc = new Universe()
                {
                    VerticalAlignment   = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Height = UniverseCellSize,
                    Width  = UniverseCellSize,
                    Margin = new Thickness(x, y, 0, 0),
                    Name   = "Universe" + count.ToString(),
                    X      = uniX,
                    Y      = uniY,
                    ID     = count
                };
                switch (t.Result)
                {
                case true:
                    acc.Born();
                    break;

                case false:
                    acc.Die();
                    break;
                }
                ;
                Universes.Add(acc);

                Log.Information("[Matrix][Generate] Added Universe(" + (t.Result?"alive":"dead") + ") at " + x.ToString() + "," + y.ToString() + " -- #" + count.ToString() + " --- Coords X: " + uniX + " Y: " + uniY);
                await GenerateLife();

                count -= -1;
                uniX  += 1;
                x     -= -UniverseCellSize;
                if (x >= LifeSize & y <= LifeSize)
                {
                    x     = 0;
                    y    -= -UniverseCellSize;
                    uniY += 1;
                    uniX  = 0;
                }
            }
            Universes.All(u => { this.RefGrid.Children.Add(u); return(true); });

            this.RefGrid.Children.Remove((UIElement)(this.RefGrid.Children.OfType <object>().Where(b => b.GetType().Equals(typeof(Label))).FirstOrDefault()));
            IsMatrixReady = true;
            Log.Information(new string('=', 50));
            Log.Information("[Matrix][Generate] Generated " + Universes.Count.ToString() + " universes in total.");
            Log.Information("[Matrix][Generate] Generation complete!");
            Log.Information(new string('=', 50));
        }