private void SwapPuzzles(PuzzlePictureBox puzzleBox, PuzzlePictureBox swapPuzzleBox) { var swapCell = swapPuzzleBox.Cell; var swapLoc = swapPuzzleBox.Location; swapPuzzleBox.Cell = puzzleBox.Cell; swapPuzzleBox.Location = puzzleBox.Location; puzzleBox.Cell = swapCell; puzzleBox.Location = swapLoc; }
/// <summary> /// Returns valid cell position for current location of puzzlebox. /// If position is outside of panel returns null. /// </summary> private Point?GetCellForCurrentPos(PuzzlePictureBox puzzleBox) { var cell = new Point( (puzzleBox.Left - panelImages.Left + puzzleSizeX / 2) / puzzleSizeX, (puzzleBox.Top - panelImages.Top + puzzleSizeX / 2) / puzzleSizeX); if (cell.X < 0 || cell.X >= puzzleNumX || cell.Y < 0 || cell.Y >= puzzleNumX) { return(null); } return(cell); }
private bool RotateAndCheckAllDirections(PuzzlePictureBox puzzleBox) { for (var i = 0; i < (int)PuzzlePictureBox.DirectionType.Count; i++) { if (CheckIsPuzzleCorrect(puzzleBox)) { return(true); } puzzleBox.RotateClockWise(1); RedrawUI(); } return(false); }
private void SliceInputImage() { try { puzzleNumX = (int)numericUpDownSize.Value; puzzleSizeX = sizeWholeImage / puzzleNumX; panelImages.Width = puzzleSizeX * puzzleNumX; panelImages.Height = puzzleSizeX * puzzleNumX; rotationEnabled = checkBoxRotate.Checked; var random = new Random(); var cellsList = new List <Point>(); for (var x = 0; x < puzzleNumX; x++) { for (var y = 0; y < puzzleNumX; y++) { cellsList.Add(new Point(x, y)); } } // randomize list cellsList = cellsList.OrderBy(x => random.Next()).ToList(); var index = 0; for (var x = 0; x < puzzleNumX; x++) { for (var y = 0; y < puzzleNumX; y++) { var puzzleBox = new PuzzlePictureBox(new Point(x, y), PuzzlePictureBox.DirectionType.Up); puzzleBox.Image = GetPartOfImage(x * puzzleSizeX, y * puzzleSizeX); puzzleBoxesCollection.Add(puzzleBox); var cell = cellsList[index]; var rotation = (uint)random.Next(); InitPuzzleBox(puzzleBox, cell.X, cell.Y, rotation); index++; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void InitPuzzleBox(PuzzlePictureBox puzzleBox, int x, int y, uint rotation) { Controls.Add(puzzleBox); puzzleBox.BringToFront(); puzzleBox.Location = panelImages.Location + new Size(x * puzzleSizeX, y * puzzleSizeX); puzzleBox.Size = new Size(puzzleSizeX, puzzleSizeX); puzzleBox.SizeMode = PictureBoxSizeMode.Zoom; puzzleBox.BorderStyle = BorderStyle.Fixed3D; puzzleBox.Cell = new Point(x, y); if (rotationEnabled) { puzzleBox.RotateClockWise(rotation); } puzzleBox.MouseDown += pictureBoxMouseDown; }
private bool CheckIsPuzzleCorrect(PuzzlePictureBox puzzleBox) { return(puzzleBox.IsCorrectPlace()); }