Пример #1
0
        public void SetImage() //playlevel() old
        {
            int numRow = (int)Math.Sqrt((int)GameLevel.Beginner);
            int numCol = numRow;

            int unitX = Width / numRow;
            int unitY = Heigth / numCol;

            int[] indice = new int[(int)GameLevel.Beginner]; // indexes of parts of splited image

            PuzzleGame.myForm.groupboxPuzzleGetControl(groupboxpuzzle);
            PuzzleGame.myForm.clickonbutton(mybutton);

            for (int i = 0; i < (int)GameLevel.Beginner; i++)
            {
                indice[i] = i;
                if (imagePieceContainers[i] == null)
                {
                    imagePieceContainers[i] = new MyPictureBox();
                    // imagePieceContainers[i].Click += new EventHandler(); // must be on puzzle click
                    imagePieceContainers[i].BorderStyle = BorderStyle.Fixed3D;
                }
                imagePieceContainers[i].Width  = unitX;
                imagePieceContainers[i].Height = unitY;

                ((MyPictureBox)imagePieceContainers[i]).Index = i;                              //getting index of box

                CreateBitmapImage(originalImage, imagePieces, i, numRow, numCol, unitX, unitY); //dive to small images
                imagePieceContainers[i].Location = new Point(unitX * (i % numCol), unitY * (i / numCol));
                if (!groupboxpuzzle.Controls.Contains(imagePieceContainers[i]))
                {
                    groupboxpuzzle.Controls.Add(imagePieceContainers[i]); //setting location on created images
                }
            }
        }
 public void OnPuzzleClick(object sender, EventArgs e)
 {
     if (firstBox == null)
     {
         firstBox             = (MyPictureBox)sender;
         firstBox.BorderStyle = BorderStyle.FixedSingle;
     }
     else if (secondBox == null)
     {
         secondBox             = (MyPictureBox)sender;
         firstBox.BorderStyle  = BorderStyle.Fixed3D;
         secondBox.BorderStyle = BorderStyle.FixedSingle;
         SwitchImages(firstBox, secondBox);
         firstBox  = null;
         secondBox = null;
     }
     //else
     //{
     //    firstBox = secondBox;
     //    firstBox.BorderStyle = BorderStyle.Fixed3D;
     //    secondBox = (MyPictureBox)sender;
     //    secondBox.BorderStyle = BorderStyle.FixedSingle;
     //
     //}
 }
        private void PlayLevel()
        {
            int currentLevel = Globals.getLvl();

            //int currentLevel = Globals.LEVEL;

            groupBoxPuzzle.Controls.Clear();
            if (picBoxWhole != null)
            {
                groupBoxPuzzle.Controls.Remove(picBoxWhole);
                picBoxWhole.Dispose();
                picBoxWhole = null;
            }
            if (picBoxes == null)
            {
                images   = new Image[currentLevel];
                picBoxes = new PictureBox[currentLevel];
            }
            int numRow   = (int)Math.Sqrt(currentLevel);
            int numColom = numRow;
            int unitX    = groupBoxPuzzle.Width / numRow;
            int unitY    = groupBoxPuzzle.Height / numColom;

            int[] indice = new int[currentLevel];

            for (int i = 0; i < currentLevel; i++)
            {
                indice[i] = i;
                if (picBoxes[i] == null)
                {
                    picBoxes[i]             = new MyPictureBox();
                    picBoxes[i].Click      += new EventHandler(OnPuzzleClick);
                    picBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                }
                picBoxes[i].Width  = unitX;
                picBoxes[i].Height = unitY;

                ((MyPictureBox)picBoxes[i]).Index = i;
                CreateBitmapImage(image, images, i, numRow, numColom, unitX, unitY);
                picBoxes[i].Location = new Point(unitX * (i % numColom), unitY * (i / numColom));
                if (!groupBoxPuzzle.Controls.Contains(picBoxes[i]))
                {
                    ;
                }
                groupBoxPuzzle.Controls.Add(picBoxes[i]);
            }
            shuffle(ref indice);
            for (int i = 0; i < currentLevel; i++)
            {
                picBoxes[i].Image = images[indice[i]];
                ((MyPictureBox)picBoxes[i]).Imageindex = indice[i];
            }
        }
Пример #4
0
        private void SwitchImages(MyPictureBox box1, MyPictureBox box2) //replaces 2 boxs and checks for finish
        {
            int tmp = box2.ImageIndex;

            box2.Image      = images[box1.ImageIndex];
            box2.ImageIndex = box1.ImageIndex;
            box1.Image      = images[tmp];
            box1.ImageIndex = tmp;
            attemps++;
            if (isSuccessful())
            {
                MessageBox.Show("It tooks " + attemps + " swaps");
                labelStatus.Text = "Well done!";
                attemps          = 0;
            }
        }
Пример #5
0
        private void PlayLevel()
        {
            RemoveOldImageFromBoard();

            if (picBoxes == null)
            {
                images   = new Image[currentLevel];
                picBoxes = new PictureBox[currentLevel];
            }

            int numRow = (int)Math.Sqrt(currentLevel);
            int numCol = numRow;
            int unitX  = groupboxPuzzle.Width / numRow;
            int unitY  = groupboxPuzzle.Height / numCol;

            int[] indice = new int[currentLevel]; // indexes of parts of splited image

            for (int i = 0; i < currentLevel; i++)
            {
                indice[i] = i;
                if (picBoxes[i] == null)
                {
                    picBoxes[i]             = new MyPictureBox();
                    picBoxes[i].Click      += new EventHandler(OnPuzzleClick);
                    picBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                }
                picBoxes[i].Width  = unitX;
                picBoxes[i].Height = unitY;

                ((MyPictureBox)picBoxes[i]).Index = i;                             //getting index of box

                CreateBitmapImage(image, images, i, numRow, numCol, unitX, unitY); //dive to small images
                picBoxes[i].Location = new Point(unitX * (i % numCol), unitY * (i / numCol));
                if (!groupboxPuzzle.Controls.Contains(picBoxes[i]))
                {
                    groupboxPuzzle.Controls.Add(picBoxes[i]); //setting location on created images
                }
            }
            shuffle(ref indice);                   //
            for (int i = 0; i < currentLevel; i++) //setting images on position we see after shuffling
            {
                picBoxes[i].Image = images[indice[i]];
                ((MyPictureBox)picBoxes[i]).ImageIndex = indice[i];
            }
            previousLevel = currentLevel;//for checkup deleted image after end round
        }
        private void SwitchImages(MyPictureBox box1, MyPictureBox box2)
        {
            moves++;
            // timer.Start();
            //string laikas = timer.ToString();
            //timeLabel.Text = laikas;
            movesLabel.Text = "Padaryta ėjimų : " + moves.ToString();
            int tmp = box2.Imageindex;

            box2.Image      = images[box1.Imageindex];
            box2.Imageindex = box1.Imageindex;
            box1.Image      = images[tmp];
            box1.Imageindex = tmp;
            if (isSuccessful())
            {
                timer1.Enabled    = false;
                processLabel.Text = "Dėlionė sudėliota teisingai!";
            }
        }