[Résolu] Problème de relancement de programme
Publié : mar. 12/août/2014 13:07
Bonjour à tous,
je voudrais faire un programme pour mes petits enfants, qui se relance quand on presse le bouton "recommencer", mais le problème c'est qu'il m'envoie toujours la même séquence, bien évidemment il y aura des cases à remplir, mais pour l'instant, ce n'est qu'une ébauche.
Je vous remercie tous par anticipation.
Michel
je voudrais faire un programme pour mes petits enfants, qui se relance quand on presse le bouton "recommencer", mais le problème c'est qu'il m'envoie toujours la même séquence, bien évidemment il y aura des cases à remplir, mais pour l'instant, ce n'est qu'une ébauche.
Code : Tout sélectionner
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Fenetre_principale
EndEnumeration
;}
;{ Gadgets
Enumeration
#Txt_operation
#Txt_sgn
#Str_terme_1
#Str_terme_2
#Str_Resultat
#Txt_egal
#Btn_Recommencer
EndEnumeration
;}
;{ Polices
Enumeration
#Police_Txt_operation
#Police_Txt_sgn
#Police_Str_terme_1
#Police_Str_terme_2
#Police_Str_Resultat
#Police_Txt_egal
EndEnumeration
;}
Global.i Evenement, hasard, terme_1, terme_2, Resultat
Global Dim signes.s(1,3)
;}
signes(0,0) = "+" : signes(1,0) = "addition"
signes(0,1) = "-" : signes(1,1) = "soustraction"
signes(0,2) = "x" : signes(1,2) = "multiplication"
signes(0,3) = "/" : signes(1,3) = "division"
Procedure initialiser()
hasard = Random(3,0)
terme_1 = Random(9,1)
terme_2 = Random(9,1)
If hasard = 0
Resultat = terme_1 + terme_2
ElseIf hasard = 1
Resultat = terme_1 - terme_2
ElseIf hasard = 2
Resultat = terme_1 * terme_2
ElseIf hasard = 3 And terme_1 >= terme_2
Resultat = terme_1 / terme_2
ElseIf hasard = 3 And terme_1 < terme_2
x = terme_1
terme_1 = terme_2
terme_2 = x
Resultat = terme_1 / terme_2
EndIf
EndProcedure
Procedure OpenWindow_Fenetre_principale()
If OpenWindow(#Fenetre_principale, 568, 165, 224, 462, "Opérations", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
TextGadget(#Txt_operation, 15, 20, 195, 35, "", #PB_Text_Center)
TextGadget(#Txt_sgn, 72, 130, 70, 50, "", #PB_Text_Center)
StringGadget(#Str_terme_1, 80, 65, 55, 50, "")
StringGadget(#Str_terme_2, 80, 205, 55, 50, "")
StringGadget(#Str_Resultat, 65, 325, 80, 50, "")
TextGadget(#Txt_egal, 25, 270, 170, 50, "=", #PB_Text_Center)
ButtonGadget(#Btn_Recommencer, 45, 405, 110, 35, "Recommencer")
; Gadget Fonts
SetGadgetFont(#Txt_operation, LoadFont(#Police_Txt_operation, "Verdana", 18, #PB_Font_HighQuality))
SetGadgetFont(#Txt_sgn, LoadFont(#Police_Txt_sgn, "Verdana", 28, #PB_Font_HighQuality))
SetGadgetFont(#Str_terme_1, LoadFont(#Police_Str_terme_1, "Verdana", 28, #PB_Font_HighQuality))
SetGadgetFont(#Str_terme_2, LoadFont(#Police_Str_terme_2, "Verdana", 28, #PB_Font_HighQuality))
SetGadgetFont(#Str_Resultat, LoadFont(#Police_Str_Resultat, "Verdana", 28, #PB_Font_HighQuality))
SetGadgetFont(#Txt_egal, LoadFont(#Police_Txt_egal, "Verdana", 28, #PB_Font_HighQuality))
EndIf
EndProcedure
initialiser()
OpenWindow_Fenetre_principale()
SetGadgetText(#Txt_sgn, signes(0, hasard))
SetGadgetText(#Txt_operation, signes(1,hasard))
SetGadgetText(#Str_terme_1,Str(terme_1))
SetGadgetText(#Str_terme_2,Str(terme_2))
SetGadgetText(#Str_Resultat,Str(Resultat))
;{- Boucle d'événements
Repeat
Evenement = WaitWindowEvent()
Select Evenement
; ///////////////////
Case #PB_Event_Gadget
Select EventGadget()
Case #Txt_operation
Case #Txt_sgn
Case #Str_terme_1
Case #Str_terme_2
Case #Str_Resultat
Case #Txt_egal
Case #Btn_Recommencer
initialiser()
EndSelect
; ////////////////////////
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Fenetre_principale
CloseWindow(#Fenetre_principale)
Break
EndSelect
EndSelect
ForEver
;
;}
Michel