Voici un petit jeu ....

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

Déjà, peut-être devrais-tu vérifier les 3 chiffres, car si tu as 2 septs, tu es censé gagné 2 fois la mise, donc +10 dans ton programme

Code : Tout sélectionner

If R1=7
   gains=gains+5
endif
If R2=7
   gains=gains+5
endif
If R3=7
   gains=gains+5
endif
Je suppose que c'était ça ton problème de score ?

sinon, je m'étais permis de modifier ton code pour ajouter un "effet graphique" sur les chiffres :


;***** Bandit manchot *****
;***** écris par Jbernard *****

;**** Constantes *****
Enumeration
     #Fenetre_main
     #Cadre_0
     #cadre_1
     #Titre
     #Titre2
     #Titre3
     #string_Resultat
     #Texte_Gains
     #string_Gains
     #Bouton_lancer
     #Bouton_rejouer
     #Font1
     #Font2
     #Font3
     #Font4
     #Font5
EndEnumeration

;**** Déclarations des variables ****
;*** Pour les polices ***
Global Font01,Font02,font03,Font04,Font05
;*** Pour le calcul du resultat et du gains
Global Resultat,gains
;*** Chargement de la police ****
Font01= loadfont ( #Font1 , "arial" ,20, #PB_Font_Bold )
Font02= loadfont ( #Font2 , "arial" ,50, #PB_Font_Bold )
font03= loadfont ( #Font3 , "arial" ,15, #PB_Font_Bold )
font05= loadfont ( #Font5 , "Impact" ,50, #PB_Font_Bold )

;**** Les procédures ****

Procedure Calcul_Resultat()
     Shared gains
    Resultat = random (9)
    
     ; Faire "tourner" le rouleau des chiffres
     ; Tout d'abord 3 fois complet
        speed=32
         For roul=1 To 3
            y=0
             Repeat
                 displaytranslucentsprite (1,5,y+81,255)
                 flipbuffers ()
                 clearscreen ( rgb (255,255,0))
                y=y-speed
             Until y=<-902 ;738
            speed=speed/2
         Next roul
    
         ; puis une seule fois où on s'arrête sur le bon numéro
            y=0
             Repeat
                 displaytranslucentsprite (1,5,y+81,255)
                 flipbuffers ()
                 clearscreen ( rgb (255,255,0))
                y=y-speed
             Until y<=((resultat+1)*82)*-1
    
    
     setgadgettext ( #string_Resultat , " " + str (Resultat))
     If Resultat= 7
         textgadget ( #Titre2 ,60,120,110,70, "Gagné" , #PB_Text_Center )
         setgadgetfont ( #Titre2 ,Font01)
         setgadgetcolor ( #Titre2 , #PB_Gadget_FrontColor , rgb ($FF,$0,$0))
        gains= gains+10
         setgadgettext ( #string_Gains , "" + str (gains))
     Else
         textgadget ( #Titre3 ,60,120,110,70, "Perdu" , #PB_Text_Center )
         setgadgetfont ( #Titre3 ,Font01)
         setgadgetcolor ( #Titre3 , #PB_Gadget_FrontColor , rgb ($FF,$0,$0))
     EndIf
EndProcedure

Procedure rejouer()
     setgadgettext ( #Titre2 , "" )
     setgadgettext ( #Titre3 , "" )
EndProcedure



;***** Création de la fenetre et des gadgets *****
; Initialisations Diverses
      If initsprite () =0 Or initkeyboard ()=0 Or initmouse ()=0 Or initsprite3d ()=0
          messagerequester ( "Error" , "Sprite system can't be initialized" , 0)
          End
      EndIf
     
If openwindow ( #Fenetre_main ,0,0,340,440, " Bandit Manchot " , #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered )
    If openwindowedscreen ( windowid ( #Fenetre_main ),240,60,45,80,0,0,0)
              clearscreen ( rgb (255,255,0))
     EndIf
     frame3dgadget ( #Cadre_0 ,20,10,300,200, "" )
     textgadget ( #Titre ,60,30,110,70, "Bandit Manchot" , #PB_Text_Center )
     setgadgetfont ( #Titre ,Font01)
     setgadgetcolor ( #Titre , #PB_Gadget_FrontColor , rgb ($FF,$0,$0))
     stringgadget ( #string_Resultat ,180,60,45,80, "" , #PB_String_Numeric|#PB_String_ReadOnly )
     ;StringGadget(#string_Resultat,240,60,45,80,"",#PB_String_Numeric|#PB_String_ReadOnly)
     setgadgetfont ( #string_Resultat ,Font02)
     setgadgetcolor ( #string_Resultat , #PB_Gadget_BackColor , rgb ($FF,$FF,$0))
     ;***** Deuxieme cadre ***********
     frame3dgadget ( #cadre_1 ,20,220,300,200, "" )
     textgadget ( #Texte_Gains ,50,250,100,30, "Gains : " , #PB_Text_Center )
     setgadgetfont ( #Texte_Gains ,font03)
     setgadgetcolor ( #Texte_Gains , #PB_Gadget_FrontColor , rgb ($FF,$0,$0))
     stringgadget ( #string_Gains ,180,250,100,20, "0" , #PB_String_Numeric|#PB_String_ReadOnly )
     setgadgetfont ( #string_Gains ,Font04)
     setgadgetcolor ( #string_Gains , #PB_Gadget_BackColor , rgb ($FF,$FF,$0))
     buttongadget ( #Bouton_lancer ,30,310,50,20, "Lancer" )
     buttongadget ( #Bouton_rejouer ,110,310,50,20, "Rejouer" )
   
    ; Création du "rouleau" de chiffres
     createsprite (1,36,821)
          For i=0 To 9
              startdrawing ( spriteoutput (1))
                  drawingmode ( #PB_2DDrawing_Transparent )
                  drawingfont ( fontid ( #font5 ))
                  drawtext (0,(i*82)+1, str (i), rgb (0,1,0), rgb (0,0,0))
              stopdrawing ()
          Next i
EndIf




;***** Boucle du programe ****

Repeat
     Select waitwindowevent ()
         Case #PB_Event_Gadget
             Select eventgadget ()
                 Case #Bouton_lancer
                     textgadget ( #Titre3 ,60,120,110,70, " " , #PB_Text_Center )
                     setgadgetfont ( #Titre3 ,Font01)
                     setgadgetcolor ( #Titre3 , #PB_Gadget_FrontColor , rgb ($FF,$0,$0))
                     setgadgettext ( #string_Resultat , " " )
                    
                    Calcul_Resultat()
                 Case #Bouton_rejouer
                     messagerequester ( "Infos" , "Nouvelle partie" , #PB_MessageRequester_Ok )
                    rejouer()
             EndSelect
         Case #PB_Event_CloseWindow
            Fermer = #True
           
     EndSelect
Until Fermer
End
EDIT : je pense aussi que tu devrais tester l'égalité des 3 chiffres, pour augmenter les gains, du style "3 3 3" rapporte 10 points, et "7 7 7" rapporte 50 points.
Un bon "IF..." devrait faire l'affaire
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

merci je vais le refaire entierement ....
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

Question bête pour les pros des sprites, mais dans le code de JBernard13 que j'ai modifié pour ajouter l'effet "rouleau", à la fin de mon sprite que je déplace verticalement, il y a une zone "blanche" du au fait que j'attends que le sprite soit hors zone visible pour le repositionner en bas, mais comment faire une sorte de défilement continu pour qu'après 9, réapparaisse 0 (zéro) ?

J'ai bien pensé à 2 sprites qui s'afficheraient alternativement, mais ça ma parait un peu lourd, une idée les Grands Maîtres de PB ?
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Message par djes »

Il ne faut pas te bloquer parce que tu utilises deux sprites, y'a pas de honte! Sinon utilise le panel clipsprite/grabsprite, et un modulo (%) pour éviter les conditions et reboucler les valeurs.
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

djes , si tu as un petit exemple ..... merci d'avance

et Grand merci à
TazNormand
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

bonjour

je voudrais savoir comment mettre 3 fois la roulette , faut'il crée 3 OpenWindowedScreen? et comment faire diminuer le score quand on perd?

Code : Tout sélectionner

;***** Bandit manchot *****
;***** écris par Jbernard *****

;**** Constantes *****
Enumeration
  #Fenetre_main
  #Cadre_0
  #cadre_2
  #Cadre_3
  #Titre_1
  #Titre_2
  #Titre_3
  #string_Resultat
  #string_Gains
  #Bouton_jouer
  #Bouton_rejouer
  #Font1
  #Font2
  #Font3
  #Font4
  #Font5
EndEnumeration

;**** Déclarations des variables ****
;*** Pour les polices ***
Global Font01,Font02,font03,Font04,Font05
;*** Pour le calcul du resultat et du gains
Global Resultat,gains
;*** Chargement de la police ****
Font01= LoadFont ( #Font1 , "arial" ,20, #PB_Font_Bold )
Font02= LoadFont ( #Font2 , "arial" ,50, #PB_Font_Bold )
font03= LoadFont ( #Font3 , "arial" ,15, #PB_Font_Bold )
Font05= LoadFont ( #Font5 , "Impact" ,50, #PB_Font_Bold )

;**** Les procédures ****

Procedure Calcul_Resultat()
   SetGadgetText(#Titre_2,"")
  Shared gains
  Resultat = Random (9)
  
  ; Faire "tourner" le rouleau des chiffres
  ; Tout d'abord 3 fois complet
  speed=32
  For roul=1 To 3
    y=0
    Repeat
      DisplayTranslucentSprite (1,5,y+81,255)
      FlipBuffers ()
      ClearScreen ( RGB (255,255,0))
      y=y-speed
    Until y=<-902 ;738
    speed=speed/2
  Next roul
  
  ; puis une seule fois où on s'arrête sur le bon numéro
  y=0
  Repeat
    DisplayTranslucentSprite (1,5,y+81,255)
    FlipBuffers ()
    ClearScreen ( RGB (255,255,0))
    y=y-speed
  Until y<=((Resultat+1)*82)*-1
  
  
  SetGadgetText ( #string_Resultat , " " + Str (Resultat))
  If Resultat= 7
     SetGadgetText(#Titre_2,"GAGNER!")
    
    gains= gains+10
    SetGadgetText ( #string_Gains , "" + Str (gains))
  Else
     SetGadgetText(#Titre_2,"PERDU!")
   
  EndIf
EndProcedure

Procedure rejouer()
  SetGadgetText ( #Titre_2 , "" )
  SetGadgetText ( #string_Gains , "0" )
EndProcedure



;***** Création de la fenetre et des gadgets *****
; Initialisations Diverses
If InitSprite () =0 Or InitKeyboard ()=0 Or InitMouse ()=0 Or InitSprite3D ()=0
  MessageRequester ( "Error" , "Sprite system can't be initialized" , 0)
  End
EndIf
     
If OpenWindow ( #Fenetre_main ,0,0,320,400, " Bandit Manchot " , #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered )
  If OpenWindowedScreen ( WindowID ( #Fenetre_main ),130,80,45,80,0,0,0)
    ClearScreen ( RGB (255,255,0))
  EndIf
  SetWindowColor(#Fenetre_main,RGB($0,$80,$FF))
  Frame3DGadget(#Cadre_0,10,10,300,50,"")
  TextGadget(#Titre_1,35,20,250,30,"Bandit Manchot",#PB_Text_Center)
  SetGadgetFont(#Titre_1,Font01)
  SetGadgetColor(#Titre_1, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_1, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  Frame3DGadget(#cadre_2,10,170,300,50,"")
  TextGadget(#Titre_2,35,180,250,30,"",#PB_Text_Center)
  SetGadgetFont(#Titre_2,Font01)
  SetGadgetColor(#Titre_2, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_2, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  ;***********************************************************
  Frame3DGadget(#Cadre_3,10,260,300,120,"")
  TextGadget(#Titre_3,20,290,120,30,"Gains :",#PB_Text_Center)
  SetGadgetFont(#Titre_3,font03)
  SetGadgetColor(#Titre_3, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_3, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  StringGadget(#string_Gains,150,290,80,30,"0",#PB_String_Numeric|#PB_String_ReadOnly)
  SetGadgetFont(#string_Gains,font03)
  SetGadgetColor(#string_Gains, #PB_Gadget_BackColor,RGB($FF,$FF,$0))
  ButtonGadget(#Bouton_jouer,60,350,60,20,"JOUER")
  PureCOLOR_SetButtonColor(#Bouton_jouer,RGB($FF,$FF,$0),RGB(0,0,0)) 
  ButtonGadget(#Bouton_rejouer,200,350,60,20,"REJOUER")
  PureCOLOR_SetButtonColor(#Bouton_rejouer,RGB($FF,$FF,$0),RGB(0,0,0))
 
  ; Création du "rouleau" de chiffres
  CreateSprite (1,36,821)
  For i=0 To 9
   StartDrawing ( SpriteOutput (1))
      DrawingMode ( #PB_2DDrawing_Transparent )
      DrawingFont ( FontID ( #Font5 ))
      DrawText (0,(i*82)+1, Str (i), RGB (0,1,0), RGB (0,0,0))
    StopDrawing ()
  Next i
EndIf




;***** Boucle du programe ****

Repeat
  Select WaitWindowEvent ()
    Case #PB_Event_Gadget
      Select EventGadget ()
        Case #Bouton_jouer
           
          
          Calcul_Resultat()
        Case #Bouton_rejouer
          MessageRequester ( "Infos" , "Nouvelle partie" , #PB_MessageRequester_Ok )
          rejouer()
      EndSelect
    Case #PB_Event_CloseWindow
      Fermer = #True
      
  EndSelect
Until Fermer
End 
Dernière modification par jbernard13 le jeu. 14/mai/2009 9:32, modifié 1 fois.
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

jbernard13 a écrit :bonjour

je voudrais savoir comment mettre 3 fois la roulette , faut'il crée 3 OpenWindowedScreen?
Salut,

Popurquoi ouvrir 3 écrans (je ne sais pas si c'est possible d'ailleurs), il te suffit d'agrandir celui existant, et de positionner 3 displaysprite.

comme l'a souligné plus haut Djes, utilise un clipsprite. pour l'effet de défilement, tu choisis de boucler sur les coordonnées "Y" du clipsprite.

je vais voir pour mettre un exemple. Laisses moi un peu de temps.

Si jamais un pro vient a passer, quelques conseils sont les bienvenus
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

je voudrais c'est avoir 3 rectangles avec 3 roulette mais separer
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

Bon, la doc dit un seul "windowedscreen" possible.

J'ai bien compris ta demande, je suis en train de regarder ça (tout en répondant au tél aux utilisateurs que je suis censé dépanner, c'est mon patron qui va être content :wink: )
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

je voudrais savoir comment je peux faire une soustraction de score car à chaque fois dans lestringadget s'ecris - 10( par exemple) et apres -0
comment faire pour que le score se soustrait ..

merci encore
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

Peux-tu être plus clair ?

Si tu ne veux pas de -10 (en général, les machines à sous ne te réclament pas de l'argent quand tu as perdu :wink: ), fais un test avec un IF.

Si c'est négatif (<0), alors ça vaut 0 (zéro).

C'est ça que tu cherches ?

Bon, pour l'instant voici un 1er jet pour les 3 rouleaux ; mais il faudrait l'améliorer, dans ce source, les 3 rouleaux tournent à la même vitesse, et s'arrêtent en même temps, alors qu'en réalité, le 1er est censé s'arrêter, puis le 2nd, et enfin le 3eme. Je peaufine, et déposerai un nouveau source plus tard.

Au fait, JBernanrd, tu devrais utiliser COLORER de Dobro pour poster tes sources, c'est plus lisible.

Sources à 3 rouleaux, version simpliste :

;***** Bandit manchot *****
;***** écris par Jbernard *****

;**** Constantes *****
Enumeration
   #Fenetre_main
   #Cadre_0
   #cadre_2
   #Cadre_3
   #Titre_1
   #Titre_2
   #Titre_3
   #string_Resultat
   #string_Gains
   #Bouton_jouer
   #Bouton_rejouer
   #Font1
   #Font2
   #Font3
   #Font4
   #Font5
EndEnumeration

;**** Déclarations des variables ****
;*** Pour les polices ***
Global Font01,Font02,font03,Font04,Font05
;*** Pour le calcul du resultat et du gains
Global Resultat,gains
;*** Chargement de la police ****
Font01= loadfont ( #Font1 , "arial" ,20, #PB_Font_Bold )
Font02= loadfont ( #Font2 , "arial" ,50, #PB_Font_Bold )
font03= loadfont ( #Font3 , "arial" ,15, #PB_Font_Bold )
Font05= loadfont ( #Font5 , "Impact" ,50, #PB_Font_Bold )

;**** Les procédures ****

Procedure Calcul_Resultat()
    setgadgettext ( #Titre_2 , "" )
   Shared gains
  Resultat = random (9)
 
   ; Faire "tourner" le rouleau des chiffres
   ; Tout d'abord 3 fois complet
  speed=32
   For roul=1 To 3
    y=0
     Repeat
         displaytranslucentsprite (1,5,y+81,255)
         displaytranslucentsprite (1,135,y+81,255)
         displaytranslucentsprite (1,260,y+81,255)
         flipbuffers ()
         clearscreen ( rgb (255,255,0))
        y=y-speed
     Until y=<-902
    speed=speed/2
   Next roul
 
   ; puis une seule fois où on s'arrête sur le bon numéro
  y=0
   Repeat
     displaytranslucentsprite (1,5,y+81,255)
     displaytranslucentsprite (1,135,y+81,255)
     displaytranslucentsprite (1,260,y+81,255)
     flipbuffers ()
     clearscreen ( rgb (255,255,0))
    y=y-speed
   Until y<=((Resultat+1)*82)*-1
 
 
   setgadgettext ( #string_Resultat , " " + str (Resultat))
   If Resultat= 7
      setgadgettext ( #Titre_2 , "GAGNER!" )
   
    gains= gains+10
     setgadgettext ( #string_Gains , "" + str (gains))
   Else
      setgadgettext ( #Titre_2 , "PERDU!" )
   
   EndIf
EndProcedure

Procedure rejouer()
   setgadgettext ( #Titre_2 , "" )
   setgadgettext ( #string_Gains , "0" )
EndProcedure



;***** Création de la fenetre et des gadgets *****
; Initialisations Diverses
If initsprite () =0 Or initkeyboard ()=0 Or initmouse ()=0 Or initsprite3d ()=0
   messagerequester ( "Error" , "Sprite system can't be initialized" , 0)
   End
EndIf
     
If openwindow ( #Fenetre_main ,0,0,320,400, " Bandit Manchot " , #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered )

   ; **************************************************************************************************************
   ; On définit un "WindowedScreen" plus large
     If openwindowedscreen ( windowid ( #Fenetre_main ),10,80,300,80,0,0,0)
         clearscreen ( rgb (255,255,0))
     EndIf
   ; **************************************************************************************************************
  
   setwindowcolor ( #Fenetre_main , rgb ($0,$80,$FF))
   frame3dgadget ( #Cadre_0 ,10,10,300,50, "" )
   textgadget ( #Titre_1 ,35,20,250,30, "Bandit Manchot" , #PB_Text_Center )
   setgadgetfont ( #Titre_1 ,Font01)
   setgadgetcolor ( #Titre_1 , #PB_Gadget_FrontColor , rgb ($FF,$80,$C0))
   setgadgetcolor ( #Titre_1 , #PB_Gadget_BackColor , rgb ($0,$80,$FF))
   frame3dgadget ( #cadre_2 ,10,170,300,50, "" )
   textgadget ( #Titre_2 ,35,180,250,30, "" , #PB_Text_Center )
   setgadgetfont ( #Titre_2 ,Font01)
   setgadgetcolor ( #Titre_2 , #PB_Gadget_FrontColor , rgb ($FF,$80,$C0))
   setgadgetcolor ( #Titre_2 , #PB_Gadget_BackColor , rgb ($0,$80,$FF))
   ;***********************************************************
   frame3dgadget ( #Cadre_3 ,10,260,300,120, "" )
   textgadget ( #Titre_3 ,20,290,120,30, "Gains :" , #PB_Text_Center )
   setgadgetfont ( #Titre_3 ,font03)
   setgadgetcolor ( #Titre_3 , #PB_Gadget_FrontColor , rgb ($FF,$80,$C0))
   setgadgetcolor ( #Titre_3 , #PB_Gadget_BackColor , rgb ($0,$80,$FF))
   stringgadget ( #string_Gains ,150,290,80,30, "0" , #PB_String_Numeric|#PB_String_ReadOnly )
   setgadgetfont ( #string_Gains ,font03)
   setgadgetcolor ( #string_Gains , #PB_Gadget_BackColor , rgb ($FF,$FF,$0))
   buttongadget ( #Bouton_jouer ,60,350,60,20, "JOUER" )
   ;PureCOLOR_SetButtonColor(#Bouton_jouer,RGB($FF,$FF,$0),RGB(0,0,0))
   buttongadget ( #Bouton_rejouer ,200,350,60,20, "REJOUER" )
   ;PureCOLOR_SetButtonColor(#Bouton_rejouer,RGB($FF,$FF,$0),RGB(0,0,0))
 
   ; Création du "rouleau" de chiffres
   createsprite (1,36,821)
   For i=0 To 9
    startdrawing ( spriteoutput (1))
       drawingmode ( #PB_2DDrawing_Transparent )
       drawingfont ( fontid ( #Font5 ))
       drawtext (0,(i*82)+1, str (i), rgb (0,1,0), rgb (0,0,0))
     stopdrawing ()
   Next i
EndIf

;***** Boucle du programe ****

Repeat
   Select waitwindowevent ()
     Case #PB_Event_Gadget
       Select eventgadget ()
         Case #Bouton_jouer
           
         
          Calcul_Resultat()
         Case #Bouton_rejouer
           messagerequester ( "Infos" , "Nouvelle partie" , #PB_MessageRequester_Ok )
          rejouer()
       EndSelect
     Case #PB_Event_CloseWindow
      Fermer = #True
     
   EndSelect
Until Fermer
End
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

Merci TazNormand ce que je cherche à faire c'est de soustraire le score en mettant un moins 10 mais si j'ecris Gains = Gains -10 ça marche pas car apres dans mon stringadgets s'écris -10 et je veux pas que le signe - apparait .
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

peux-tu remettre ton code source ici ?

Et pour faire court, appelles moi Taz, pas TazNormand :wink:
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

Code : Tout sélectionner

;***** Bandit manchot *****
;***** écris par Jbernard *****

;**** Constantes *****
Enumeration
  #Fenetre_main
  #Cadre_0
  #cadre_2
  #Cadre_3
  #Titre_1
  #Titre_2
  #Titre_3
  #string_Resultat
  #string_Gains
  #Bouton_jouer
  #Bouton_rejouer
  #Font1
  #Font2
  #Font3
  #Font4
  #Font5
EndEnumeration

;**** Déclarations des variables ****
;*** Pour les polices ***
Global Font01,Font02,font03,Font04,Font05
;*** Pour le calcul du resultat et du gains
Global Resultat,gains
;*** Chargement de la police ****
Font01= LoadFont ( #Font1 , "arial" ,20, #PB_Font_Bold )
Font02= LoadFont ( #Font2 , "arial" ,50, #PB_Font_Bold )
font03= LoadFont ( #Font3 , "arial" ,15, #PB_Font_Bold )
Font05= LoadFont ( #Font5 , "Impact" ,50, #PB_Font_Bold )

;**** Les procédures ****

Procedure Calcul_Resultat()
   SetGadgetText(#Titre_2,"")
  Shared gains
  Resultat = Random (9)
  
  ; Faire "tourner" le rouleau des chiffres
  ; Tout d'abord 3 fois complet
  speed=32
  For roul=1 To 3
    y=0
    Repeat
      DisplayTranslucentSprite (1,5,y+81,255)
      FlipBuffers ()
      ClearScreen ( RGB (255,255,0))
      y=y-speed
    Until y=<-902 ;738
    speed=speed/2
  Next roul
  
  ; puis une seule fois où on s'arrête sur le bon numéro
  y=0
  Repeat
    DisplayTranslucentSprite (1,5,y+81,255)
    FlipBuffers ()
    ClearScreen ( RGB (255,255,0))
    y=y-speed
  Until y<=((Resultat+1)*82)*-1
  
  
  SetGadgetText ( #string_Resultat , " " + Str (Resultat))
  If Resultat= 7
     SetGadgetText(#Titre_2,"GAGNER!")
    
    gains= gains+10
    SetGadgetText ( #string_Gains , "" + Str (gains))
  Else
    gains = gains -10
    SetGadgetText(#Titre_2,"PERDU!")
  EndIf

EndProcedure

Procedure rejouer()
  SetGadgetText ( #Titre_2 , "" )
  SetGadgetText ( #string_Gains , "0" )
EndProcedure



;***** Création de la fenetre et des gadgets *****
; Initialisations Diverses
If InitSprite () =0 Or InitKeyboard ()=0 Or InitMouse ()=0 Or InitSprite3D ()=0
  MessageRequester ( "Error" , "Sprite system can't be initialized" , 0)
  End
EndIf
     
If OpenWindow ( #Fenetre_main ,0,0,320,400, " Bandit Manchot " , #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered )
  If OpenWindowedScreen ( WindowID ( #Fenetre_main ),130,80,45,80,0,0,0)
    ClearScreen ( RGB (255,255,0))
  EndIf
  SetWindowColor(#Fenetre_main,RGB($0,$80,$FF))
  Frame3DGadget(#Cadre_0,10,10,300,50,"")
  TextGadget(#Titre_1,35,20,250,30,"Bandit Manchot",#PB_Text_Center)
  SetGadgetFont(#Titre_1,Font01)
  SetGadgetColor(#Titre_1, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_1, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  Frame3DGadget(#cadre_2,10,170,300,50,"")
  TextGadget(#Titre_2,35,180,250,30,"",#PB_Text_Center)
  SetGadgetFont(#Titre_2,Font01)
  SetGadgetColor(#Titre_2, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_2, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  ;***********************************************************
  Frame3DGadget(#Cadre_3,10,260,300,120,"")
  TextGadget(#Titre_3,20,290,120,30,"Gains :",#PB_Text_Center)
  SetGadgetFont(#Titre_3,font03)
  SetGadgetColor(#Titre_3, #PB_Gadget_FrontColor,RGB($FF,$80,$C0))
  SetGadgetColor(#Titre_3, #PB_Gadget_BackColor,RGB($0,$80,$FF))
  StringGadget(#string_Gains,150,290,80,30,"0",#PB_String_Numeric|#PB_String_ReadOnly)
  SetGadgetFont(#string_Gains,font03)
  SetGadgetColor(#string_Gains, #PB_Gadget_BackColor,RGB($FF,$FF,$0))
  ButtonGadget(#Bouton_jouer,60,350,60,20,"JOUER")
  PureCOLOR_SetButtonColor(#Bouton_jouer,RGB($FF,$FF,$0),RGB(0,0,0)) 
  ButtonGadget(#Bouton_rejouer,200,350,60,20,"REJOUER")
  PureCOLOR_SetButtonColor(#Bouton_rejouer,RGB($FF,$FF,$0),RGB(0,0,0))
 
  ; Création du "rouleau" de chiffres
  CreateSprite (1,36,821)
  For i=0 To 9
   StartDrawing ( SpriteOutput (1))
      DrawingMode ( #PB_2DDrawing_Transparent )
      DrawingFont ( FontID ( #Font5 ))
      DrawText (0,(i*82)+1, Str (i), RGB (0,1,0), RGB (0,0,0))
    StopDrawing ()
  Next i
EndIf




;***** Boucle du programe ****

Repeat
  Select WaitWindowEvent ()
    Case #PB_Event_Gadget
      Select EventGadget ()
        Case #Bouton_jouer
           
          
          Calcul_Resultat()
        Case #Bouton_rejouer
          MessageRequester ( "Infos" , "Nouvelle partie" , #PB_MessageRequester_Ok )
          rejouer()
      EndSelect
    Case #PB_Event_CloseWindow
      Fermer = #True
      
  EndSelect
Until Fermer
End 
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Message par TazNormand »

Pour les gains, fais comme je t'ai dit : testes si cela devient négatif.

toi tu mets ça :

Code : Tout sélectionner

  SetGadgetText ( #string_Resultat , " " + Str (Resultat))
  If Resultat= 7
     SetGadgetText(#Titre_2,"GAGNER!")
   
    gains= gains+10
    SetGadgetText ( #string_Gains , "" + Str (gains))
  Else
    gains = gains -10
    SetGadgetText(#Titre_2,"PERDU!")
  EndIf

Alors qu'il faut mettre :

   setgadgettext ( #string_Resultat , " " + str (Resultat))
   If Resultat= 7
      setgadgettext ( #Titre_2 , "GAGNER!" )
   
    gains= gains+10
     setgadgettext ( #string_Gains , "" + str (gains))
   Else
    gains = gains -10
    
     ; TESTER SI Négatif, SI OUI, ALORS METTRE 0/zéro
     If gains<0
        gains=0
     EndIf
     setgadgettext ( #Titre_2 , "PERDU!" )
   EndIf
Répondre