tourhanoi

Programmation avancée de jeux en PureBasic
spirit
Messages : 3
Inscription : sam. 28/juin/2008 7:20

tourhanoi

Message par spirit »

Code : Tout sélectionner

 
InitSprite()
InitSound()
InitKeyboard()
InitMouse()
Structure fg
n.w
x.f
y.f
w.f
s.w
EndStructure
Global nb,wna,wnb
Procedure Open_Window_0()
  If OpenWindow(0, 381, 226, 316, 205, "select",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(0))
      Frame3DGadget(0, 20, 10, 280, 180, "")
      ButtonGadget(1, 90, 140, 130, 40, "OK")
      StringGadget(2, 80, 70, 150, 40, "select niveau (de 1 a 10)", #PB_String_Numeric)
      
    EndIf
  EndIf
EndProcedure
Open_Window_0()
Repeat
e=WaitWindowEvent()
If EventGadget()=1:quit=1:EndIf


Until e=#PB_Event_CloseWindow Or quit=1
nb=Val(GetGadgetText(2)) 

If nb<1 Or nb>10
End
EndIf





Global Dim  p.fg(nb),xs.f=250;{------------------------------------
#width=500 ;screen
#hight=450 ;screen
#ws=100 ;witdth of sprite
#hs=20 ;height of sprite
;#nb=7 ;nb de boulet
cline.f=0 ;color of the line
;---------line-------
xa.f=100:ya.f=100:xyw.f=350
xb.f=250:yb.f=100
 xc.f=400:yc.f=100
;------------------------
cbox.f=RGB(20,200,100)


ClearScreen=RGB(200,200,200)
;}------------------------------------




LoadFont(0,"",15)
LoadFont(1,"",30)




Procedure boxe(c.f)

For i=0 To nb-1
If p(i)\s=1:p(i)\x=xs-(p(i)\w/2):EndIf

 Box(p(i)\x,p(i)\y,p(i)\w,#hs,c)
 Box(p(i)\x+2,p(i)\y+2,p(i)\w-4,#hs-4,c*100)
  Box(p(i)\x+4,p(i)\y+4,p(i)\w-8,#hs-8,c*300)
  Next
 EndProcedure





debut.f=ElapsedMilliseconds()

 OpenWindow(0, 216, 0, #width,#hight, "tourhanoi",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar )
 OpenWindowedScreen(WindowID(0),0,0,#width,#hight,1,0,0)
 
 Gosub begin
;-----------------------------------------------------------------------------------------
Repeat
      
      
      
FlipBuffers()
ExamineMouse()
ExamineKeyboard()
ClearScreen(ClearScreen)

StartDrawing(ScreenOutput())
Gosub drawline
Gosub win


Boxe(cbox)


Gosub move
Circle(xs,ya-5,10,658794)
Circle(xs,ya-5,8,6587945)
If win=1

DrawingFont(FontID(1))
DrawText(200,200,"you win",255,clearscreen)
DrawingFont(FontID(0))
DrawText(200,300,"Time "+Str(time/1000)+"s "+Str(time),255,clearscreen)
If p3=0
;PlaySound(3,0)
ReleaseMouse(1)
EndIf
p3=1
Else
DrawingFont(FontID(0))
time=(ElapsedMilliseconds()-debut)
 
DrawText(20,20,"Time :"+Str(time/1000)+"s "+Str(time-((time/1000)*1000)),255,clearscreen)
EndIf
StopDrawing()

Until WaitWindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
;----------------------------------------------------------------------------------------
End
;{
begin:
win=0:pw.f=0

py.f=ya+10
For i=0 To nb-1 
pw.f+(10):py.f+#hs+10
p(i)\w=pw
p(i)\x=xb-(p(i)\w/2)
p(i)\y=py
Next
Return

drawline:
Line(xa,ya,0,xyw,cline)
Line(xb,yb,0,xyw,cline)
Line(xc,yc,0,xyw,cline)
Return
move:
If KeyboardReleased(#PB_Key_Right)And win=0 
If xs=xa:xs=xb:Else
If xs=xb:xs=xc:Else
If xs=xc:xs=xa
EndIf:EndIf:EndIf::EndIf

If KeyboardReleased(#PB_Key_Left) And win=0 
If xs=xa:xs=xc:Else
If xs=xb:xs=xa:Else
If xs=xc:xs=xb
 EndIf:EndIf:EndIf::EndIf


If KeyboardReleased(#PB_Key_Up)And win=0 
If slect=0
For i=0 To nb-1
If p(i)\x=xs-(p(i)\w/2):p(i)\y=ya-5:p(i)\s=1:is=i:Slect=1:Break:EndIf
Next
Else

For i=0 To nb-1
If p(i)\x=xs-(p(i)\w/2) And p(i)\s=0:
oi=i:Break
Else :oi=-1
EndIf
Next
If oi<>-1
If is<oi
p(is)\y=p(oi)\y-10-#hs:p(is)\s=0:Slect=0
Else
;If IsSound(2):PlaySound(2,0):EndIf
EndIf
Else
p(is)\y=py:p(is)\s=0:slect=0
EndIf
EndIf
;If IsSound(1):PlaySound(1,0):EndIf
EndIf




Return
;}

win:
For i=0 To nb-1
If p(i)\x=xa-(p(i)\w/2):wna+1:EndIf
If p(i)\x=xc-(p(i)\w/2):wnb+1:EndIf
Next
If wna=nb And Slect=0:win=1:Else:wna=0:EndIf
If wnb=nb And Slect=0:win=1:Else:wnb=0:EndIf
Return



Anonyme

Message par Anonyme »

tout ce code pour un message box ?? et pas un mot , même un simple bonjour de ta part, pas top...
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

explication du jeux !! :D


lorsque la message box demande le niveau
tu efface le message
et tu entre un chiffre entre 1 et 10 (c'est le nombre de palets)
entre 4 par ex !!


ensuite le rond représente la main tu peux déplacer cette main avec les touches flèche gauche-droite


puis la touche flèche Haut permet de soulever un palet
ensuite il te faut déplacer la main (fleche gauche-droite) puis a nouveau flèche du haut pour lâcher le palet !!

donc

flèche gauche--droite pour déplacer a gauche et a droite

Flèche Haut pour prendre ou lâcher le palet !! :D

pas mal ce code !! :D

mais une explication aurai été sympath !! :D
Répondre