{
En este ejemplo de visual studio mostrare como editar el juego de “pluzzle”, juego que constara de un tablero de 8 x 8 en el que se deberá colocar un total de 8 círculos de los cuales no deberá haber dos círculos en la misma, columna, diagonal o hilera las cuales las diferenciaremos por color.
Aquí el diseño:Como se puede observar necesitaremos colocar 1 button y 64 Picturebox a las cuales se le asignara el nombre del color + ubicación por ejemplo la primer PictureBox del color verde lleva el nombre de v11 y la última PictureBox lleva el nombre de gr88.Continuando aquí enlisto las imágenes que contienen los PictureBox:
Las imágenes sin círculo llevan el nombre de color+f:amrfazfcffgrisfmrfrfrsfvfLas imágenes con círculo llevan el nombre de color+t:amrtaztcftgristmrtrtrstvtTodas las imágenes so de tipo .pngUna vez se hallan colocado todos los PictureBox con su imagen respectiva pasamos al código.Aquí el código:}Public Class Form1'Definidendo array que contendra el estado de cada'PictureBoxDim comprobante(8, 8) As BooleanPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load'All empezar el juego no hay seleccionada ninguna opcion'por lo que el comprobante completo debe'ser falseFor i As Integer = 1 To 8For i2 As Integer = 1 To 8comprobante(i, i2) = FalseNextNextEnd Sub'Editando sub para los cambios de imagen de los'PictureBox color verde y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub changeVerde(num1 As Integer, num2 As Integer)For i As Integer = 1 To 4For i2 As Integer = 1 To 2If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(1, 1) = False Thenv11.ImageLocation = "vf.png"v11.Load()Elsev11.ImageLocation = "vt.png"v11.Load()End IfIf comprobante(1, 2) = False Thenv12.ImageLocation = "vf.png"v12.Load()Elsev12.ImageLocation = "vt.png"v12.Load()End IfIf comprobante(2, 1) = False Thenv21.ImageLocation = "vf.png"v21.Load()Elsev21.ImageLocation = "vt.png"v21.Load()End IfIf comprobante(2, 2) = False Thenv22.ImageLocation = "vf.png"v22.Load()Elsev22.ImageLocation = "vt.png"v22.Load()End IfIf comprobante(3, 1) = False Thenv31.ImageLocation = "vf.png"v31.Load()Elsev31.ImageLocation = "vt.png"v31.Load()End IfIf comprobante(3, 2) = False Thenv32.ImageLocation = "vf.png"v32.Load()Elsev32.ImageLocation = "vt.png"v32.Load()End IfIf comprobante(4, 1) = False Thenv41.ImageLocation = "vf.png"v41.Load()Elsev41.ImageLocation = "vt.png"v41.Load()End IfIf comprobante(4, 2) = False Thenv42.ImageLocation = "vf.png"v42.Load()Elsev42.ImageLocation = "vt.png"v42.Load()End IfEnd SubPrivate Sub v11_Click(sender As Object, e As EventArgs) Handles v11.ClickchangeVerde(1, 1)End SubPrivate Sub v12_Click(sender As Object, e As EventArgs) Handles v12.ClickchangeVerde(1, 2)End SubPrivate Sub v21_Click(sender As Object, e As EventArgs) Handles v21.ClickchangeVerde(2, 1)End SubPrivate Sub v22_Click(sender As Object, e As EventArgs) Handles v22.ClickchangeVerde(2, 2)End SubPrivate Sub v31_Click(sender As Object, e As EventArgs) Handles v31.ClickchangeVerde(3, 1)End SubPrivate Sub v32_Click(sender As Object, e As EventArgs) Handles v32.ClickchangeVerde(3, 2)End SubPrivate Sub v41_Click(sender As Object, e As EventArgs) Handles v41.ClickchangeVerde(4, 1)End SubPrivate Sub v42_Click(sender As Object, e As EventArgs) Handles v42.ClickchangeVerde(4, 2)End Sub'Editando sub para los cambios de imagen de los'PictureBox color rojo y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub changeRojo(num1 As Integer, num2 As Integer)For i As Integer = 1 To 4For i2 As Integer = 3 To 4If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(1, 3) = False Thenr13.ImageLocation = "rf.png"r13.Load()Elser13.ImageLocation = "rt.png"r13.Load()End IfIf comprobante(1, 4) = False Thenr14.ImageLocation = "rf.png"r14.Load()Elser14.ImageLocation = "rt.png"r14.Load()End IfIf comprobante(2, 3) = False Thenr23.ImageLocation = "rf.png"r23.Load()Elser23.ImageLocation = "rt.png"r23.Load()End IfIf comprobante(2, 4) = False Thenr24.ImageLocation = "rf.png"r24.Load()Elser24.ImageLocation = "rt.png"r24.Load()End IfIf comprobante(3, 3) = False Thenr33.ImageLocation = "rf.png"r33.Load()Elser33.ImageLocation = "rt.png"r33.Load()End IfIf comprobante(3, 4) = False Thenr34.ImageLocation = "rf.png"r34.Load()Elser34.ImageLocation = "rt.png"r34.Load()End IfIf comprobante(4, 3) = False Thenr43.ImageLocation = "rf.png"r43.Load()Elser43.ImageLocation = "rt.png"r43.Load()End IfIf comprobante(4, 4) = False Thenr44.ImageLocation = "rf.png"r44.Load()Elser44.ImageLocation = "rt.png"r44.Load()End IfEnd SubPrivate Sub r13_Click(sender As Object, e As EventArgs) Handles r13.ClickchangeRojo(1, 3)End SubPrivate Sub r14_Click(sender As Object, e As EventArgs) Handles r14.ClickchangeRojo(1, 4)End SubPrivate Sub r23_Click(sender As Object, e As EventArgs) Handles r23.ClickchangeRojo(2, 3)End SubPrivate Sub r24_Click(sender As Object, e As EventArgs) Handles r24.ClickchangeRojo(2, 4)End SubPrivate Sub r33_Click(sender As Object, e As EventArgs) Handles r33.ClickchangeRojo(3, 3)End SubPrivate Sub r34_Click(sender As Object, e As EventArgs) Handles r34.ClickchangeRojo(3, 4)End SubPrivate Sub r43_Click(sender As Object, e As EventArgs) Handles r43.ClickchangeRojo(4, 3)End SubPrivate Sub r44_Click(sender As Object, e As EventArgs) Handles r44.ClickchangeRojo(4, 4)End Sub'Editando sub para los cambios de imagen de los'PictureBox color Morado y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub changeMorado(num1 As Integer, num2 As Integer)For i As Integer = 5 To 8For i2 As Integer = 5 To 6If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(5, 5) = False Thenmr55.ImageLocation = "mrf.png"mr55.Load()Elsemr55.ImageLocation = "mrt.png"mr55.Load()End IfIf comprobante(5, 6) = False Thenmr56.ImageLocation = "mrf.png"mr56.Load()Elsemr56.ImageLocation = "mrt.png"mr56.Load()End IfIf comprobante(6, 5) = False Thenmr65.ImageLocation = "mrf.png"mr65.Load()Elsemr65.ImageLocation = "mrt.png"mr65.Load()End IfIf comprobante(6, 6) = False Thenmr66.ImageLocation = "mrf.png"mr66.Load()Elsemr66.ImageLocation = "mrt.png"mr66.Load()End IfIf comprobante(7, 5) = False Thenmr75.ImageLocation = "mrf.png"mr75.Load()Elsemr75.ImageLocation = "mrt.png"mr75.Load()End IfIf comprobante(7, 6) = False Thenmr76.ImageLocation = "mrf.png"mr76.Load()Elsemr76.ImageLocation = "mrt.png"mr76.Load()End IfIf comprobante(8, 5) = False Thenmr85.ImageLocation = "mrf.png"mr85.Load()Elsemr85.ImageLocation = "mrt.png"mr85.Load()End IfIf comprobante(8, 6) = False Thenmr86.ImageLocation = "mrf.png"mr86.Load()Elsemr86.ImageLocation = "mrt.png"mr86.Load()End IfEnd SubPrivate Sub mr55_Click(sender As Object, e As EventArgs) Handles mr55.ClickchangeMorado(5, 5)End SubPrivate Sub mr56_Click(sender As Object, e As EventArgs) Handles mr56.ClickchangeMorado(5, 6)End SubPrivate Sub mr65_Click(sender As Object, e As EventArgs) Handles mr65.ClickchangeMorado(6, 5)End SubPrivate Sub mr66_Click(sender As Object, e As EventArgs) Handles mr66.ClickchangeMorado(6, 6)End SubPrivate Sub mr75_Click(sender As Object, e As EventArgs) Handles mr75.ClickchangeMorado(7, 5)End SubPrivate Sub mr76_Click(sender As Object, e As EventArgs) Handles mr76.ClickchangeMorado(7, 6)End SubPrivate Sub mr85_Click(sender As Object, e As EventArgs) Handles mr85.ClickchangeMorado(8, 5)End SubPrivate Sub mr86_Click(sender As Object, e As EventArgs) Handles mr86.ClickchangeMorado(8, 6)End Sub'Editando sub para los cambios de imagen de los'PictureBox color gris y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub changeGris(num1 As Integer, num2 As Integer)Dim imgf As String, imgt As Stringimgf = "grisf.png"imgt = "grist.png"For i As Integer = 5 To 8For i2 As Integer = 7 To 8If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(5, 7) = False Thengr57.ImageLocation = imgfgr57.Load()Elsegr57.ImageLocation = imgtgr57.Load()End IfIf comprobante(5, 8) = False Thengr58.ImageLocation = imgfgr58.Load()Elsegr58.ImageLocation = imgtgr58.Load()End IfIf comprobante(6, 7) = False Thengr67.ImageLocation = imgfgr67.Load()Elsegr67.ImageLocation = imgtgr67.Load()End IfIf comprobante(6, 8) = False Thengr68.ImageLocation = imgfgr68.Load()Elsegr68.ImageLocation = imgtgr68.Load()End IfIf comprobante(7, 7) = False Thengr77.ImageLocation = imgfgr77.Load()Elsegr77.ImageLocation = imgtgr77.Load()End IfIf comprobante(7, 8) = False Thengr78.ImageLocation = imgfgr78.Load()Elsegr78.ImageLocation = imgtgr78.Load()End IfIf comprobante(8, 7) = False Thengr87.ImageLocation = imgfgr87.Load()Elsegr87.ImageLocation = imgtgr87.Load()End IfIf comprobante(8, 8) = False Thengr88.ImageLocation = imgfgr88.Load()Elsegr88.ImageLocation = imgtgr88.Load()End IfEnd SubPrivate Sub gr57_Click(sender As Object, e As EventArgs) Handles gr57.ClickchangeGris(5, 7)End SubPrivate Sub gr58_Click(sender As Object, e As EventArgs) Handles gr58.ClickchangeGris(5, 8)End SubPrivate Sub gr67_Click(sender As Object, e As EventArgs) Handles gr67.ClickchangeGris(6, 7)End SubPrivate Sub gr68_Click(sender As Object, e As EventArgs) Handles gr68.ClickchangeGris(6, 8)End SubPrivate Sub gr77_Click(sender As Object, e As EventArgs) Handles gr77.ClickchangeGris(7, 7)End SubPrivate Sub gr78_Click(sender As Object, e As EventArgs) Handles gr78.ClickchangeGris(7, 8)End SubPrivate Sub gr87_Click(sender As Object, e As EventArgs) Handles gr87.ClickchangeGris(8, 7)End SubPrivate Sub gr88_Click(sender As Object, e As EventArgs) Handles gr88.ClickchangeGris(8, 8)End Sub'Editando sub para los cambios de imagen de los'PictureBox color Amarillo y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub changeAmarillo(num1 As Integer, num2 As Integer)Dim imgf As String, imgt As Stringimgf = "amrf.png"imgt = "amrt.png"For i As Integer = 1 To 2For i2 As Integer = 5 To 8If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(1, 5) = False Thenamr15.ImageLocation = imgfamr15.Load()Elseamr15.ImageLocation = imgtamr15.Load()End IfIf comprobante(1, 6) = False Thenamr16.ImageLocation = imgfamr16.Load()Elseamr16.ImageLocation = imgtamr16.Load()End IfIf comprobante(1, 7) = False Thenamr17.ImageLocation = imgfamr17.Load()Elseamr17.ImageLocation = imgtamr17.Load()End IfIf comprobante(1, 8) = False Thenamr18.ImageLocation = imgfamr18.Load()Elseamr18.ImageLocation = imgtamr18.Load()End IfIf comprobante(2, 5) = False Thenamr25.ImageLocation = imgfamr25.Load()Elseamr25.ImageLocation = imgtamr25.Load()End IfIf comprobante(2, 6) = False Thenamr26.ImageLocation = imgfamr26.Load()Elseamr26.ImageLocation = imgtamr26.Load()End IfIf comprobante(2, 7) = False Thenamr27.ImageLocation = imgfamr27.Load()Elseamr27.ImageLocation = imgtamr27.Load()End IfIf comprobante(2, 8) = False Thenamr28.ImageLocation = imgfamr28.Load()Elseamr28.ImageLocation = imgtamr28.Load()End IfEnd SubPrivate Sub amr15_Click(sender As Object, e As EventArgs) Handles amr15.ClickchangeAmarillo(1, 5)End SubPrivate Sub amr16_Click(sender As Object, e As EventArgs) Handles amr16.ClickchangeAmarillo(1, 6)End SubPrivate Sub amr17_Click(sender As Object, e As EventArgs) Handles amr17.ClickchangeAmarillo(1, 7)End SubPrivate Sub amr18_Click(sender As Object, e As EventArgs) Handles amr18.ClickchangeAmarillo(1, 8)End SubPrivate Sub amr25_Click(sender As Object, e As EventArgs) Handles amr25.ClickchangeAmarillo(2, 5)End SubPrivate Sub amr26_Click(sender As Object, e As EventArgs) Handles amr26.ClickchangeAmarillo(2, 6)End SubPrivate Sub amr27_Click(sender As Object, e As EventArgs) Handles amr27.ClickchangeAmarillo(2, 7)End SubPrivate Sub amr28_Click(sender As Object, e As EventArgs) Handles amr28.ClickchangeAmarillo(2, 8)End Sub'Editando sub para los cambios de imagen de los'PictureBox color azul y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub ChangeAzul(num1 As Integer, num2 As Integer)Dim imgf As String, imgt As Stringimgf = "azf.png"imgt = "azt.png"For i As Integer = 3 To 4For i2 As Integer = 5 To 8If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(3, 5) = False Thenaz35.ImageLocation = imgfaz35.Load()Elseaz35.ImageLocation = imgtaz35.Load()End IfIf comprobante(3, 6) = False Thenaz36.ImageLocation = imgfaz36.Load()Elseaz36.ImageLocation = imgtaz36.Load()End IfIf comprobante(3, 7) = False Thenaz37.ImageLocation = imgfaz37.Load()Elseaz37.ImageLocation = imgtaz37.Load()End IfIf comprobante(3, 8) = False Thenaz38.ImageLocation = imgfaz38.Load()Elseaz38.ImageLocation = imgtaz38.Load()End IfIf comprobante(4, 5) = False Thenaz45.ImageLocation = imgfaz45.Load()Elseaz45.ImageLocation = imgtaz45.Load()End IfIf comprobante(4, 6) = False Thenaz46.ImageLocation = imgfaz46.Load()Elseaz46.ImageLocation = imgtaz46.Load()End IfIf comprobante(4, 7) = False Thenaz47.ImageLocation = imgfaz47.Load()Elseaz47.ImageLocation = imgtaz47.Load()End IfIf comprobante(4, 8) = False Thenaz48.ImageLocation = imgfaz48.Load()Elseaz48.ImageLocation = imgtaz48.Load()End IfEnd SubPrivate Sub az35_Click(sender As Object, e As EventArgs) Handles az35.ClickChangeAzul(3, 5)End SubPrivate Sub az36_Click(sender As Object, e As EventArgs) Handles az36.ClickChangeAzul(3, 6)End SubPrivate Sub az37_Click(sender As Object, e As EventArgs) Handles az37.ClickChangeAzul(3, 7)End SubPrivate Sub az38_Click(sender As Object, e As EventArgs) Handles az38.ClickChangeAzul(3, 8)End SubPrivate Sub az45_Click(sender As Object, e As EventArgs) Handles az45.ClickChangeAzul(4, 5)End SubPrivate Sub az46_Click(sender As Object, e As EventArgs) Handles az46.ClickChangeAzul(4, 6)End SubPrivate Sub az47_Click(sender As Object, e As EventArgs) Handles az47.ClickChangeAzul(4, 7)End SubPrivate Sub az48_Click(sender As Object, e As EventArgs) Handles az48.ClickChangeAzul(4, 8)End Sub'Editando sub para los cambios de imagen de los'PictureBox color rosado y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub ChangeRosado(num1 As Integer, num2 As Integer)Dim imgf As String, imgt As Stringimgf = "rsf.png"imgt = "rst.png"For i As Integer = 5 To 6For i2 As Integer = 1 To 4If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(5, 1) = False Thenrs51.ImageLocation = imgfrs51.Load()Elsers51.ImageLocation = imgtrs51.Load()End IfIf comprobante(5, 2) = False Thenrs52.ImageLocation = imgfrs52.Load()Elsers52.ImageLocation = imgtrs52.Load()End IfIf comprobante(5, 3) = False Thenrs53.ImageLocation = imgfrs53.Load()Elsers53.ImageLocation = imgtrs53.Load()End IfIf comprobante(5, 4) = False Thenrs54.ImageLocation = imgfrs54.Load()Elsers54.ImageLocation = imgtrs54.Load()End If'--If comprobante(6, 1) = False Thenrs61.ImageLocation = imgfrs61.Load()Elsers61.ImageLocation = imgtrs61.Load()End IfIf comprobante(6, 2) = False Thenrs62.ImageLocation = imgfrs62.Load()Elsers62.ImageLocation = imgtrs62.Load()End IfIf comprobante(6, 3) = False Thenrs63.ImageLocation = imgfrs63.Load()Elsers63.ImageLocation = imgtrs63.Load()End IfIf comprobante(6, 4) = False Thenrs64.ImageLocation = imgfrs64.Load()Elsers64.ImageLocation = imgtrs64.Load()End IfEnd SubPrivate Sub rs51_Click(sender As Object, e As EventArgs) Handles rs51.ClickChangeRosado(5, 1)End SubPrivate Sub rs52_Click(sender As Object, e As EventArgs) Handles rs52.ClickChangeRosado(5, 2)End SubPrivate Sub rs53_Click(sender As Object, e As EventArgs) Handles rs53.ClickChangeRosado(5, 3)End SubPrivate Sub rs54_Click(sender As Object, e As EventArgs) Handles rs54.ClickChangeRosado(5, 4)End SubPrivate Sub rs61_Click(sender As Object, e As EventArgs) Handles rs61.ClickChangeRosado(6, 1)End SubPrivate Sub rs62_Click(sender As Object, e As EventArgs) Handles rs62.ClickChangeRosado(6, 2)End SubPrivate Sub rs63_Click(sender As Object, e As EventArgs) Handles rs63.ClickChangeRosado(6, 3)End SubPrivate Sub rs64_Click(sender As Object, e As EventArgs) Handles rs64.ClickChangeRosado(6, 4)End Sub'Editando sub para los cambios de imagen de los'PictureBox color cafe y cambiando el estado'del comprobante dependiendo del PictureBox'presionadoSub ChangeCafe(num1 As Integer, num2 As Integer)Dim imgf As String, imgt As Stringimgf = "cff.png"imgt = "cft.png"For i As Integer = 7 To 8For i2 As Integer = 1 To 4If i = num1 And i2 = num2 Thencomprobante(i, i2) = TrueElsecomprobante(i, i2) = FalseEnd IfNextNextIf comprobante(7, 1) = False Thencf71.ImageLocation = imgfcf71.Load()Elsecf71.ImageLocation = imgtcf71.Load()End IfIf comprobante(7, 2) = False Thencf72.ImageLocation = imgfcf72.Load()Elsecf72.ImageLocation = imgtcf72.Load()End IfIf comprobante(7, 3) = False Thencf73.ImageLocation = imgfcf73.Load()Elsecf73.ImageLocation = imgtcf73.Load()End IfIf comprobante(7, 4) = False Thencf74.ImageLocation = imgfcf74.Load()Elsecf74.ImageLocation = imgtcf74.Load()End If'--If comprobante(8, 1) = False Thencf81.ImageLocation = imgfcf81.Load()Elsecf81.ImageLocation = imgtcf81.Load()End IfIf comprobante(8, 2) = False Thencf82.ImageLocation = imgfcf82.Load()Elsecf82.ImageLocation = imgtcf82.Load()End IfIf comprobante(8, 3) = False Thencf83.ImageLocation = imgfcf83.Load()Elsecf83.ImageLocation = imgtcf83.Load()End IfIf comprobante(8, 4) = False Thencf84.ImageLocation = imgfcf84.Load()Elsecf84.ImageLocation = imgtcf84.Load()End IfEnd SubPrivate Sub cf71_Click(sender As Object, e As EventArgs) Handles cf71.ClickChangeCafe(7, 1)End SubPrivate Sub cf72_Click(sender As Object, e As EventArgs) Handles cf72.ClickChangeCafe(7, 2)End SubPrivate Sub cf73_Click(sender As Object, e As EventArgs) Handles cf73.ClickChangeCafe(7, 3)End SubPrivate Sub cf74_Click(sender As Object, e As EventArgs) Handles cf74.ClickChangeCafe(7, 4)End SubPrivate Sub cf81_Click(sender As Object, e As EventArgs) Handles cf81.ClickChangeCafe(8, 1)End SubPrivate Sub cf82_Click(sender As Object, e As EventArgs) Handles cf82.ClickChangeCafe(8, 2)End SubPrivate Sub cf83_Click(sender As Object, e As EventArgs) Handles cf83.ClickChangeCafe(8, 3)End SubPrivate Sub cf84_Click(sender As Object, e As EventArgs) Handles cf84.ClickChangeCafe(8, 4)End Sub'Editando sub del Button1 el cual seria'para la comprobacion de que no se repite'El circulo tanto en la columna, diagonal'o hileraPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim contx As IntegerDim conty As IntegerDim cc As Integercontx = 0conty = 0cc = 0For i As Integer = 1 To 8For i2 As Integer = 1 To 8If comprobante(i, i2) = True And cc <> i Thenconty = conty + 1cc = iEnd IfNextcc = 0NextFor i As Integer = 1 To 8For i2 As Integer = 1 To 8If comprobante(i2, i) = True And cc <> i Thencontx = contx + 1cc = iEnd IfNextcc = 0NextIf contx = 8 And conty = 8 ThenMsgBox("correcto")ElseMsgBox("Incorrecto")End IfEnd SubEnd Class
Ahora que ya está creado es juego ¿podrás resolverlo?
Saludos.