public static void RenderingGeneric(bool[,] datas, List <IStep> stp)
        {
            log(datas);

            int max = datas.GetLength(0);

            if (max > Definition.Number_Led_X_total)
            {
                int nbrIncrement = max - Definition.Number_Led_X_total;

                for (int increment = 0; increment <= nbrIncrement; increment++)
                {
                    bool[,] current = ModelHelper.Extract(datas, increment, 0, Definition.Number_Led_X_total,
                                                          Definition.Number_Led_Y_total);


                    List <bool[, ]> dico = HelperMatriceListConvertor.ConvertToList(current);

                    stp.ForEach(s => s.Apply(dico));
                    Thread.Sleep(period);

                    Thread.Sleep(period * 2);
                }
            }
            else
            {
                //TODO centrer
            }
        }
        public void ShiftRightClick()
        {
            var screen = _vmlayout.ReadScreen();

            var matrice = HelperMatriceListConvertor.ConvertToMatrice(screen);

            bool[,] newmatrice = new bool[40, 16];


            for (int i = 0; i < 39; i++)
            {
                newmatrice[i + 1, 0]  = matrice[i, 0];
                newmatrice[i + 1, 1]  = matrice[i, 1];
                newmatrice[i + 1, 2]  = matrice[i, 2];
                newmatrice[i + 1, 3]  = matrice[i, 3];
                newmatrice[i + 1, 4]  = matrice[i, 4];
                newmatrice[i + 1, 5]  = matrice[i, 5];
                newmatrice[i + 1, 6]  = matrice[i, 6];
                newmatrice[i + 1, 7]  = matrice[i, 7];
                newmatrice[i + 1, 8]  = matrice[i, 8];
                newmatrice[i + 1, 9]  = matrice[i, 9];
                newmatrice[i + 1, 10] = matrice[i, 10];
                newmatrice[i + 1, 11] = matrice[i, 11];
                newmatrice[i + 1, 12] = matrice[i, 12];
                newmatrice[i + 1, 13] = matrice[i, 13];
                newmatrice[i + 1, 14] = matrice[i, 14];
                newmatrice[i + 1, 15] = matrice[i, 15];
            }


            _vmlayout.Apply(HelperMatriceListConvertor.ConvertToList(newmatrice));
        }
        public void Render()
        {
            //bool[,] datas = new bool[40, 16];
            Dictionary <int, KeyValuePair <int, int> > dico = new Dictionary <int, KeyValuePair <int, int> >();
            int id = 1;

            for (int j = 0; j < 16; j++)
            {
                for (int i = 0; i < 40; i++)
                {
                    dico.Add(id, new KeyValuePair <int, int>(i, j));
                    id++;
                }
            }
            var all = HelperMatriceListConvertor.ConvertToList(BuildMatrice(dico));

            _steps.ForEach(x => x.Apply(all));



            for (int cycle = 0; cycle < 40 * 16 / 2; cycle++)
            {
                int x1 = FindNewOne(dico);
                if (x1 > 0)
                {
                    dico.Remove(x1);
                }

                int x2 = FindNewOne(dico);
                if (x2 > 0)
                {
                    dico.Remove(x2);
                }

                int x3 = FindNewOne(dico);
                if (x3 > 0)
                {
                    dico.Remove(x3);
                }

                all = HelperMatriceListConvertor.ConvertToList(BuildMatrice(dico));
                _steps.ForEach(s => s.Apply(all));

                Thread.Sleep(ModelHelper.period);

                if (dico.Count == 0)
                {
                    continue;
                }
            }
        }
        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);
            }
        }
Example #5
0
        private void ImportClick()
        {
            OpenFileDialog f        = new OpenFileDialog();
            var            result   = f.ShowDialog();
            string         fullpath = @"e:\g.png";

            if (result == false)
            {
                return;
            }
            fullpath = f.FileName;


            var original = Image.FromFile(fullpath);

            original = ResizePicture(original, 40, 16);
            Bitmap bmp       = new Bitmap(original);
            var    rectangle = new Rectangle(0, 0, original.Width, original.Height);
            var    bmp1bpp   = bmp.Clone(rectangle, PixelFormat.Format1bppIndexed);

            bmp1bpp.Save(@"e:\image.bmp");
            bool[,] datas = new bool[40, 16];
            for (int i = 0; i < bmp1bpp.Width; i++)
            {
                string line = string.Empty;
                for (int j = 0; j < bmp1bpp.Height; j++)
                {
                    Color pixel = bmp1bpp.GetPixel(i, j);
                    bool  r     = !((pixel.R == Color.White.R) && (pixel.G == Color.White.G) && (pixel.B == Color.White.B));
                    line       += r ? "x" : "_";
                    datas[i, j] = r;
                }
                line += Environment.NewLine;
            }
            ModelHelper.log(datas);

            var line1 = HelperMatriceListConvertor.ConvertToList(datas);

            steps.ForEach(x => x.Apply(line1));
            ModelHelper.log(line1);
        }
        public void Render()
        {
            snake.Add(new Position(4, 7));
            snake.Add(new Position(3, 7));
            snake.Add(new Position(2, 7));
            snake.Add(new Position(1, 7));
            snake.Add(new Position(0, 7));
            currentSaut = randomX.Next(2, 6);

            for (int cycle = 0; cycle < NbrOfCycle; cycle++)
            {
                EDirection dir = EDirection.Undefine;
                cpt++;
                if (cpt == currentSaut)
                {
                    cpt         = 0;
                    currentSaut = randomX.Next(2, 6);
                    dir         = GetNextDirection(snake[0], snakeDirection);
                }
                else
                {
                    if (snake[0].IsACorner())
                    {
                        dir = GetNextDirection(snake[0], snakeDirection);
                    }
                    else
                    {
                        dir = snakeDirection;
                        /**************/
                        if (snake[0].Y == 0 && snakeDirection == EDirection.Haut)
                        {
                            dir = GetNextDirection(snake[0], snakeDirection);
                        }

                        if (snake[0].Y == 15 && snakeDirection == EDirection.Bas)
                        {
                            dir = GetNextDirection(snake[0], snakeDirection);
                        }

                        if (snake[0].X == 0 && snakeDirection == EDirection.Gauche)
                        {
                            dir = GetNextDirection(snake[0], snakeDirection);
                        }

                        if (snake[0].X == 39 && snakeDirection == EDirection.Droite)
                        {
                            dir = GetNextDirection(snake[0], snakeDirection);
                        }
                        /************/
                    }
                }

                bool[,] datas = new bool[40, 16];


                Position newHead = null;
                switch (dir)
                {
                case EDirection.Bas:
                    newHead = new Position(snake[0].X, snake[0].Y + 1);
                    break;

                case EDirection.Droite:
                    newHead = new Position(snake[0].X + 1, snake[0].Y);
                    break;

                case EDirection.Gauche:
                    newHead = new Position(snake[0].X - 1, snake[0].Y);
                    break;

                case EDirection.Haut:
                    newHead = new Position(snake[0].X, snake[0].Y - 1);
                    break;
                }
                if (newHead.X == 40 || newHead.X == -1 || newHead.Y == 16 || newHead.Y == -1)
                {
                }
                snakeDirection = dir;

                List <Position> newSnake = new List <Position> {
                    newHead, snake[0], snake[1], snake[2], snake[3]
                };
                snake = newSnake;
                datas = NewGrid(snake, datas);
                var line1 = HelperMatriceListConvertor.ConvertToList(datas);

                _steps.ForEach(x => x.Apply(line1));

                Thread.Sleep(ModelHelper.period);
            }
        }