Jeu pour les petits heu ! ou pour les grands (pack)
Publié : ven. 17/avr./2020 9:10
Bonjour a tous
C'est la première fois que je programme un jeu. Je n'est pas utilisé des trucs compliqués avec collisions ou autres sprites en ballades.
Donc soyer critiques, mais indulgent.
Je donne le code complet avec image et son sous forme de data, c'est un peu lourding, mais cela vous permettras de faire toutes les modif de votre choix.
suite dans les postes suivants car les postes sont limité 60000caractères
C'est la première fois que je programme un jeu. Je n'est pas utilisé des trucs compliqués avec collisions ou autres sprites en ballades.
Donc soyer critiques, mais indulgent.
Je donne le code complet avec image et son sous forme de data, c'est un peu lourding, mais cela vous permettras de faire toutes les modif de votre choix.
Code : Tout sélectionner
;¤¤¤¤¤¤¤ jeux Ciseaux,Pierre,feuille ¤¤¤¤¤
;MLD le 16/04/2020 ¤¤¤¤¤
;compilation BP 5.72 X86 Droits libres ¤¤¤¤¤
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
UsePNGImageDecoder()
InitSound() ; initialisation du son
#Fp = 1
#canvas1 = 2:#txtbtrj = 3:#txtbtscor = 4:#txtbtnp = 5:#txtbtstop = 6
#txtcis = 10:#txtpier = 11:#txtfeuil = 12:
#Imagegad1 = 19:#Imagegad2 = 20:#Imagegad3 = 21:#Imagegad4 = 22:#Imagegad5 = 23:#Imagegad6 = 24:
#txtexpliq1 = 35:#txtexpliq2 = 36:#txtordi1 = 37:#txtordi2 = 38:#txtj1 = 39:#txtj2 = 40
#txtm = 41:#txtnm = 42:#txtmo = 43:#txtgmo = 44:#txtgmj = 45:#txtmj = 46:#txtpo = 47:#txtnpo = 48:#txtnpj = 49:#txtpj = 50:#txtdcpt = 51
#lgh1 = 55:#lgv1 = 56
;¤¤¤¤ fenêtre nouvelle partie ou scor ¤¤¤¤¤¤¤¤¤¤¤¤¤¤
#Fnpcr = 70:#txttitre = 71:#txtnom = 72:#txtdif = 73:#strnom = 74:#cochfac = 75:#cochfmoy = 76:#cochdiff = 77:#cochson = 78:#listscor = 79
#bntok = 83:#bntraz = 84:#bntstop = 85
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
#tim1 = 100:#Son = 150:#Fscor = 151
#Image1 = 200:#Image2 = 201:#Image3 = 202:#Image4 = 203:#Image5 = 204:#Image6 = 205:#Image7 = 206
Declare Epsikal()
Declare tdv(ch)
Declare aff(n)
Global a,dc,dpj,dpsn,dpdif,dppart,chor,reso,resj,mch,mchgo,mchgj,cc,cp,cf
Global nj$
Global Dim L.s(11)
CatchImage(#Image1,?tj_png_start);image_titre
CatchImage(#Image2,?ciseauxD_png_start)
CatchImage(#Image3,?pierreD_png_start)
CatchImage(#Image4,?FeuilleD_png_start)
CatchImage(#Image5,?ciseauxG_png_start)
CatchImage(#Image6,?pierreG_png_start)
CatchImage(#Image7,?FeuilleG_png_start)
Global FontID1 = LoadFont(300,"Comic sans MS",16)
Global FontID2 = LoadFont(301,"Arial",10,#PB_Font_Italic)
Global FontID3 = LoadFont(302,"Comic sans MS",20,#PB_Font_Italic)
Global FontID4 = LoadFont(303,"Comic sans MS",16,#PB_Font_Italic)
Global FontID5 = LoadFont(304,"Arial",60)
Global FontID6 = LoadFont(305,"Comic sans MS",14)
Macro inf1(n1,n2)
Select n1
Case 1
SetGadgetText(35,"La pierre brise les ciseaux")
Case 2
SetGadgetText(35,"Les ciseaux coupent la feuille")
Case 3
SetGadgetText(35,"La feuille recouvre la pierre")
Case 4
SetGadgetText(35,"Une nouvelle partie contre Epsikal ?")
EndSelect
Select n2
Case 1
SetGadgetText(36,"Epsikal gagne")
Case 2
SetGadgetText(36,nj$ + " gagne")
Case 3
SetGadgetText(36,"Humm ! !")
EndSelect
EndMacro
Macro Fcoul(g,coul)
SetGadgetColor(g,#PB_Gadget_FrontColor,coul)
EndMacro
Macro Bcoul(g,coul)
SetGadgetColor(g,#PB_Gadget_BackColor,coul)
EndMacro
;¤¤¤¤ Regle du jeu ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
L.s(1) = "Jeu Ciseaux Pierre Feuille" +#CRLF$ +#CRLF$
L.s(2) = "Vous jouez contre le calculateur EpsiKal."+#CRLF$
L.s(3) = "Vous devez chosir les ciseaux,la pierre ou la feuille par un clic de souris sur l'image symbole de la main d'un joueur."+#CRLF$
L.s(4) = "La règle du jeu est simple:"+#CRLF$
L.s(5) = "Les ciseaux perdent contre la pierre, et gagnent contre la feuille."+#CRLF$
L.s(6) = "La pierre perd contre la feuille, et gagne contre les ciseaux."+#CRLF$
L.s(7) = "La feuille perd contre les ciseaux, et gagne contre la pierre."+#CRLF$
L.s(8) = "Si vous ne jouez pas assez vite ou pas du tout EpsiKal gagne le point."+#CRLF$
L.s(9) = "Une partie comprend trois manches de douze points."+#CRLF$
L.s(10) = "Il y a trois niveaux de difficuté de jeu."+#CRLF$
L.s(11) = "Bon jeu Merci (MLD)."+#CRLF$
For X = 1 To 11
LT$ = LT$ + L.s(X)
Next
FreeArray(L.s())
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Procedure Forme(win)
Region = CreatePolygonRgn_(?Triangle, 4, #WINDING)
SetWindowRgn_(WindowID(win), Region, #True) ; On applique la région
DeleteObject_(Region) ;supprime la région
DataSection
Triangle:
Data.l 400, 800, 0, 0, 800, 0, 400, 800;Coordonnées des points du triangle en x, y
EndDataSection
EndProcedure
Procedure Titre()
CanvasGadget(2,0,0,800,60, #PB_Canvas_Container)
StartDrawing(CanvasOutput(2))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($CB9B79):BackColor($6F5C4F)
LinearGradient(0,GadgetHeight(2),0,0)
Box(0,0,800,60,$CB9B79)
StopDrawing()
CloseGadgetList()
ImageGadget(19,140,5,100,30,ImageID(200))
EndProcedure
Procedure WindowProc(hWnd, msg, wParam, lParam)
If msg=#WM_CTLCOLORSTATIC
Select GetDlgCtrlID_(lParam)
Case 75 To 78
GadgetBkg = CreateSolidBrush_($4D9439)
ProcedureReturn GadgetBkg : DeleteObject_(GadgetBkg)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure npcr(typ)
StickyWindow(1,0)
OpenWindow(70,WindowX(1)+ ((WindowWidth(1)- 500)/2),WindowY(1)+ ((WindowHeight(1)- 590)/2),500,180,"",#PB_Window_BorderLess|#NUL)
SetWindowColor(70,$4D9439)
SetWindowLongPtr_(WindowID(70),#GWL_HWNDPARENT,FindWindow_(0,"program manager"))
SetWindowLongPtr_(WindowID(70), #GWL_STYLE, GetWindowLongPtr_(WindowID(70), #GWL_STYLE) | #WS_DLGFRAME)
SetWindowPos_(WindowID(70), 0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_NOZORDER|#SWP_FRAMECHANGED)
SetWindowCallback(@WindowProc())
StickyWindow(70,1)
TextGadget(71,10,10,470,40, "",#PB_Text_Center)
SetGadgetFont(71,FontID3)
Bcoul(71,$4D9439):Fcoul(71,$FFFFFF)
ButtonGadget(85,410,145,80,25,"Stop")
If typ = 1
SetGadgetText(40,"")
SetGadgetText(71,"Nouvelle partie")
TextGadget(72,60,60,80,30, "Joueur")
SetGadgetFont(72,FontID4)
TextGadget(73,10,105,90,30, "Difficulté:",#PB_Text_Center)
SetGadgetFont(73,FontID6)
StringGadget(74,160,60,180,30,nj$)
SetGadgetFont(74,FontID4)
SetGadgetAttribute(74,#PB_String_MaximumLength,9)
For z = 72 To 74
Bcoul(z,$4D9439):Fcoul(z,$FFFFFF)
Next
CheckBoxGadget(75,105,105,80,30,"Facile")
SetGadgetState(75,#PB_Checkbox_Checked)
CheckBoxGadget(76,205,105,100,30,"Moyenne")
CheckBoxGadget(77,325,105,100,30,"Difficile")
CheckBoxGadget(78,10,140,100,30,"Son")
SetGadgetState(78,#PB_Checkbox_Checked)
dpsn = 1;drapeau son
dpdif = 1
For z = 75 To 78
SetGadgetFont(z,FontID6)
Next
AddWindowTimer(1,100,750)
ButtonGadget(83,329,145,80,25,"Jeu !")
SetActiveGadget(74)
Else
SetGadgetText(71,"Scores")
ListViewGadget(79,20,50,300,120)
SetGadgetColor(79,#PB_Gadget_BackColor,$69416A):Fcoul(79,$00FF7F)
OpenFile(151,"scorCPF")
While Eof(151) = 0
AddGadgetItem(79,-1,ReadString(151))
Wend
CloseFile(151)
ButtonGadget(84,329,145,80,25,"RAZ")
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 75
If GetGadgetState(75) = 1
dpdif = 1:SetGadgetState(76,0): SetGadgetState(77,0)
EndIf
Case 76
If GetGadgetState(76)
dpdif = 2:SetGadgetState(75,0): SetGadgetState(77,0)
EndIf
Case 77
If GetGadgetState(77) = 1
RemoveWindowTimer(1,100): AddWindowTimer(1,100,330)
dpdif = 3:SetGadgetState(75,0): SetGadgetState(76,0)
EndIf
Case 78
If GetGadgetState(78) = 0
dpsn = 0
Else
dpsn = 1
EndIf
Case 83
If GetGadgetText(74)<> ""
nj$ = GetGadgetText(74)
Else
nj$ = "XXX"
EndIf
SetGadgetText(40,nj$)
SetGadgetState(23,0):SetGadgetState(24,0)
mch = 1:SetGadgetText(42,Str(mch))
reso = 0:resj = 0 :mch = 1
mchgo = 0:mchgj = 0:pto = 0:ptj = 0
SetGadgetText(44,"0"):SetGadgetText(45,"0")
SetGadgetText(48,"0"):SetGadgetText(49,"0")
dppart = 1;drapeau départ partie
CloseWindow(70)
StickyWindow(1,1)
Break
Case 84
ClearGadgetItems(79)
DeleteFile("scorCPF")
Case 85 ;bt stop
CloseWindow(70)
StickyWindow(1,1)
Break
EndSelect
EndIf
ForEver
EndProcedure
Procedure gptm(pto,ptj);gestion points manches
reso = reso + pto : resj = resj + ptj
SetGadgetText(48,Str(reso)) : SetGadgetText(49,Str(resj))
If reso = 12
aff(10):mchgo = mchgo + 1: SetGadgetText(44,Str(mchgo))
EndIf
If resj = 12
aff(11):mchgj = mchgj + 1: SetGadgetText(45,Str(mchgj))
EndIf
If reso = 12 Or resj = 12
pto = 0:ptj= 0:reso = 0: resj = 0
SetGadgetText(48,Str(reso)) : SetGadgetText(49,Str(resj))
If mch = 3
dppart = 0
If mchgo > mchgj
aff(13)
Else
aff(14)
EndIf
cc =0:cp = 0:cf = 0:inf1(4,3)
enrsc$ = FormatDate("%dd/%mm/%YYYY - %hhH %ii ",Date()) + "Epsikal " + Str(mchgo) + " " + nj$ + " " + Str(mchgj)+" "+ "Dif " +Str(dpdif)
OpenFile(151,"scorCPF")
FileSeek(151, Lof(151)):WriteStringN(151,enrsc$)
CloseFile(151)
Else
mch = mch + 1:aff(12):SetGadgetText(42,Str(mch))
EndIf
EndIf
EndProcedure
Procedure aff(n)
Select n
Case 1
SetGadgetText(35,"Pas joué"):inf1(0,1)
Case 2
SetGadgetText(35,"Pas assez rapide"):inf1(0,1)
Case 3
SetGadgetText(35,"Coup nul"):SetGadgetText(36,"Pas de point")
Case 4
inf1(1,2)
Case 5
inf1(2,1)
Case 6
inf1(1,1)
Case 7
inf1(3,2)
Case 8
inf1(2,2)
Case 9
inf1(3,1)
Case 10
SetGadgetText(35,"Epsikal gagne cette manche"):SetGadgetText(36,"Haïe! haïe! ")
Case 11
SetGadgetText(35,nj$ + " gagne cette manche"):SetGadgetText(36,"Bravo!")
Case 12
SetGadgetText(35,"Nouvelle manche"):SetGadgetText(36,"Que le meilleur gagne !")
Case 13
SetGadgetText(35,"Epsikal gagne la partie"):SetGadgetText(36,"Pas de chanche !")
Case 14
SetGadgetText(35,"Bravo ! " + nj$ + " gagne la partie"):SetGadgetText(36,"Super !")
EndSelect
Sleep_(2550)
SetGadgetText(35,""):SetGadgetText(36,"")
a = 0:dpj = 0:chor = 0:SetGadgetState(23,0):SetGadgetState(24,0)
EndProcedure
Procedure Epsikal()
Static nbtour
nbtour = nbtour + 1
If dpdif= 2:t= 3:EndIf
If dpdif= 3:t= 2:EndIf
If dpdif = 1
chor = Round(Random(34,10)/10,#PB_Round_Nearest)
Else
If nbtour = t
If cc > cp And cc > cf:chor = 2:EndIf
If cp > cc And cp > cf:chor = 3:EndIf
If cf > cc And cf > cp:chor = 1:EndIf
Else
chor = Round(Random(34,10)/10,#PB_Round_Nearest)
EndIf
If nbtour = t: nbtour = 0: EndIf
EndIf
If nbtour = t:nbtour = 0:EndIf
If chor = 0 : chor = 1:EndIf
If chor = 1:im = 204:EndIf
If chor = 2:im = 205:EndIf
If chor = 3:im = 206:EndIf
SetGadgetState(23,ImageID(im))
EndProcedure
Procedure tdv(ch);table de vérité
Select chor
Case 1 ;cis
If ch = 1:pto = 0 :ptj = 0:Inf = 3:EndIf
If ch = 2:pto = 0 :ptj = 1:Inf = 4:EndIf
If ch = 3:pto = 1 :ptj = 0:Inf = 5:EndIf
Case 2 ;pier
If ch = 2:pto = 0 :ptj = 0:Inf = 3:EndIf
If ch = 1:pto = 1 :ptj = 0:Inf = 6:EndIf
If ch = 3:pto = 0 :ptj = 1:Inf = 7:EndIf
Case 3 ;feuil
If ch = 3:pto = 0 :ptj = 0:Inf = 3:EndIf
If ch = 1:pto = 0 :ptj = 1:Inf = 8:EndIf
If ch = 2:pto = 1 :ptj = 0:Inf = 9:EndIf
EndSelect
If ch <> 0
aff(inf):gptm(pto,ptj)
EndIf
EndProcedure
OpenWindow(1, 0, 0, 800, 800, "Test",#PB_Window_BorderLess | #PB_Window_ScreenCentered)
StickyWindow(1,1)
SetWindowColor(1,$B69F67)
Forme(1):Titre()
TextGadget(3,140,70,125,27, "Règle du jeu",#SS_NOTIFY)
TextGadget(4,300,70,125,27, "Scores",#SS_NOTIFY)
TextGadget(5,420,70,140,27, "Nouvelle partie",#SS_NOTIFY)
TextGadget(6,600,70,125,27, "Arrêt",#SS_NOTIFY)
For t=3 To 6
SetGadgetFont(t,FontID1):SetGadgetColor(t,#PB_Gadget_BackColor,$B69F67)
Next
TextGadget(10,210,220,55,15, "Ciseaux")
TextGadget(11,380,220,55,15, "Pierre")
TextGadget(12,552,220,55,15, "Feuille")
For u = 10 To 12
SetGadgetFont(u,FontID2):Bcoul(u,$B69F67):Fcoul(u,$00FFFF)
Next
TextGadget(35,170,240,465,40,"",#PB_Text_Center)
SetGadgetFont(35,FontID3):Bcoul(35,$B69F67):Fcoul(35,$00FF00)
TextGadget(36,180,280,445,40,"",#PB_Text_Center)
SetGadgetFont(36,FontID3):Bcoul(36,$B69F67):Fcoul(36,$7A96E9)
inf1(4,3)
TextGadget(37,240,365,100,35, "Epsikal")
SetGadgetFont(37,FontID4):Bcoul(37,$B69F67):Fcoul(37,$C1B6FF)
TextGadget(38,328,374,70,15, "Calculateur")
SetGadgetFont(38,FontID2):Bcoul(38,$B69F67):Fcoul(38,$00FFFF)
TextGadget(39,410,374,60,15, "Joueur")
SetGadgetFont(39,FontID2):Bcoul(39,$B69F67):Fcoul(39,$00FFFF)
TextGadget(40,465,365,140,35, "")
SetGadgetFont(40,FontID4):Bcoul(40,$B69F67):Fcoul(40,$FF0000)
TextGadget(41,300,320,80,30, "Manche")
Fcoul(41,$FFFFFF)
TextGadget(42,430,320,30,30, "0")
Fcoul(42,$FFFFFF)
TextGadget(43,260,405,100,30, "Manche G")
Fcoul(43,$95EC89)
TextGadget(44,360,405,30,30, "0",#PB_Text_Center)
Fcoul(44,$95EC89)
TextGadget(45,420,405,30,30, "0")
Fcoul(45,$95EC89)
TextGadget(46,455,405,100,30, "Manche G")
Fcoul(46,$95EC89)
TextGadget(47,280,445,90,30, "Point(s)")
Fcoul(47,$7AADDA)
TextGadget(48,370,445,30,30, "0")
Fcoul(48,$7AADDA)
TextGadget(49,420,445,30,30, "0")
Fcoul(49,$7AADDA)
TextGadget(50,460,445,90,30, "Point(s)")
Fcoul(50,$7AADDA)
For zz = 41 To 50
SetGadgetFont(zz,FontID1):Bcoul(zz,$B69F67)
Next
TextGadget(51,367,620,70,100, "3",#PB_Text_Center)
SetGadgetFont(51,FontID5):Bcoul(51,$B69F67):Fcoul(51,$00FFFF)
ImageGadget(20,170,115,100,30,ImageID(201))
ImageGadget(21,341,115,100,30,ImageID(202))
ImageGadget(22,512,115,100,30,ImageID(203))
ImageGadget(23,300,485,100,30,ImageID(204))
ImageGadget(24,401,485,100,30,ImageID(203))
TextGadget(55,80,100,640,1,"");lgh1
Bcoul(55,$FF00FF)
TextGadget(56,400,380,1,180,"");lgv1
Bcoul(56,$BAAB85)
Repeat
If Event = #WM_LBUTTONDOWN
SendMessage_(WindowID(1), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
Event = WaitWindowEvent()
If Event = #PB_Event_Timer And EventTimer() = 100
If dppart = 1
If a= 0:SetGadgetState(23,0):SetGadgetState(24,0):EndIf
a = a - 1
dc = 4 + a
If dc = 0
If dpsn = 1
CatchSound(150, ?bipj_wav_start)
PlaySound (150,#PB_Sound_Frame,20)
EndIf
Epsikal();le calculateur
EndIf
If dc >= 0
SetGadgetText(51,Str(dc))
EndIf
If dc = -2 And dpj = 0
aff(1):gptm(1,0);pas joué
EndIf
EndIf
EndIf
If Event = #PB_Event_Gadget
Select EventGadget()
Case 3 ;règle du jeu
MessageRequester("Règle du jeu",LT$,#PB_MessageRequester_Ok | #PB_MessageRequester_Info)
Case 4 ;scor
npcr(2)
Case 5;nouv partie
npcr(1)
Case 6
Event = #PB_Event_CloseWindow ; On quitte
Break
Case 20
Select EventType()
Case #PB_EventType_LeftClick
If dc < 1
dpj = 1
cc = cc +1:SetGadgetState(24,ImageID(201))
If dc = -1
aff(2):gptm(1,0)
Else
tdv(1)
EndIf
EndIf
EndSelect
Case 21
Select EventType()
Case #PB_EventType_LeftClick
If dc < 1
dpj = 1
cp = cp +1:SetGadgetState(24,ImageID(202))
If dc = -1
aff(2):gptm(1,0)
Else
tdv(2)
EndIf
EndIf
EndSelect
Case 22
Select EventType()
Case #PB_EventType_LeftClick
If dc < 1
dpj = 1
cf = cf +1:SetGadgetState(24,ImageID(203))
If dc = -1
aff(2):gptm(1,0)
Else
tdv(3)
EndIf
EndIf
EndSelect
EndSelect
EndIf
ForEver