public Form2(int level)
        {
            initial = true;
            timer1  = new Timer();
            timer2  = new Timer();
            timer3  = new Timer();

            label1 = new Label();
            label2 = new Label();
            label3 = new Label();

            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            currentHint = 0;
            gameManager = new GameManager();
            this.level  = gameManager.getLevel(level);
            g           = this.CreateGraphics();
            gameManager.initializePuzzle(level, g);
            spriteMap2 = new MapSprite(level, g);
            length     = gameManager.numberOfPuzzlePiece();
            pieceArray = gameManager.getInventoryPuzzlePieces();
            locXarray  = new int[length];
            locYarray  = new int[length];
            builder    = new MapBuilder(level);


            timer1.Start(); timer2.Start(); timer3.Start();

            if (length > 3)
            {
                for (int i = 0; i < length - 3; i++)
                {
                    locYarray[i] = 400;
                }
                for (int i = length - 3; i < length; i++)
                {
                    locYarray[i] = 500;
                }
                for (int i = 0; i < length - 3; i++)
                {
                    locXarray[i] += i * 300;
                }
                for (int i = length - 3; i < length; i++)
                {
                    locXarray[i] += (i - (length - 3)) * 300;
                }
            }
            else
            {
                for (int i = 0; i < length; i++)
                {
                    locYarray[i] = 400;
                }
                for (int i = 0; i < length; i++)
                {
                    locXarray[i] += i * 300;
                }
            }



            sprite1       = new Sprite2[length];
            selectedPiece = 30;
            for (int i = 0; i < length; i++)
            {
                sprite1[i] = new Sprite2(locXarray[i], locYarray[i], 60, pieceArray[i]);
            }



            InitializeComponent();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            currentHint = 0;
            spriteMap2  = new MapSprite(level, g);
            length      = gameManager.numberOfPuzzlePiece();
            pieceArray  = gameManager.getInventoryPuzzlePieces();
            locXarray   = new int[length];
            locYarray   = new int[length];
            builder     = new MapBuilder(level);
            timer1      = new Timer();
            timer2      = new Timer();
            timer3      = new Timer();

            Form1_Load(sender, formE);

            timer1.Start(); timer2.Start(); timer3.Start();
            if (length > 3)
            {
                for (int i = 0; i < length - 3; i++)
                {
                    locYarray[i] = 400;
                }
                for (int i = length - 3; i < length; i++)
                {
                    locYarray[i] = 500;
                }
                for (int i = 0; i < length - 3; i++)
                {
                    locXarray[i] += i * 300;
                }
                for (int i = length - 3; i < length; i++)
                {
                    locXarray[i] += (i - (length - 3)) * 300;
                }
            }
            else
            {
                for (int i = 0; i < length; i++)
                {
                    locYarray[i] = 400;
                }
                for (int i = 0; i < length; i++)
                {
                    locXarray[i] += i * 300;
                }
            }



            for (int i = 0; i < sprite1.Length; i++)
            {
                sprite1[i].setLocX(locXarray[i]);
                sprite1[i].setLocY(locYarray[i]);
            }

            Invalidate();


            sprite1       = new Sprite2[length];
            selectedPiece = 30;
            for (int i = 0; i < length; i++)
            {
                sprite1[i] = new Sprite2(locXarray[i], locYarray[i], 60, pieceArray[i]);
            }
        }
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            bool       allAvailable = true;
            bool       done         = false;
            MapBuilder mapa         = new MapBuilder(level);

            int[,] arrr = mapa.getMapArray();

            if (selectedPiece < length)
            {
                int d = (sprite1[selectedPiece].getLocX()) / 60;
                int f = (sprite1[selectedPiece].getLocY()) / 60;

                int x1 = (int)d;
                int y1 = (int)f;

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (sprite1[selectedPiece].pieceArray[i, j] && f < 5 && d < 11)
                        {
                            if (arrr[f, d] == -1)
                            {
                                allAvailable = true;
                            }
                            else
                            {
                                allAvailable = false;
                                break;
                            }
                            if (!allAvailable)
                            {
                                break;
                            }
                        }

                        d++;
                    }

                    d = d - 4;
                    if (!allAvailable)
                    {
                        break;
                    }

                    f++;
                }

                if (!allAvailable && selectedPiece < length)
                {
                    sprite1[selectedPiece].setLocX(locXarray[selectedPiece]);
                    sprite1[selectedPiece].setLocY(locYarray[selectedPiece]);
                }
                else
                {
                    sprite1[selectedPiece].setLocX(x1 * 60);
                    sprite1[selectedPiece].setLocY(y1 * 60);

                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            if (sprite1[selectedPiece].pieceArray[j, i] && (x1 + i) < 11 && (y1 + j) < 5)
                            {
                                spriteMap2.arr[(y1 + j), (x1 + i)] = sprite1[selectedPiece].ID;
                            }
                        }
                    }
                    if (e.X > 660 || e.Y > 300)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 11; j++)
                            {
                                if (spriteMap2.arr[i, j] == sprite1[selectedPiece].ID)
                                {
                                    spriteMap2.arr[i, j] = -1;
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    Console.Write(" | " + spriteMap2.arr[i, j]);
                }
                Console.WriteLine();
            }

            if (selectedPiece < length)
            {
                Region rgn = new Region(sprite1[selectedPiece].gp);
                rgn.Union(sprite1[selectedPiece].gp);
                Invalidate(rgn, false);
                panel1.Invalidate();
                sprite1[selectedPiece].draw(g);
            }

            dragging = false;
            if (isGameOver(spriteMap2.arr))
            {
                int      nLevel = level++;
                string   s      = label1.Text + " : " + label2.Text + " : " + label3.Text;
                GameOver gOver  = new GameOver(nLevel, s);
                gOver.Show();
                this.Hide();
            }
        }