rrr = 0 'variable que va sumando cada vez que una pregunta queda resuelta para averiguar algo más abajo cuando ya se acaba la partida si es igual al total de preguntas
pp = 0 'preguntas pendientes
If rrr = num_respuestas Then 'aquí cuento las respuestas 'dummies' que tengo más arriba y que se van rellenando con el valor de preguntas resueltas con "setvalue", para si ya se llega a ese número con la variable "rrr+1", el juego acaba"
GraphicsWindow.ShowMessage("Finalizó la partida. Ya se han mostrado todas las palabras/frases por adiviniar. Has acabado con " + marcador + " puntos. ¡Gracias por jugar a 'Saber y Ganar'!","Aviso")
Program.End()
Else
pp = num_preguntas - rrr 'aquí averiguo cuántas preguntas quedan pendientes por resolver y mostrar en la barra de título
If pp < 50 And pp > 25 Then
countdown = 45
ElseIf pp < 25 Or pp = 25 Then
countdown = 30
Else
countdown = 60
EndIf
Timer.Tick = Seconds ' triggered event subroutine to change the text displayed by shape object -> display
Timer.Interval = 1000 ' it's called-back every 1 second ( 1 second = 1000 milliseconds )
'chequeo el array con las respuestas que se van metiendo para comparar con la BD de las preguntas y que no se repitan
repeticion_pregunta:
random = Math.GetRandomNumber(num_preguntas)
For cv = 1 To num_respuestas
If Array.GetValue (respuestas, cv) <> random Then
rand = random
Elseif Array.GetValue (respuestas, cv) = random Then
' GraphicsWindow.ShowMessage("detectado el " + random,"Aviso")
Goto repeticion_pregunta
EndIf
EndFor
'quito ";"
For i = 1 To Text.GetLength(preguntas[rand])
If Text.GetSubText(preguntas[rand], i, 1) = ";" Then 'si el carácter es ";"
For x = 1 To i - 1 'busca los caracteres antes de ";"
pregunta_sin_putoycoma = pregunta_sin_putoycoma + Text.GetSubText(preguntas[rand], x, 1) 'add that character to our new text
EndFor
pregunta_sin_putoycoma = pregunta_sin_putoycoma + "" 'reemplazo
For x = i + 1 To Text.GetLength(preguntas[rand]) 'sigo por el resto del texto
pregunta_sin_putoycoma = pregunta_sin_putoycoma + Text.GetSubText(preguntas[rand], x ,1) 'se añade el texto
EndFor
' TextToReplace = PreText
EndIf
EndFor
'Testeo: GraphicsWindow.DrawText (0,320,pregunta_sin_putoycoma) = OK
'Quito "=" y dejo el Tema
For ii = 1 To Text.GetLength(pregunta_sin_putoycoma)
If Text.GetSubText(pregunta_sin_putoycoma, ii, 1) = "=" Then 'si el carácter es "="
For xx = 1 To ii - 1 'busca los caracteres antes de "="
tema = tema + Text.GetSubText(pregunta_sin_putoycoma, xx, 1)
EndFor
EndIf
EndFor
'Testeo: GraphicsWindow.DrawText (0,330,tema) = OK
'Cojo del array la pregunta de manera visible y oculta
pregunta_hide = ""
pos = Text.GetIndexOf(pregunta_sin_putoycoma,"=") ' lo que busco para separar y quedarme con lo que hay tras el "="
if pos > 0 Then
pregunta_visible = Text.GetSubTextToEnd(pregunta_sin_putoycoma,pos+Text.GetLength("=")) 'el texto que está tras la búsqueda de texto realizada
EndIf
For xy = 1 To Text.GetLength(pregunta_visible)
If Text.GetSubText(pregunta_visible,xy, 1) = " " Then
pregunta_hide = pregunta_hide + " "
Else
pregunta_hide = pregunta_hide + "-"
EndIf
EndFor
'Testeo: TextWindow.WriteLine ("Pregunta visible: " + pregunta_visible + " - Pregunta oculta: " + pregunta_hide) = OK
lng_pregunta = Text.GetLength (pregunta_visible) 'averiguo cuántos caracteres tiene la pregunta para, en función de eso, dar a la pregunta más o menos puntos.
If lng_pregunta < 7 Then
contador = 14
ElseIf lng_pregunta > 10 Then
contador = 18
Else
contador = 16
EndIf
cuestionario()
EndIf
EndSub
Sub cuestionario
GraphicsWindow.Clear()
botones()
GraphicsWindow.FontSize = 12
GraphicsWindow.BrushColor = "Blue"
GraphicsWindow.DrawText (69,5,"BIENVENID@ A SABER y GANAR ver.1.0 - Roberto García Cáceres - 2018 - http://rgc.eu5.org")
GraphicsWindow.FontItalic = "true"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = 11
GraphicsWindow.DrawText (18,30,"Cada letra introducida, inlcuida la 1ª vocal, reducirá 2 puntos el valor de la frase (según complejidad) a averiguar")
GraphicsWindow.DrawText (57,50,"Las siguientes vocales te descontarán 4 puntos. Según se avance, tienes 60'', 45'' o 30'' para resolver")
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.FontItalic = "false"
GraphicsWindow.FontSize = 25
GraphicsWindow.DrawText (10, 90, "Tema: " + tema + " " + pregunta_hide)
GraphicsWindow.FontSize = 22
GraphicsWindow.DrawText (10, 130, "Puntos pregunta: " + contador)
GraphicsWindow.DrawText (10, 160, "Marcador total: " + marcador + " puntos")
GraphicsWindow.FontSize = 12
GraphicsWindow.BrushColor = "Blue"
GraphicsWindow.DrawText (232,400,"roberto.garcia.caceres@gmail.com")
GraphicsWindow.BrushColor = "Red"
EndSub
Sub cotejar_frase
respuesta_total_mayusculas = Text.ConvertToUpperCase (Controls.GetTextBoxText(respuesta_total))
If respuesta_total_mayusculas = pregunta_visible Then
pregunta_hide = pregunta_visible
marcador = marcador + contador
cuestionario ()
Timer.Pause()
Sound.PlayChime()
GraphicsWindow.ShowMessage("¡Genial! Has acertado, efectivamente era '" + pregunta_visible +"'.","Acierto")
Array.SetValue (respuestas,rand, rand) ' añado index de la pregunta al array de respuestas para su posterior comparación y que la pregunta no vuelva a salir
rrr = rrr + 1
inicio ()
Else
Timer.Pause()
GraphicsWindow.ShowMessage("Lamentablemente '" + respuesta_total_mayusculas + "' no es correcto.","Fallo")
Timer.Resume()
EndIf
EndSub
Sub cotejar_letra
l_acertada_before = 0 'Con "letra acertada" voy a comprobar si la letra introducida ha sido acertada, comparo los guiones antes de cotejar y los que quedan tras el cotejo (más abajo). Si hay uno de menos, es porque se ha acertado; si se mantiene el número de guiones, se ha fallado y emito un sonido de error.
For la = 1 To Text.GetLength(pregunta_hide)
If Text.GetSubText(pregunta_hide, la, 1) = "-" Then 'si el carácter es "-"
l_acertada_before = l_acertada_before + 1
EndIf
EndFor
iii = iii + 1
If iii = 1 Then
respuesta1 = respuesta
ElseIf iii = 2 Then
respuesta2 = respuesta
ElseIf iii = 3 Then
respuesta3 = respuesta
ElseIf iii = 4 Then
respuesta4 = respuesta
ElseIf iii = 5 Then
respuesta5 = respuesta
ElseIf iii = 6 Then
respuesta6 = respuesta
ElseIf iii = 7 Then
respuesta7 = respuesta
ElseIf iii = 8 Then
respuesta8 = respuesta
ElseIf iii = 9 Then
respuesta9 = respuesta
ElseIf iii = 10 Then
respuesta10 = respuesta
ElseIf iii = 11 Then
respuesta11 = respuesta
ElseIf iii = 12 Then
respuesta12 = respuesta
ElseIf iii = 13 Then
respuesta13 = respuesta
ElseIf iii = 14 Then
respuesta14 = respuesta
ElseIf iii = 15 Then
respuesta15 = respuesta
ElseIf iii = 16 Then
respuesta16 = respuesta
EndIf
If contador = 2 Then
Timer.Pause()
GraphicsWindow.ShowMessage("Solo te quedan 2 puntos, solo tiene sentido que resuelvas a través del botón 'Validar'.","Aviso")
Timer.Resume()
Else
pregunta_hide = ""
If respuesta = "A" Or respuesta = "E" Or respuesta = "I" Or respuesta = "O" Or respuesta = "U" Then
If vocal = 0 Then
contador = contador -2
vocal = 1
Else
contador = contador -4
EndIf
Else
contador = contador -2
EndIf
For w = 1 To Text.GetLength(pregunta_visible)
If Text.GetSubText(pregunta_visible, w, 1) = respuesta1 Then
pregunta_hide = pregunta_hide + respuesta1
If Text.GetSubText(pregunta_visible, w, 1) = " " Then
pregunta_hide = (pregunta_hide + " ")
Else
pregunta_hide = pregunta_hide + "-"
EndIf
EndIf
EndFor
guion = "no"
For bmw = 1 To Text.GetLength(pregunta_hide)
If Text.GetSubText(pregunta_hide, bmw, 1) = "-" Then
guion = "si"
EndIf
EndFor
l_acertada_after = 0 'Comparando para saber si la letra era acertada o no, y si no lo era, emito sonido de fallo
For lac = 1 To Text.GetLength(pregunta_hide)
If Text.GetSubText(pregunta_hide, lac, 1) = "-" Then 'si el carácter es "-"
l_acertada_after = l_acertada_after + 1
EndIf
EndFor
If l_acertada_after = l_acertada_before Then
Sound.PlayClickAndWait()
'Sound.PlayAndWait(urlBeep)'Al fallar, emito un beep
EndIf
If guion = "no" Then
pregunta_hide = pregunta_visible
marcador = marcador + contador
cuestionario ()
Timer.Pause()
Sound.PlayChime()
GraphicsWindow.ShowMessage("¡Genial! Has acertado, efectivamente era '" + pregunta_visible +"'.","Acierto")
Array.SetValue (respuestas,rand, rand) ' añado index de la pregunta al array de respuestas para su posterior comparación y que la pregunta no vuelva a salir
rrr = rrr + 1
inicio()
Elseif lastButton = validarButton Then
If Controls.GetTextBoxText(respuesta_total) = "" Or Controls.GetTextBoxText(respuesta_total) = " " Or Text.GetLength (Controls.GetTextBoxText(respuesta_total)) < 3 Then
Timer.Pause()
GraphicsWindow.ShowMessage("No se ha rellenado correctamente la palabra o frase a resolver.","Error")
Timer.Resume()
Else
cotejar_frase()
Endif
EndIf
EndSub
Sub botones
GraphicsWindow.FontBold = "true"
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.DrawText (5,245,"Resolver: ")
GraphicsWindow.BrushColor = "Brown"
validarButton = Controls.AddButton ("Validar", 230, 240)
respuesta_total = Controls.AddTextBox (65,240)
nextButton = Controls.AddButton ("Ir a otra palabra / frase", 264, 320)
closeButton = Controls.AddButton ("Salir de Saber y Ganar", 269, 360)
EndSub
Sub Seconds
If countdown > 0 Then
countdown = countdown - 1 ' 1 second less for countdown
ElseIf countdown = 0 Then
Timer.Pause()
GraphicsWindow.ShowMessage("Se agotó el minuto para resolver esta palabra/frase, 0 puntos. Ésta puede volver a aparecer.","Tiempo cumplido")
contador = 0
marcador = marcador + contador
inicio()
EndIf
GraphicsWindow.Title = "SABER y GANAR Ver. 1.0 - Tiempo restante para resolver: " + countdown + " segundo(s) - Preguntas restantes: " + pp