Código
Module Module1 Sub Main() Dim x As Integer = 0 Dim y As Integer = 0 Dim z As Integer = 99 Dim contpalabras As Integer = 0 Dim aux1 = "", aux2 As String = "" Dim Formato As String = "" '(vertical/horizontal) Dim posicionX = -1, posicionY As Integer = -1 Dim cantPalabras As Integer = 0 Dim rep As Boolean = True 'variable para pedir palabras While x <= 0 Console.Write("Ingresar el numero de Columnas[X](mayor a 0): ") x = Console.ReadLine End While While y <= 0 Console.Write("Ingresar el numero de Filas[Y](mayor a 0): ") y = Console.ReadLine End While Dim Sopa(x, y) As Char 'matriz de sopa Dim Palabras(z) As String 'vector palabras Console.WriteLine("============ DIBUJADO DE SOPA DE LETRAS ============") Console.WriteLine("Caja de posiciones") For i = 0 To y - 1 For j = 0 To x - 1 Console.Write(j & "," & i & "|") Next Console.WriteLine() Next Console.WriteLine("============FIN DIBUJADO DE SOPA DE LETRAS ============") While rep aux1 = "" aux2 = "" posicionX = -1 posicionY = -1 While aux1 = "" Console.Write("añada una palabra: ") aux1 = Console.ReadLine If aux1.ToCharArray.Length >= 3 And aux1.ToCharArray.Length <= x Or aux1.ToCharArray.Length <= y Then Palabras(contpalabras) = aux1 contpalabras += 1 Else aux1 = "" Console.WriteLine("ERROR -> la palabra debe tener mas de 3 letras y debe ser menor al maximo X y maximo Y") End If End While While aux2 = "" Console.Write("Horizontal o Vertical: ") aux2 = Console.ReadLine If (aux2.ToLower = "horizontal" And aux1.ToCharArray.Length < x) Or (aux1.ToCharArray.Length < y And aux2.ToLower = "vertical") Then Formato = aux2.ToLower Else aux2 = "" Console.WriteLine("ERROR -> debe escribir una de las 2 opciones, y revisar que la palabra pueda ser añadida en esa opcion") End If End While While posicionX = -1 And posicionY = -1 Console.Write("Posicion inicial de la palabra en la matriz en X: ") posicionX = Console.ReadLine Console.Write("Posicion inicial de la palabra en la matriz en Y: ") posicionY = Console.ReadLine If Formato = "horizontal" Then If posicionX + aux1.ToCharArray.Length > x Or posicionX < 0 Or posicionY < 0 Or posicionY > y Then posicionX = -1 posicionY = -1 End If ElseIf Formato = "vertical" Then If posicionY + aux1.ToCharArray.Length > y Or posicionY < 0 Or posicionX < 0 Or posicionX > x Then posicionX = -1 posicionY = -1 End If End If If posicionX < 0 Or posicionY < 0 Then Console.WriteLine("ERROR -> la suma de la posicion y el tamaño de la palabra supera el limite de la sopa de letras") End If End While If Formato = "horizontal" Then For i = 0 To aux1.ToCharArray.Length - 1 Sopa(posicionX + i, posicionY) = aux1.ToCharArray()(i).ToString.ToLower Next ElseIf Formato = "vertical" Then For i = 0 To aux1.ToCharArray.Length - 1 Sopa(posicionX, posicionY + i) = aux1.ToCharArray()(i).ToString.ToLower Next End If 'dibujado de la sopa de letras Console.WriteLine("============ DIBUJADO DE SOPA DE LETRAS ============") Console.WriteLine("Caja de posiciones") For i = 0 To y - 1 For j = 0 To x - 1 Console.Write(j & "," & i & "|") Next Console.WriteLine() Next Console.WriteLine() For i = 0 To y - 1 For j = 0 To x - 1 If Sopa(j, i) = "" Then Console.Write(" |") Else Console.Write(Sopa(j, i) & "|") End If Next Console.WriteLine() Next Console.WriteLine("============FIN DIBUJADO DE SOPA DE LETRAS ============") 'añadir mas palabras aux2 = "" While aux2 = "" Console.Write("Desea añadir otra palabra[si/no]?: ") aux2 = Console.ReadLine If aux2 = "si" Then rep = True ElseIf aux2 = "no" Then rep = False Else aux2 = "" End If End While End While aux2 = "" rep = True While aux2 = "" Console.Write("Desea Rellenar la sopa de letras[si/no]?: ") aux2 = Console.ReadLine If aux2 = "si" Then rep = True ElseIf aux2 = "no" Then rep = False Else aux2 = "" End If End While If rep Then Dim r As New Random Dim letras As Char() = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "ñ", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} For i = 0 To y - 1 For j = 0 To x - 1 If Sopa(j, i) = "" Or Sopa(j, i) = Nothing Then Sopa(j, i) = letras(r.Next(0, letras.Length)) End If Next Next End If Console.WriteLine() Console.WriteLine("============ DIBUJADO FINAL DE SOPA DE LETRAS ============") For i = 0 To y - 1 For j = 0 To x - 1 If Sopa(j, i) = "" Then Console.Write(" |") Else Console.Write(Sopa(j, i) & "|") End If Next Console.WriteLine() Next Console.WriteLine() Console.WriteLine("Palabras utilizadas") For i = 0 To Palabras.Length - 1 If Palabras(i) = Nothing Or Palabras(i) = "" Then Else Console.WriteLine(Palabras(i)) End If Next Console.WriteLine("============FIN DIBUJADO FINAL DE SOPA DE LETRAS ============") Console.WriteLine("Presiona una tecla para salir...") Console.ReadKey() End Sub End Module
NO ESTA OPTIMIZADO
USO TECNICAS PERMITIDAS EN SUS CURSOS (no hay subs, no hay functions,nada de eso)
desarrollado para consola, y en un simple Sub
UNICO DETALLE = NO INTERCEPTAR PALABRAS ( me dio flojera añadirlo)
saludos