Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando
-- Tutorial de iniciación a Autoit --
Volver al índice del tutorial
____________________________
12.- Ruleta rusa.
ruleta_rusa.exe
- En este caso tenemos un revólver para 6 balas.
- Primero Rearmamos el revólver poniendo una sola bala y girando el tambor. La bala se ubicará aleatoriamente en uno de los 6 sitios.
- Luego vamos pulsando de manera desordenada los distintos botones .
- Si el número de lugar de la bala coincide con el número del Botón pulsado, la pantalla se tiñe de rojo
- En caso contrario se deshabilita ($GUI_DISABLE) el botón pulsado.
- Este código es similar al que vimos en App Inventor: Ruleta rusa.
__________________________
- Ejecutamos Koda para crear el formulario.
- Creamos el siguiente Formulario. Ponemos 6 Botones de igual tamaño y luego uno más ancho como se ve en la imagen.
- He puesto la Propiedad Font de los botones a Size: 20 y Bold (negrita)
- 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 Ruleta rusa.
Ruleta rusa. |
$x = 1
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1 ; Presiona Botón1
if $x = 1 Then
GUISetBkColor(0xFF0000) ; Si x = 1, Formulario en rojo
Else
GUICtrlSetState($Button1, $GUI_DISABLE) ; Deshabilita el Botón1
EndIf
Case $msg = $Button2 ; Presiona Botón2
if $x = 2 Then
GUISetBkColor(0xFF0000) ; Si x = 2, Formulario en rojo
Else
GUICtrlSetState($Button2, $GUI_DISABLE) ; Deshabilita el Botón2
EndIf
Case $msg = $Button3 ; Presiona Botón3
if $x = 3 Then
GUISetBkColor(0xFF0000) ; Si x = 3, Formulario en rojo
Else
GUICtrlSetState($Button3, $GUI_DISABLE) ; Deshabilita el Botón3
EndIf
Case $msg = $Button4 ; Presiona Botón4
if $x = 4 Then
GUISetBkColor(0xFF0000) ; Si x = 4, Formulario en rojo
Else
GUICtrlSetState($Button4, $GUI_DISABLE) ; Deshabilita el Botón4
EndIf
Case $msg = $Button5 ; Presiona Botón5
if $x = 5 Then
GUISetBkColor(0xFF0000) ; Si x = 5, Formulario en rojo
Else
GUICtrlSetState($Button5, $GUI_DISABLE) ; Deshabilita el Botón5
EndIf
Case $msg = $Button6 ; Presiona Botón6
if $x = 6 Then
GUISetBkColor(0xFF0000) ; Si x = 6, Formulario en rojo
Else
GUICtrlSetState($Button6, $GUI_DISABLE) ; Deshabilita el Botón6
EndIf
Case $msg = $Button7 ; Rearme.
$x = Random(1,6,1) ; Crea un número aleatorio del 1 al 6
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
GUICtrlSetState($Button4, $GUI_ENABLE)
GUICtrlSetState($Button5, $GUI_ENABLE)
GUICtrlSetState($Button6, $GUI_ENABLE)
GUISetBkColor(0xFFFFFF) ; Formulario en Blanco.
EndSelect
Wend
Exit
|
- La parte azul de arriba y abajo la insertaremos también.
ruleta_rusa.au3 |
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Ruleta rusa - Juan A. Villalpando", 645, 487, 398, 194)
$Button1 = GUICtrlCreateButton("1", 32, 24, 89, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("2", 128, 24, 89, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("3", 224, 24, 89, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button4 = GUICtrlCreateButton("4", 320, 24, 91, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button5 = GUICtrlCreateButton("5", 416, 24, 89, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button6 = GUICtrlCreateButton("6", 512, 24, 89, 65)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
$Button7 = GUICtrlCreateButton("Rearme", 40, 192, 561, 89)
GUICtrlSetFont(-1, 22, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$x = 1
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1 ; Presiona Botón1
if $x = 1 Then
GUISetBkColor(0xFF0000) ; Si x = 1, Formulario en rojo
Else
GUICtrlSetState($Button1, $GUI_DISABLE) ; Deshabilita el Botón1
EndIf
Case $msg = $Button2 ; Presiona Botón2
if $x = 2 Then
GUISetBkColor(0xFF0000) ; Si x = 2, Formulario en rojo
Else
GUICtrlSetState($Button2, $GUI_DISABLE) ; Deshabilita el Botón2
EndIf
Case $msg = $Button3 ; Presiona Botón3
if $x = 3 Then
GUISetBkColor(0xFF0000) ; Si x = 3, Formulario en rojo
Else
GUICtrlSetState($Button3, $GUI_DISABLE) ; Deshabilita el Botón3
EndIf
Case $msg = $Button4 ; Presiona Botón4
if $x = 4 Then
GUISetBkColor(0xFF0000) ; Si x = 4, Formulario en rojo
Else
GUICtrlSetState($Button4, $GUI_DISABLE) ; Deshabilita el Botón4
EndIf
Case $msg = $Button5 ; Presiona Botón5
if $x = 5 Then
GUISetBkColor(0xFF0000) ; Si x = 5, Formulario en rojo
Else
GUICtrlSetState($Button5, $GUI_DISABLE) ; Deshabilita el Botón5
EndIf
Case $msg = $Button6 ; Presiona Botón6
if $x = 6 Then
GUISetBkColor(0xFF0000) ; Si x = 6, Formulario en rojo
Else
GUICtrlSetState($Button6, $GUI_DISABLE) ; Deshabilita el Botón6
EndIf
Case $msg = $Button7 ; Rearme.
$x = Random(1,6,1) ; Crea un número aleatorio del 1 al 6
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
GUICtrlSetState($Button4, $GUI_ENABLE)
GUICtrlSetState($Button5, $GUI_ENABLE)
GUICtrlSetState($Button6, $GUI_ENABLE)
GUISetBkColor(0xFFFFFF) ; Formulario en Blanco.
EndSelect
Wend
Exit
|
- Lo ejecutamos: Tools / Go. [En caso de que ya estuviera funcionando pulsamos "Stop Executing"]
Cuando pulsamos el botón de Rearmar, Botón7, se crea un número aleatorio del 1 al 6, se habilitan todos los botones y el fondo de la pantalla se pone en blanco.
Cuando pulsamos cualquier botón:
- Si el valor x generado aleatoriamente en el rearme coincide con el número del Botón, se pone la pantalla roja.
- En caso contrario, se Deshabilita el botón pulsado.
- La convertimos en autoejecutable mediante Aut2Exe, aqui está: ruleta_rusa.exe
_________________
- Propuesta.
- Realiza el busca minas que vimos al final del tutorial de App Inventor: Ruleta rusa.
|