I get the application mozayka, but here is something the algorithm does not work well. Gives a message about the folding of the picture, even when the picture is not folded

Here is the folding code and a full match check:

void PB_Click(object sender, EventArgs e) { PictureBox pb = (PictureBox)sender; for (int i = 0; i < PB.Length; i++) { // Π‘Π½Π°Ρ‡Π°Π»Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΠΌ пустоС мСсто Π½Π° области рисования ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. if (PB[i].Visible == false) { // Π—Π°Ρ‚Π΅ΠΌ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΠΌ ΠΊΠ»ΠΈΠΊΠ½ΡƒΡ‚Ρ‹ΠΉ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ ΠΈ // Ссли Ρƒ Π½Π΅Π³ΠΎ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ ΠΏΠΎ X ΠΈΠ»ΠΈ Y, // (ΠΎΡ‚ΠΊΠΈΠ΄Ρ‹Π²Π°Π΅ΠΌ ΠΈΠ· вычислСния ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΈ располоТСннныС ΠΏΠΎ Π΄ΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈ) // Π½ΠΎ ΠΏΡ€ΠΈ этом ΠΎΠ½ Π½Π° блиТайшСм расстоянии ΠΎΡ‚ пустого // ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° // (ΠΎΡ‚ΠΊΠΈΠ΄Ρ‹Π²Π°Π΅ΠΌ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΈ располоТСнныС Ρ‡Π΅Ρ€Π΅Π· ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ ΠΎΡ‚ пустого) if ((pb.Location.X == PB[i].Location.X && Math.Abs(pb.Location.Y - PB[i].Location.Y) == PB[i].Height) || (pb.Location.Y == PB[i].Location.Y && Math.Abs(pb.Location.X - PB[i].Location.X) == PB[i].Width)) { // ПослС ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΉ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ // мСняСм мСстами пустой ΠΈ ΠΊΠ»ΠΈΠΊΠ½ΡƒΡ‚Ρ‹ΠΉ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΈ. Point pt = PB[i].Location; PB[i].Location = pb.Location; pb.Location = pt; // ПослС ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ…ΠΎΠ΄Π° ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π½Π° ΠΏΠΎΠ»Π½ΡƒΡŽ сборку ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. //*************** Π±Π»ΠΎΠΊ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ *********************** // Если Ρ…ΠΎΡ‚ΡŒ Ρƒ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° Π½Π΅ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚ // Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ ΠΈ ΠΏΠ΅Ρ€Π²ΠΈΡ‡Π½Ρ‹Π΅ Π²Ρ‹Ρ…ΠΎΠ΄ΠΈΠΌ ΠΈΠ· Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ. for (int j = 0; j < PB.Length; j++) { Point point = (Point)PB[i].Tag; if (PB[j].Location != point) { //MessageBox.Show(this, point + "x" + PB[j].Location.ToString(), "Data"); Debug.WriteLine(point + "x" + PB[j].Location.ToString()); return; } } // Если Ρƒ всСх ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΎΠ² совпали Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΈ ΠΏΠ΅Ρ€Π²ΠΈΡ‡Π½Ρ‹Π΅ // ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ - ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° собрана! for (int m = 0; m < PB.Length; m++) { PB[m].Visible = true; PB[m].BorderStyle = BorderStyle.None; // ΡƒΠ±ΠΈΡ€Π°Π΅ΠΌ ΠΎΠ±Ρ€Π°ΠΌΠ»Π΅Π½ΠΈΠ΅ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΎΠ² Properties.Settings.Default.LevelCompleted = true; MessageBox.Show(this, "ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° собрана!", "ПобСда", MessageBoxButtons.OK, MessageBoxIcon.Information); } //************** ΠΎΠΊΠΎΠ½Ρ‡Π°Π½ΠΈΠ΅ Π±Π»ΠΎΠΊΠ° ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ************* } break; } } } 

Here is the project: http://www.interestprograms.ru/sources/csharp/files/sourcemosaic.rar It is necessary to display a message when the picture is collected. The message displays even when the picture is not collected. Most likely due to the incorrect verification of coordinates for folding and checking the image composure.

  • add in the last for the condition of collection. Properties.Settings.Default.LevelCompleted = true; MessageBox.Show(this, "ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° собрана!" Properties.Settings.Default.LevelCompleted = true; MessageBox.Show(this, "ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° собрана!" Always works - codename0082016
  • one
    +1 for the word "mozayka" - Igor
  • @ codename0082016 this code does not pass to the last for as the coordinates do not match and the function returns. - Sppevg
  • if you lay out the project, then I will see - codename0082016
  • @ codename0082016 Can you tell me your mail? - Sppevg

0