|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  Raspberry Pi Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  AutoIt (Programación) Visual Basic Cosas de Windows Webs interesantes
Translate:
Búsqueda en este sitio:


.

Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando

-- Tutorial de iniciación a Autoit --

Volver al índice del tutorial

____________________________

13.- Tres iguales. Imágenes.

tres_iguales.exe

- Se trata de pulsar el Botón "Comienzo", en ese momentos tres imagenes fresa.gif, limon.gif y pera.gif, se van reproduciendo aleatoriamente en los cuadros (Pics1, Pics2 y Pics3).

- Cuando pulsamos el Botón "Para", las imágenes quedan estáticas, se incrementa en uno el número de intentos y se comprueba si las tres imagenes son iguales, en este caso se incrementa en uno el número de aciertos.

- Fijate que en el temporizador Reloj1 he puesto un IntervaloDeTiempo de 200

- A las imágenes que vamos a utilizar (fresa.gif, limon.gif y pera.gif) las hemos Añadido en el apartado Medios.

- De aquí puedes bajar los dibujos de las frutas.

- Este código es similar al que vimos en App Inventor: Tres iguales pero un poco más complicado debido a que el código es menos intuitovo para un principiante.

__________________________

- Ejecutamos Koda para crear el formulario.


- Creamos el siguiente Formulario. Tenemos Label (etiquetas), Imágenes y Botones.

- IMPORTANTE: copiamos las tres imágenes de las frutas en la misma carpeta donde guardemos la aplicación.

- El componente de imágenes (Pictures) está en la pestaña "Additional".

- El dibujo de la imagen lo tomamos desde la Propiedad Picture.

- Si pulsas Tools / Run Form, verás cómo va quedando.

- Pulsamos en Tools / Generate Form Code... y obtenemos el código de situación de los componentes del Formulario.

- Ese código lo copiamos en el Editor SciTe. Borramos las últimas líneas como indico en la imagen.

- Creo el código de Tres iguales.

Tres iguales.

;;;;;;;;;;;;;;;; Configuración del Temporizador ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $inicio = 0
 $final = 0
 $TemporizadorHabilitado = "cierto"
 $IntervaloDelTemporizador = 40
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $x = 0
 $y = 0
 $z = 0
 $aciertos = 0
 $intentos = 0

While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Case $msg = $Button1
     $intentos = $intentos + 1
     GUICtrlSetData($Label1,$intentos)
     $TemporizadorHabilitado = "falso"
     if $x = $y And $y = $z Then
       $aciertos = $aciertos + 1
       GUICtrlSetData($Label2,$aciertos)
     EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   Case $msg = $Button2
     $TemporizadorHabilitado = "cierto"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   Case $msg = $Button3
    $aciertos = 0
    GUICtrlSetData($Label2,$aciertos)
    $intentos = 0
    GUICtrlSetData($Label1,$intentos)
    $TemporizadorHabilitado = "cierto"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EndSelect

;;;;;;;;;;;;;;;;;; Comprueba el temporizador  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $final = TimerDiff($inicio)
 if $final > $IntervaloDelTemporizador And $TemporizadorHabilitado="cierto" Then
   Reloj_Temporizador()
   $inicio = TimerInit()
 EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Wend
Exit

; RELOJ_TEMPORIZADOR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func Reloj_Temporizador()
$x = Random(1,3,1)
$y = Random(1,3,1)
$z = Random(1,3,1)

 if $x = 1 Then
   GUICtrlSetImage ($Pic1, "fresa.gif")
 EndIf
 if $x = 2 Then
   GUICtrlSetImage ($Pic1, "limon.gif")
 EndIf
 if $x = 3 Then
   GUICtrlSetImage ($Pic1, "pera.gif")
 EndIf

 if $y = 1 Then
   GUICtrlSetImage ($Pic2, "fresa.gif")
 EndIf
 if $y = 2 Then
   GUICtrlSetImage ($Pic2, "limon.gif")
 EndIf
   if $y = 3 Then
   GUICtrlSetImage ($Pic2, "pera.gif")
 EndIf

 if $z = 1 Then
   GUICtrlSetImage ($Pic3, "fresa.gif")
 EndIf
   if $z = 2 Then
   GUICtrlSetImage ($Pic3, "limon.gif")
 EndIf
   if $z = 3 Then
   GUICtrlSetImage ($Pic3, "pera.gif")
 EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

- La parte azul de arriba y abajo la insertaremos también.

tres_iguales.au3
				   
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Tres iguales - Juan A. Villalpando", 703, 513, 464, 136)
$Pic1 = GUICtrlCreatePic("limon.gif", 280, 24, 153, 113)
$Pic2 = GUICtrlCreatePic("fresa.gif", 80, 24, 153, 113)
$Pic3 = GUICtrlCreatePic("pera.gif", 488, 24, 153, 113)
$Button1 = GUICtrlCreateButton("Para", 136, 184, 209, 57)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Continua", 376, 184, 209, 57)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Label1", 88, 272, 392, 41)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Label2", 88, 328, 394, 41)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("Comienzo", 224, 408, 273, 49)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; Configuración del Temporizador ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $inicio = 0
 $final = 0
 $TemporizadorHabilitado = "cierto"
 $IntervaloDelTemporizador = 40
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $x = 0
 $y = 0
 $z = 0
 $aciertos = 0
 $intentos = 0

While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Case $msg = $Button1
     $intentos = $intentos + 1
     GUICtrlSetData($Label1,$intentos)
     $TemporizadorHabilitado = "falso"
     if $x = $y And $y = $z Then
       $aciertos = $aciertos + 1
       GUICtrlSetData($Label2,$aciertos)
     EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   Case $msg = $Button2
     $TemporizadorHabilitado = "cierto"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   Case $msg = $Button3
    $aciertos = 0
    GUICtrlSetData($Label2,$aciertos)
    $intentos = 0
    GUICtrlSetData($Label1,$intentos)
    $TemporizadorHabilitado = "cierto"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EndSelect

;;;;;;;;;;;;;;;;;; Comprueba el temporizador  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 $final = TimerDiff($inicio)
 if $final > $IntervaloDelTemporizador And $TemporizadorHabilitado="cierto" Then
   Reloj_Temporizador()
   $inicio = TimerInit()
 EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Wend
Exit

; RELOJ_TEMPORIZADOR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func Reloj_Temporizador()
$x = Random(1,3,1)
$y = Random(1,3,1)
$z = Random(1,3,1)

 if $x = 1 Then
   GUICtrlSetImage ($Pic1, "fresa.gif")
 EndIf
 if $x = 2 Then
   GUICtrlSetImage ($Pic1, "limon.gif")
 EndIf
 if $x = 3 Then
   GUICtrlSetImage ($Pic1, "pera.gif")
 EndIf

 if $y = 1 Then
   GUICtrlSetImage ($Pic2, "fresa.gif")
 EndIf
 if $y = 2 Then
   GUICtrlSetImage ($Pic2, "limon.gif")
 EndIf
   if $y = 3 Then
   GUICtrlSetImage ($Pic2, "pera.gif")
 EndIf

 if $z = 1 Then
   GUICtrlSetImage ($Pic3, "fresa.gif")
 EndIf
   if $z = 2 Then
   GUICtrlSetImage ($Pic3, "limon.gif")
 EndIf
   if $z = 3 Then
   GUICtrlSetImage ($Pic3, "pera.gif")
 EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

- Lo ejecutamos: Tools / Go. [En caso de que ya estuviera funcionando pulsamos "Tools / Stop Executing"]

- La convertimos en autoejecutable mediante Aut2Exe, aqui está: tres_iguales.exe

_________________
- Propuesta.

- Crea otra etiqueta donde se muestre la relación entre aciertos e intentos.
Obtén la probabilidad de acertar:

Hay 3 elevado a 3 = 27 combinaciones posibles y 3 aciertos.

Luego la probabilidad de acertar es 3 / 27 = 1 / 9

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información