Comment rendre mon programme plus rapide ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Comment rendre mon programme plus rapide ?

Message par Micoute »

Bonjour à tous,

toujours dans mes programmes destinés à mes petits enfants, je souhaiterais améliorer l'initialisation pour rendre ce logiciel, un poil plus rapide.

Je viens donc une fois de plus, solliciter votre aide bienveillante et je vous en remercie beaucoup par anticipation.

Code : Tout sélectionner

;Capitales de l'Europe des 27
Enumeration Fenetres
  #Fenetre_principale
EndEnumeration

Enumeration Gadgets
  #Txt_0
  #Txt_1
  #Txt_2
  #Txt_3
  #Txt_4
  #Txt_5
  #Txt_6
  #Txt_7
  #Txt_8
  #Txt_9
  #Txt_10
  #Txt_11
  #Txt_12
  #Txt_13
  #Txt_14
  #Txt_15
  #Txt_16
  #Txt_17
  #Txt_18
  #Txt_19
  #Txt_20
  #Txt_21
  #Txt_22
  #Txt_23
  #Txt_24
  #Cmb_0
  #Cmb_1
  #Cmb_2
  #Cmb_3
  #Cmb_4
  #Cmb_5
  #Cmb_6
  #Cmb_7
  #Cmb_8
  #Cmb_9
  #Cmb_10
  #Cmb_11
  #Cmb_12
  #Cmb_13
  #Cmb_14
  #Cmb_15
  #Cmb_16
  #Cmb_17
  #Cmb_18
  #Cmb_19
  #Cmb_20
  #Cmb_21
  #Cmb_22
  #Cmb_23
  #Cmb_24
  #Btn_Verifier
  #Ctn_0
  #Ctn_1
EndEnumeration

Enumeration Polices
  #Police
EndEnumeration

Structure Jeu
  Points.i
  C0.b
  C1.b
  C2.b
  C3.b
  C4.b
  C5.b
  C6.b
  C7.b
  C8.b
  C9.b
  C10.b
  C11.b
  C12.b
  C13.b
  C14.b
  C15.b
  C16.b
  C17.b
  C18.b
  C19.b
  C20.b
  C21.b
  C22.b
  C23.b
  C24.b
EndStructure

;Déclarations des variables
Global NbQuestions = 24, Dim Question.s(NbQuestions), Dim Reponse.s(NbQuestions), Dim RndReponse.s(NbQuestions), Evenement, 
       Police = LoadFont(#Police, "FontAwesome", 18, #PB_Font_Bold|#PB_Font_HighQuality)
Global.Jeu NbPoints, Verif


NbPoints\Points = 0
Verif\C0 = #False
Verif\C1 = #False
Verif\C2 = #False
Verif\C3 = #False
Verif\C4 = #False
Verif\C5 = #False
Verif\C6 = #False
Verif\C7 = #False
Verif\C8 = #False
Verif\C9 = #False
Verif\C10 = #False
Verif\C11 = #False
Verif\C12 = #False
Verif\C13 = #False
Verif\C14 = #False
Verif\C15 = #False
Verif\C16 = #False
Verif\C17 = #False
Verif\C18 = #False
Verif\C19 = #False
Verif\C20 = #False
Verif\C21 = #False
Verif\C22 = #False
Verif\C23 = #False
Verif\C24 = #False

SetGadgetFont(#PB_Default,FontID(#Police))

;Lecture des questions
Procedure Lire_les_donnees()
Restore Debut
For i = 0 To NbQuestions
  Read.s Question(i)
  Read.s Reponse(i)
Next i

;Lectures des réponses
;Restore Reponse
For i = 0 To NbQuestions
  RndReponse(i) = Reponse(i)
Next i

;Mélanges des réponses
RandomizeArray(RndReponse())
SortArray(RndReponse(), #PB_Sort_Ascending)
EndProcedure

Procedure.s Clic_Btn_Verifier()
  If GetGadgetText(#Cmb_0) = Reponse(0)
    If Verif\C0 = #False
      SetGadgetColor(#Txt_0, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C0 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_0, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_0, Reponse(0))
  EndIf
  
  If GetGadgetText(#Cmb_1) = Reponse(1)
    If Verif\C1 = #False
      SetGadgetColor(#Txt_1, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C1 = #True
    EndIf
  Else
     SetGadgetColor(#Txt_1, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_1, Reponse(1))
  EndIf
  NbPoints\Points + Points
  
  If GetGadgetText(#Cmb_2) = Reponse(2)
    If Verif\C2 = #False
      SetGadgetColor(#Txt_2, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C2 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_2, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_2, Reponse(2))
  EndIf
  
  If GetGadgetText(#Cmb_3) = Reponse(3)
    If Verif\C3 = #False
      SetGadgetColor(#Txt_3, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C3 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_3, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_3, Reponse(3))
  EndIf
  
  If GetGadgetText(#Cmb_4) = Reponse(4)
    If Verif\C4 = #False
      SetGadgetColor(#Txt_4, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C4 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_4, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_4, Reponse(4))
  EndIf
  
  If GetGadgetText(#Cmb_5) = Reponse(5)
    If Verif\C5 = #False
      SetGadgetColor(#Txt_5, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C5 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_5, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_5, Reponse(5))
  EndIf
  
  If GetGadgetText(#Cmb_6) = Reponse(6)
    If Verif\C6 = #False
      SetGadgetColor(#Txt_6, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C6 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_6, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_6, Reponse(6))
  EndIf
  
  If GetGadgetText(#Cmb_7) = Reponse(7)
    If Verif\C7 = #False
      SetGadgetColor(#Txt_7, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C7 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_7, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_7, Reponse(7))
  EndIf
  
  If GetGadgetText(#Cmb_8) = Reponse(8)
    If Verif\C8 = #False
      SetGadgetColor(#Txt_8, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C8 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_8, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_8, Reponse(8))
  EndIf
  
  If GetGadgetText(#Cmb_9) = Reponse(9)
    If Verif\C9 = #False
      SetGadgetColor(#Txt_9, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C9 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_9, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_9, Reponse(9))
  EndIf
  
  If GetGadgetText(#Cmb_10) = Reponse(10)
    If Verif\C10 = #False
      SetGadgetColor(#Txt_10, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C10 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_10, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_10, Reponse(10))
  EndIf
  
  If GetGadgetText(#Cmb_11) = Reponse(11)
    If Verif\C11 = #False
      SetGadgetColor(#Txt_11, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C11 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_11, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_11, Reponse(11))
  EndIf
  
  If GetGadgetText(#Cmb_12) = Reponse(12)
    If Verif\C12 = #False
      SetGadgetColor(#Txt_12, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C12 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_12, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_12, Reponse(12))
  EndIf
  
  If GetGadgetText(#Cmb_13) = Reponse(13)
    If Verif\C13 = #False
      SetGadgetColor(#Txt_13, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C13 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_13, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_13, Reponse(13))
  EndIf
  
  If GetGadgetText(#Cmb_14) = Reponse(14)
    If Verif\C14 = #False
      SetGadgetColor(#Txt_14, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C14 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_14, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_14, Reponse(14))
  EndIf
  
  If GetGadgetText(#Cmb_15) = Reponse(15)
    If Verif\C15 = #False
      SetGadgetColor(#Txt_15, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C15 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_15, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_15, Reponse(15))
  EndIf
  
  If GetGadgetText(#Cmb_16) = Reponse(16)
    If Verif\C16 = #False
      SetGadgetColor(#Txt_16, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C16 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_16, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_16, Reponse(16))
  EndIf
  
  If GetGadgetText(#Cmb_17) = Reponse(17)
    If Verif\C17 = #False
      SetGadgetColor(#Txt_17, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C17 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_17, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_17, Reponse(17))
  EndIf
  
  If GetGadgetText(#Cmb_18) = Reponse(18)
    If Verif\C18 = #False
      SetGadgetColor(#Txt_18, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C18 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_18, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_18, Reponse(18))
  EndIf
  
  If GetGadgetText(#Cmb_19) = Reponse(19)
    If Verif\C19 = #False
      SetGadgetColor(#Txt_19, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C19 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_19, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_19, Reponse(19))
  EndIf
  
  If GetGadgetText(#Cmb_20) = Reponse(20)
    If Verif\C20 = #False
      SetGadgetColor(#Txt_20, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C20 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_20, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_20, Reponse(20))
  EndIf
  
  If GetGadgetText(#Cmb_21) = Reponse(21)
    If Verif\C21 = #False
      SetGadgetColor(#Txt_21, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C21 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_21, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_21, Reponse(21))
  EndIf
  
  If GetGadgetText(#Cmb_22) = Reponse(22)
    If Verif\C22 = #False
      SetGadgetColor(#Txt_22, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C22 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_22, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_22, Reponse(22))
  EndIf
  
  If GetGadgetText(#Cmb_23) = Reponse(23)
    If Verif\C23 = #False
      SetGadgetColor(#Txt_23, #PB_Gadget_FrontColor, $7F00)
      Points + 10
      Verif\C23 = #True
    EndIf
  Else
    SetGadgetColor(#Txt_23, #PB_Gadget_FrontColor, $FF)
    SetGadgetText(#Cmb_23, Reponse(23))
  EndIf
  
  ;If GetGadgetText(#Cmb_24) = Reponse(24)
  ;  If Verif\C24 = #False
  ;    SetGadgetColor(#Txt_24, #PB_Gadget_FrontColor, $7F00)
  ;    Points + 10
  ;    Verif\C24 = #True
  ;  EndIf
  ;Else
  ;  SetGadgetColor(#Txt_24, #PB_Gadget_FrontColor, $FF)
  ;  SetGadgetText(#Cmb_24, Reponse(24))
  ;EndIf
  
  NbPoints\Points = Points
  
  If NbPoints\Points = 0
    MessageRequester("Info", "Hélas, tu n'as aucun point")
  Else
    MessageRequester("Info", "Bravo, tu as " + Str(NbPoints\Points) + " points")
  EndIf
  Points = 0
  
EndProcedure

;Questionnaire
Procedure Ouvrir_Questionnaire()
OpenWindow(#Fenetre_principale, 0, 0, 1600, 680, "Capitales de l'Europe des 27", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  
ContainerGadget(#Ctn_0, 0, 10, 800, 585)
TextGadget(#Txt_0, 10, 3, 500, 25, Question(0), #PB_Text_Right)
ComboBoxGadget(#Cmb_0, 520, 0, 270, 35)

TextGadget(#Txt_1, 10, 53, 500, 25, Question(1), #PB_Text_Right)
ComboBoxGadget(#Cmb_1, 520, 50, 270, 35) 

TextGadget(#Txt_2, 10, 103, 500, 25, Question(2), #PB_Text_Right)
ComboBoxGadget(#Cmb_2, 520, 100, 270, 35)  

TextGadget(#Txt_3, 10, 153, 500, 25, Question(3), #PB_Text_Right)
ComboBoxGadget(#Cmb_3, 520, 150, 270, 35)

TextGadget(#Txt_4, 10, 203, 500, 25, Question(4), #PB_Text_Right)
ComboBoxGadget(#Cmb_4, 520, 200, 270, 35)

TextGadget(#Txt_5, 10, 253, 500, 25, Question(5), #PB_Text_Right)
ComboBoxGadget(#Cmb_5, 520, 250, 270, 35)

TextGadget(#Txt_6, 10, 303, 500, 25, Question(6), #PB_Text_Right)
ComboBoxGadget(#Cmb_6, 520, 300, 270, 35)

TextGadget(#Txt_7, 10, 353, 500, 25, Question(7), #PB_Text_Right)
ComboBoxGadget(#Cmb_7, 520, 350, 270, 35)

TextGadget(#Txt_8, 10, 403, 500, 25, Question(8), #PB_Text_Right)
ComboBoxGadget(#Cmb_8, 520, 400, 270, 35)

TextGadget(#Txt_9, 10, 453, 500, 25, Question(9), #PB_Text_Right)
ComboBoxGadget(#Cmb_9, 520, 450, 270, 35)

TextGadget(#Txt_10, 10, 503, 500, 25, Question(10), #PB_Text_Right)
ComboBoxGadget(#Cmb_10, 520, 500, 270, 35) 

TextGadget(#Txt_11, 10, 553, 500, 25, Question(11), #PB_Text_Right)
ComboBoxGadget(#Cmb_11, 520, 550, 270, 35)
CloseGadgetList()

ContainerGadget(#Ctn_1, 800, 10, 800, 585)
TextGadget(#Txt_12, 10, 3, 500, 25, Question(12), #PB_Text_Right)
ComboBoxGadget(#Cmb_12, 520, 0, 270, 35)  

TextGadget(#Txt_13, 10, 53, 500, 25, Question(13), #PB_Text_Right)
ComboBoxGadget(#Cmb_13, 520, 50, 270, 35)

TextGadget(#Txt_14, 10, 103, 500, 25, Question(14), #PB_Text_Right)
ComboBoxGadget(#Cmb_14, 520, 100, 270, 35)

TextGadget(#Txt_15, 10, 153, 500, 25, Question(15), #PB_Text_Right)
ComboBoxGadget(#Cmb_15, 520, 150, 270, 35) 

TextGadget(#Txt_16, 10, 203, 500, 25, Question(16), #PB_Text_Right)
ComboBoxGadget(#Cmb_16, 520, 200, 270, 35)

TextGadget(#Txt_17, 10, 253, 500, 25, Question(17), #PB_Text_Right)
ComboBoxGadget(#Cmb_17, 520, 250, 270, 35) 

TextGadget(#Txt_18, 10, 303, 500, 25, Question(18), #PB_Text_Right)
ComboBoxGadget(#Cmb_18, 520, 300, 270, 35)  

TextGadget(#Txt_19, 10, 353, 500, 25, Question(19), #PB_Text_Right)
ComboBoxGadget(#Cmb_19, 520, 350, 270, 35)

TextGadget(#Txt_20, 10, 403, 500, 25, Question(20), #PB_Text_Right)
ComboBoxGadget(#Cmb_20, 520, 400, 270, 35)  

TextGadget(#Txt_21, 10, 453, 500, 25, Question(21), #PB_Text_Right)
ComboBoxGadget(#Cmb_21, 520, 450, 270, 35)

TextGadget(#Txt_22, 10, 503, 500, 25, Question(22), #PB_Text_Right)
ComboBoxGadget(#Cmb_22, 520, 500, 270, 35)

TextGadget(#Txt_23, 10, 553, 500, 25, Question(23), #PB_Text_Right)
ComboBoxGadget(#Cmb_23, 520, 550, 270, 35)
CloseGadgetList()

ButtonGadget(#Btn_Verifier, 765, 620, 70, 25, "Vérifier")

  For i = 0 To NbQuestions
    AddGadgetItem(#Cmb_0, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_1, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_2, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_3, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_4, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_5, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_6, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_7, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_8, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_9, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_10, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_11, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_12, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_13, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_14, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_15, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_16, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_17, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_18, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_19, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_20, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_21, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_22, - 1, RndReponse(i))
    AddGadgetItem(#Cmb_23, - 1, RndReponse(i))
  Next i  

;BindGadgetEvent(#Btn_Verifier, @Clic_Btn_Verifier())
EndProcedure

Lire_les_donnees()
Ouvrir_Questionnaire()

;Boucle événementielle
Repeat
  Evenement = WaitWindowEvent()
  Select Evenement
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      Select EventGadget
        Case #Btn_Verifier
          Clic_Btn_Verifier()
      EndSelect
      Case #PB_Event_CloseWindow
        Select EventWindow()
          Case #Fenetre_principale
            CloseWindow(#Fenetre_principale)
            Break
        EndSelect
  EndSelect
ForEver

DataSection
  Debut:
Data.s "Dans quel pays se situe Madrid ?", "Espagne"
Data.s "Quelle est la capitale de la Finlande ?", "Helsinki"
Data.s "Où se situe Varsovie ?", "Pologne"
Data.s "Quelle est la capitale de l'Allemagne ?", "Berlin"
Data.s "Où se situe Dublin ?", "Irlande"
Data.s "Où se situe Stockholm ?", "Suède"
Data.s "Quelle est la capitale du Danemark ?", "Copenhague"
Data.s "Où se situe Vienne ?", "Autriche"
Data.s "Quelle est la capitale de la Grèce ?", "Athènes"
Data.s "Où se situe Budapest ?", "Hongrie"
Data.s "Quelle est la capitale de la Slovénie ?", "Ljubljana"
Data.s "Où se situe Bruxelles ?", "Belgique"
Data.s "Où se situe Luxembourg ?", "Grand-Duché du Luxembourg"
Data.s "Quelle est la capitale du Royaume-Uni ?", "Londres"
Data.s "Où se situe Rome ?", "Italie"
Data.s "Quelle est la capitale de la Slovaquie ?", "Bratislava"
Data.s "Où se situe La Valette ?", "Malte"
Data.s "Quelle est la capitale de Chypre ?", "Nicosie"
Data.s "Où se situe Prague ?", "République tchèque"
Data.s "Où se situe Vilnius ?", "Lituanie"
Data.s "Quelle est la capitale de la Lettonie ?", "Riga"
Data.s "Où se situe Tallinn ?", "Estonie"
Data.s "Où se situe Lisbonne ?", "Portugal"
Data.s "Quelle est la capitale des Pays-Bas ?", "Amsterdam"
Data.s "Où se situe Paris ?", "France"
EndDataSection
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Comment rendre mon programme plus rapide ?

Message par Ar-S »

Je serai toi je créerai un fichier texte ou une base de données (json, pref, xml etc.. les choix ne manquent pas) et je chargerai toutes les questions/réponses avant d'ouvrir le programme.
En y cogitant bien, tu n'aurais même plus besoin de modifier le code pour ajouter des questions/réponses supplémentaires.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: Comment rendre mon programme plus rapide ?

Message par Micoute »

Merci Ar-s, comme d'habitude, c'est tellement évident que je n'y ai même pas pensé.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Comment rendre mon programme plus rapide ?

Message par falsam »

Un poil plus rapide n'est pas nécessaire par contre plus lisible et plus court c'est possible.

Code : Tout sélectionner

EnableExplicit

Enumeration fonts
  #FontGlobal  
  #FontWait
EndEnumeration

Enumeration window
  #MainForm
EndEnumeration

Enumeration 0 Step 24
  #Question ;25 Qestions
EndEnumeration

Enumeration #PB_Compiler_EnumerationValue + 1 Step 24
  #Reponse ;25 Réponses 
EndEnumeration

Enumeration #PB_Compiler_EnumerationValue  + 1
  #Wait
  #Evaluer
  #Corriger
EndEnumeration

;Structure d'une question
Structure Question
  question.s        ;Question
  reponse.s         ;La bonne réponse
  List reponse$()   ;choix de réponses 
EndStructure

Global NewList Questions.Question()
Global NbQuestions = 25

;Plan de l'application
Declare Start()
Declare LireQuestionnaire()
Declare AfficherQuestionnaire()
Declare CorrigerQuestionnaire()
Declare Exit()

Start()

;Afficher l'application
Procedure Start()
  LoadFont(#FontGlobal, "Arial", 11)
  LoadFont(#FontWait, "Arial", 30)
  SetGadgetFont(#PB_Default, FontID(#FontGlobal))
  
  OpenWindow(#MainForm, 0, 0, 1024, 700, "Elections régionales", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)    
  
  ;Afficher le wait .....
  TextGadget(#Wait, 20, 650, 1000, 200, "Chargement des questions .....")
  SetGadgetFont(#Wait, FontID(#FontWait))
  
  ;Lire et afficher les questions      
  LireQuestionnaire()
  AfficherQuestionnaire()
  
  ;Cacher le wait
  HideGadget(#Wait, #True)
  
  ButtonGadget(#Evaluer, 400, 670, 80, 24, "Evaluer")
  ButtonGadget(#Corriger, 500, 670, 80, 24, "Correction")
  
  ;Evenements
  BindEvent(#PB_Event_CloseWindow, @Exit())
  BindGadgetEvent(#Evaluer, @CorrigerQuestionnaire())
  BindGadgetEvent(#Corriger, @CorrigerQuestionnaire())
  
  Repeat : WaitWindowEvent() : ForEver  
EndProcedure


;Lecture des questions
Procedure LireQuestionnaire()
  Protected Dim Reponses.s(24), i
  
  ;Lecture des question se trouvant en datasection
  Restore Debut
  For i = 0 To NbQuestions-1
    AddElement(Questions())
    Read.s Questions()\question        ;Question 
    Read.s Questions()\reponse         ;Reponse exacte
    
    ;Ajout de la réponse dans le tableau des réponses 
    Reponses(i) = Questions()\reponse  ;Liste des réponses possibles
  Next
  
  ;Tri des réponses dans l'ordre alphabétique
  SortArray(Reponses(), #PB_Sort_Ascending | #PB_Sort_NoCase)
  
  ;Pour chaque question, ajout du tableau des réponses.
  ForEach Questions()
    For i = 0 To NbQuestions - 1
      AddElement(Questions()\reponse$())
      Questions()\reponse$() = Reponses(i)
    Next
  Next
  
  ;Mélange des questions
  RandomizeList(Questions())
EndProcedure

;Afficher le questionnaire
Procedure AfficherQuestionnaire()
  Protected x = 20, y = 20,  z = 0, Index
  
  ForEach Questions()
    Index = ListIndex(Questions())
    
    ;Posez la question
    TextGadget(#Question + Index, x, y, 300, 50, Questions()\question)
    HideGadget(#Question + Index, #True)
    
    ;Proposer des réponses
    ComboBoxGadget(#Reponse + Index, x + 310, y, 150, 22)
    HideGadget(#Reponse + Index, #True)
    
    ;Proposer les réponses 
    ForEach Questions()\reponse$()
      AddGadgetItem(#Reponse + Index, -1, Questions()\reponse$()) 
    Next
    
    y + 50
    z + 1
    
    If z = 12 ;12 questions par colonne
      y = 20
      x = 500
    EndIf
    
  Next
  
  For Index = 0 To NbQuestions-1
    HideGadget(#Question + Index, #False)
    HideGadget(#Reponse + Index, #False)
  Next
  
EndProcedure

Procedure CorrigerQuestionnaire()
  Protected Gadget, Index, RightAnswer
  Protected Button = EventGadget()
  
  If Button = #Corriger
    DisableGadget(#Evaluer, #True)
    DisableGadget(#Corriger, #True)
  EndIf

  
  For index = 0 To NbQuestions-1
    Gadget = #Reponse + Index
    
    SelectElement(Questions(), index)
    
    If Button = #Corriger
      SetGadgetText(#Question + Index, GetGadgetText(#Question + Index)  + #CRLF$ + "R: " + Questions()\reponse)  
      DisableGadget(#Reponse + Index, #True)
    EndIf
        
    If GetGadgetItemText(Gadget, GetGadgetState(Gadget)) = Questions()\reponse
      RightAnswer + 1
      SetGadgetColor(#Question + index , #PB_Gadget_FrontColor, #Green)
    Else
      SetGadgetColor(#Question + index, #PB_Gadget_FrontColor, #Red)
    EndIf  
  Next
  
  If RightAnswer = NbQuestions
    MessageRequester("Information", "Bravo, Vous avez atteint le score maximum" + #CRLF$ +"de " + RightAnswer + " points.")
  Else
    MessageRequester("Information", "Vous avez atteint le score de " + RightAnswer + " points.") 
  EndIf  
EndProcedure  

Procedure Exit()
  End  
EndProcedure

DataSection
  Debut:
  Data.s "Dans quel pays se situe Madrid ?", "Espagne"
  Data.s "Quelle est la capitale de la Finlande ?", "Helsinki"
  Data.s "Où se situe Varsovie ?", "Pologne"
  Data.s "Quelle est la capitale de l'Allemagne ?", "Berlin"
  Data.s "Où se situe Dublin ?", "Irlande"
  Data.s "Où se situe Stockholm ?", "Suède"
  Data.s "Quelle est la capitale du Danemark ?", "Copenhague"
  Data.s "Où se situe Vienne ?", "Autriche"
  Data.s "Quelle est la capitale de la Grèce ?", "Athènes"
  Data.s "Où se situe Budapest ?", "Hongrie"
  Data.s "Quelle est la capitale de la Slovénie ?", "Ljubljana"
  Data.s "Où se situe Bruxelles ?", "Belgique"
  Data.s "Où se situe Luxembourg ?", "Grand-Duché du Luxembourg"
  Data.s "Quelle est la capitale du Royaume-Uni ?", "Londres"
  Data.s "Où se situe Rome ?", "Italie"
  Data.s "Quelle est la capitale de la Slovaquie ?", "Bratislava"
  Data.s "Où se situe La Valette ?", "Malte"
  Data.s "Quelle est la capitale de Chypre ?", "Nicosie"
  Data.s "Où se situe Prague ?", "République tchèque"
  Data.s "Où se situe Vilnius ?", "Lituanie"
  Data.s "Quelle est la capitale de la Lettonie ?", "Riga"
  Data.s "Où se situe Tallinn ?", "Estonie"
  Data.s "Où se situe Lisbonne ?", "Portugal"
  Data.s "Quelle est la capitale des Pays-Bas ?", "Amsterdam"
  Data.s "Où se situe Paris ?", "France"
EndDataSection
J'ai ajouter un bouton qui permet d'évaluer le nombre de bonnes réponses. Ce qui permet de continuer à jouer avant de cliquer sur le bouton Corriger.

Tu noteras aussi l'astuces de l'énumération qui permet de ne pas lister 25 textes par exemple ^^.

J'en ai profité pour réviser un peu. Merci.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: Comment rendre mon programme plus rapide ?

Message par Micoute »

Simple, astucieux et efficace, c'est moi qui te remercie, et pas qu'un peu !
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Répondre