Publié : dim. 22/janv./2006 15:38
Il faut que tu mette un ExamineKeyboard () dans ta deuxième boucle, sinon le programme ne détectera jamais l'appui de la touche échap
Forums PureBasic - Français
http://forums.purebasic.com/french/
Code : Tout sélectionner
InitSprite ()
InitKeyboard ()
OpenScreen (800,600,32, "QuiZZZzzz" )
Global Points.l , KeyFlag.b
Structure Questions
Text.s
Reponse.s[7]
ReponseValide.l
EndStructure : Dim Question.Questions(5)
Declare Init_question()
Declare AfficheQuestion()
Init_question()
Repeat
ClearScreen(0,0,0)
ExamineKeyboard()
AfficheQuestion()
FlipBuffers()
Until KeyboardPushed ( #PB_Key_Escape )
CloseScreen()
End
Procedure AfficheQuestion()
Shared Index.l,Debriefing.b
If Index=0 : Index=1 : EndIf
If Index=6 : Index=5 : Debriefing=1 : EndIf
If Debriefing=1
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
FrontColor(255,255,255)
DrawingMode(1)
Locate(10,10)
DrawText("Vous avez eu "+Str(Points*4)+" points sur 20")
StopDrawing ()
EndIf
If Debriefing<>1
StartDrawing(ScreenOutput())
FrontColor(255,255,255)
DrawingMode(1)
Locate(10,10)
DrawText(Question(Index)\Text)
For i = 1 To 5
Locate(50,50+i*20)
DrawText(Str(i)+"---> "+Question(Index)\Reponse[i])
Next
StopDrawing ()
;******************************************************************************
If KeyboardPushed(#PB_Key_1) And Question(Index)\ReponseValide=1 And KeyFlag=0
KeyFlag=1
Index+1
Points+1
If Index=>5 : Goto Debrief : EndIf
EndIf
If KeyboardPushed(#PB_Key_1) And Question(Index)\ReponseValide<>1 And KeyFlag=0
KeyFlag=1
Index+1
If Index=>5 : Goto Debrief : EndIf
EndIf
;******************************************************************************
If KeyboardPushed(#PB_Key_2) And Question(Index)\ReponseValide=2 And KeyFlag=0
KeyFlag=1
Index+1
Points+1
If Index=>5 : Goto Debrief : EndIf
EndIf
If KeyboardPushed(#PB_Key_2) And Question(Index)\ReponseValide<>2 And KeyFlag=0
KeyFlag=1
Index+1
If Index=>5 : Goto Debrief : EndIf
EndIf
;******************************************************************************
If KeyboardPushed(#PB_Key_3) And Question(Index)\ReponseValide=3 And KeyFlag=0
KeyFlag=1
Index+1
Points+1
If Index=>5 : Goto Debrief : EndIf
EndIf
If KeyboardPushed(#PB_Key_3) And Question(Index)\ReponseValide<>3 And KeyFlag=0
KeyFlag=1
Index+1
If Index=>5 : Goto Debrief : EndIf
EndIf
;******************************************************************************
If KeyboardPushed(#PB_Key_4) And Question(Index)\ReponseValide=4 And KeyFlag=0
KeyFlag=1
Index+1
Points+1
If Index=>5 : Goto Debrief : EndIf
EndIf
If KeyboardPushed(#PB_Key_4) And Question(Index)\ReponseValide<>4 And KeyFlag=0
KeyFlag=1
Index+1
If Index=>5 : Goto Debrief : EndIf
EndIf
;******************************************************************************
If KeyboardPushed(#PB_Key_5) And Question(Index)\ReponseValide=5 And KeyFlag=0
KeyFlag=1
Index+1
Points+1
If Index=>5 : Goto Debrief : EndIf
EndIf
If KeyboardPushed(#PB_Key_5) And Question(Index)\ReponseValide<>5 And KeyFlag=0
KeyFlag=1
Index+1
If Index=>5 : Goto Debrief : EndIf
EndIf
;******************************************************************************
EndIf
Debrief:
If KeyboardPushed(#PB_Key_All) = 0 : KeyFlag=0 : EndIf
EndProcedure
Procedure Init_question()
;************************************************
Question(1)\Text = "(1+1)*5?"
Question(1)\Reponse[1] = "7"
Question(1)\Reponse[2] = "-3"
Question(1)\Reponse[3] = "10"
Question(1)\Reponse[4] = "15"
Question(1)\Reponse[5] = "0"
Question(1)\ReponseValide = 3
;************************************************
Question(2)\Text = "((256*2)/2)*2?"
Question(2)\Reponse[1] = "512"
Question(2)\Reponse[2] = "1024"
Question(2)\Reponse[3] = "64"
Question(2)\Reponse[4] = "768"
Question(2)\Reponse[5] = "-256"
Question(2)\ReponseValide = 1
;************************************************
Question(3)\Text = "Hausse de combat du FAMAS?"
Question(3)\Reponse[1] = "100"
Question(3)\Reponse[2] = "200"
Question(3)\Reponse[3] = "300"
Question(3)\Reponse[4] = "400"
Question(3)\Reponse[5] = "500"
Question(3)\ReponseValide = 3
;************************************************
Question(4)\Text = "Sur une carte au 1/50000° , 1cm = ?"
Question(4)\Reponse[1] = "1Km"
Question(4)\Reponse[2] = "50m"
Question(4)\Reponse[3] = "500m"
Question(4)\Reponse[4] = "50km"
Question(4)\Reponse[5] = "5m"
Question(4)\ReponseValide = 3
;************************************************
Question(5)\Text = "3200 millièmes est égal à :"
Question(5)\Reponse[1] = "180 degrés"
Question(5)\Reponse[2] = "45 degrés"
Question(5)\Reponse[3] = "90 degrés"
Question(5)\Reponse[4] = "360 degrés"
Question(5)\Reponse[5] = "10 degrés"
Question(5)\ReponseValide = 1
;************************************************
EndProcedure
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenScreen(800,600,32, "QuiZZZzzz")
Global reponse$, NoQuestion, QuestionMax
Global MemReponse
NoQuestion = 1
QuestionMax = 3
MemReponse = 0
Dim Question.s(QuestionMax,4)
Dim BonneReponse(QuestionMax)
Question(1,0)="1) Quel est le nom correct : "
Question(1,1)="a) PureBasique"
Question(1,2)="b) PoureBasic"
Question(1,3)="c) PureBasic"
Question(1,4)="d) PoureBasique"
BonneReponse(1)=3
Question(2,0)="2) Qui est le createur de ce quiz: "
Question(2,1)="a) moMo"
Question(2,2)="b) DOBRO"
Question(2,3)="c) toTo"
Question(2,4)="d) wolfjeremy"
BonneReponse(2)=4
Question(3,0)="3) On dit merci Qui ? : "
Question(3,1)="a) Geraldine"
Question(3,2)="b) Albert"
Question(3,3)="c) Comtois"
Question(3,4)="d) wolfjeremy"
BonneReponse(3)=3
Procedure AfficheQuestion(No)
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor(89,200,89)
Locate (10,10)
DrawText ("Bienvenue dans mon premier programme.")
Locate (10,30)
DrawText ("Createur : wolfjeremy")
FrontColor (255, 57, 44)
Locate (10,80)
DrawText (Question(No,0))
FrontColor (242, 193, 50)
For i = 1 To 4
Locate (10,80 + i * 20)
DrawText (Question(No,i))
Next i
Locate (10,180)
DrawText ("Votre reponse: ")
StopDrawing ()
EndProcedure
Procedure AttenteReponse(No)
If ExamineKeyboard()
reponse$=KeyboardInkey()
reponse=Asc(LCase(reponse$))-96
If reponse >0 And reponse<5 And MemReponse=0
MemReponse = Reponse
EndIf
EndIf
EndProcedure
Procedure WaitKey()
ProcedureReturn KeyboardPushed(#PB_Key_Space)
EndProcedure
Procedure AfficheReponseJoueur(No)
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor (255, 57, 44)
Locate(110,180)
DrawText(Question(No,MemReponse))
;C'est la bonne réponse ?
Locate(10,200)
If MemReponse = BonneReponse(No)
DrawText("Bonne reponse !")
Else
DrawText("La bonne reponse est : " + Question(No,BonneReponse(No)))
EndIf
DrawingMode (0)
Locate(10,400)
FrontColor(255,255,0)
BackColor(0,0,255)
DrawText("Appuyez la barre espace pour passer a la question suivante")
;Passe à la question suivante
If WaitKey()
If NoQuestion < QuestionMax
NoQuestion + 1
MemReponse = 0
EndIf
EndIf
StopDrawing ()
EndProcedure
Repeat
ClearScreen(0,0,0)
ExamineKeyboard()
AfficheQuestion(NoQuestion)
AttenteReponse(NoQuestion)
If MemReponse
AfficheReponseJoueur(NoQuestion)
EndIf
FlipBuffers()
Until KeyboardPushed ( #PB_Key_Escape )
Taratata , j'ai utilisé les mêmes commandes que dans ton code , rien de nouveau sauf le tableauwolfjeremy a écrit :Les gars la le code est déjà asser complex pour moi lol
Code : Tout sélectionner
Pourquoi, lourd?CameleonTH a écrit :Euh Chris tu est un peu lourd la