la mienne (elle s'appelle pareil

)
()
Prgm
¨ SeaWar pour TI-89 et TI-92
¨ Programmå par
¨ Christophe Molon-Noblot
¨ 1999-2000
Local grille,selec,sens,test,bateau,autosel,tir,autotir,recap,grillepi
setFold(vars)»rep1
Lbl debut
Try
Unlock nj,ti
nj»i
ti+1»ti
i+1»i
Else
EndTry
Dialog
Title "*** 'Tophe's SeaWar ***"
DropDown " Partie:",{"1 joueur","2 joueurs"},i
DropDown " Version:",{"TI-92","TI-89"},ti
EndDlog
ti-1»ti
i-1»i
If ok=0:Goto fin
Define grille()=Prgm
Local l1,ˆ,ˆ1,ˆ2
setGraph("axes","off")
0»xmin
238-80*ti»xmax
0»ymin
102-26*ti»ymax
0»ˆ
ClrGraph
ClrDraw
FnOff
ClrIO
For ˆ1,0,10
For ˆ2,0,1
Line 20-20*ti+(100-4*ti)*ˆ2,(8-ti)*ˆ1+10-10*ti,(100-4*ti)*ˆ2+100-30*ti,(8-ti)*ˆ1+10-10*ti
Line (8-ti)*ˆ1+20-20*ti+(100-4*ti)*ˆ2,10-10*ti,(8-ti)*ˆ1+20-20*ti+(100-4*ti)*ˆ2,89-20*ti
EndFor
EndFor
{"A","B","C","D","E","F","G","H","I","J"}»l1
If ti=0 Then
For ˆ,1,10
For ˆ1,0,1
PtText l1[ˆ],13+ˆ*8+100*ˆ1,8
EndFor
EndFor
EndIf
For ˆ,1,9
PxlText string(ˆ),93-(8-ti)*ˆ-16*ti,107-31*ti
EndFor
PxlText "10",13-6*ti,104-31*ti
EndPrgm
Define selec()=Prgm
Local k
1»a
1»b
Line (8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,(8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,0
Line (8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,(8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,0
Line (8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,(8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,0
Line (8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,(8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,0
Lbl un
0»k
getKey()»k
If k=264 Then
Dialog
Title "Pause"
Text ""
Text " Reprendre ?"
Text ""
EndDlog
If ok=0:Return
EndIf
If k?0 and k?13 Then
If ti=0 Then
Line 8*a+12+100*j,8*b+2,8*a+12+100*j,8*b+10
Line 8*a+12+100*j,8*b+10,8*a+20+100*j,8*b+10
Line 8*a+20+100*j,8*b+10,8*a+20+100*j,8*b+2
Line 8*a+20+100*j,8*b+2,8*a+12+100*j,8*b+2
Else
Line 7*a-7+96*j,7*b-7,7*a-7+96*j,7*b
Line 7*a-7+96*j,7*b,7*a+96*j,7*b
Line 7*a+96*j,7*b,7*a+96*j,7*b-7
Line 7*a+96*j,7*b-7,7*a-7+96*j,7*b-7
EndIf
If k=344:b-1»b
If k=338:b+1»b
If k=340:a+1»a
If k=337:a-1»a
If a=0:10»a
If a=11:1»a
If b=0:10»b
If b=11:1»b
If ti=0 Then
Line 8*a+12+100*j,8*b+2,8*a+12+100*j,8*b+10,0
Line 8*a+12+100*j,8*b+10,8*a+20+100*j,8*b+10,0
Line 8*a+20+100*j,8*b+10,8*a+20+100*j,8*b+2,0
Line 8*a+20+100*j,8*b+2,8*a+12+100*j,8*b+2,0
Else
Line 7*a-7+96*j,7*b-7,7*a-7+96*j,7*b,0
Line 7*a-7+96*j,7*b,7*a+96*j,7*b,0
Line 7*a+96*j,7*b,7*a+96*j,7*b-7,0
Line 7*a+96*j,7*b-7,7*a-7+96*j,7*b-7,0
EndIf
EndIf
If k=13 Then
Line (8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,(8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti
Line (8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,(8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti
Line (8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+10-10*ti,(8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti
Line (8-ti)*a+20-20*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti,(8-ti)*a+12-19*ti+(100-4*ti)*j,(8-ti)*b+2-9*ti
EndIf
If k=13:Return
Goto un
EndPrgm
Define sens()=Prgm
Local k
Lbl un
0»k
getKey()»k
If k=337 or k=338 or k=340 or k=344 Then
If k=340:1»s
If k=344:2»s
If k=337:3»s
If k=338:4»s
Return
EndIf
Goto un
EndPrgm
Define test()=Prgm
Local ˆ,ˆ0,ˆ1,ˆ2,x,y
¨ modif
PxlText "¥",95,230
0»erreur
0»ˆ1
0»ˆ2
If s=1:1»ˆ1
If s=2:ª1»ˆ2
If s=3:ª1»ˆ1
If s=4:1»ˆ2
If a+ˆ1*(l-1)>10 or a+ˆ1*(l-1)<1:1»erreur
If b+ˆ2*(l-1)>10 or b+ˆ2*(l-1)<1:1»erreur
For ˆ0,ª1,1
For ˆ,ª1,l
a+ˆ0*abs(ˆ2)+ˆ1*ˆ»x
b+ˆ0*abs(ˆ1)+ˆ2*ˆ»y
Try
If iPart(mat[x,y])=10+90*j or iPart(mat[x,y])=110:1»erreur
Else
EndTry
¨ modif
If erreur=1:PxlText " ",95-20*ti,230-80*ti
If erreur=1:Exit
EndFor
EndFor
¨ modif
PxlText " ",95-20*ti,230-80*ti
EndPrgm
Define bateau()=Prgm
Local ˆ1,ˆ2,x,y
0»ˆ1
0»ˆ2
If s=1:1»ˆ1
If s=2:ª1»ˆ2
If s=3:ª1»ˆ1
If s=4:1»ˆ2
For ˆ,1,l
¨ modif
(a+(ˆ-1)*ˆ1)*8+12+100*j»x
¨ modif
92-(b+(ˆ-1)*ˆ2)*8»y
¨ modif
mat[(x-12-100*j)/8,(92-y)/8]+10+90*j+0.1*l1-0.09*l1*j»mat[(x-12-100*j)/8,(92-y)/8]
¨ modif
If i=1 or j=0 and i=0:RclPic jeuxswar1,y,x
EndFor
EndPrgm
Define autosel()=Prgm
rand(4)»s
rand(10)»a
rand(10)»b
EndPrgm
Define tir()=Prgm
0»t
0»touche
0»erreur
If iPart(fPart(mat[a,b]/10)*10)=1+4*j or iPart(fPart(mat[a,b]/10)*10)=6 Then
1»erreur
Return
Else
If i=0 and ntir=0 and j=1 Then
For ˆ5,ª1,1
For ˆ6,ª1,1
Try
If (iPart(fPart(mat[ˆ5+a,ˆ6+b]/10)*10)=5 or iPart(fPart(mat[ˆ5+a,ˆ6+b]/10)*10)=6) and iPart(fPart(mat[ˆ5+a,ˆ6+b]/100)*10)=1 Then
mat[a,b]+5»mat[a,b]
1»erreur
Return
EndIf
Else
EndTry
EndFor
EndFor
EndIf
¨ modif
PxlText " ",1,1
¨ modif pause(())
PxlText "Tir en "&{"A","B","C","D","E","F","G","H","I","J"}[a]&"-"&string(b)&" :",1,1
mat[a,b]+1+4*j»mat[a,b]
If iPart(mat[a,b])=111+4*j or iPart(mat[a,b])=116 or iPart(mat[a,b])=101-86*j or iPart(mat[a,b])=106-86*j or iPart(mat[a,b])=106-90*j Then
If i=0:1»touche
If j=0:fPart(fPart(mat[a,b])*10)*10»t
If j=1:iPart(fPart(mat[a,b])*10)»t
If j=0 Then
l1[t]+1»l1[t]
If l1[t]={2,3,3,4,5}[t] Then
¨ modif
PxlText "Touchå-coulå !",1,74
RclPic jeuxswar1,92-8*b,12+8*a+100*abs(1-j)
Else
¨ modif
PxlText "Touchå ! ",1,74
¨ modif
RclPic jeuxswar1,92-8*b,12+8*a+100*abs(1-j)
EndIf
EndIf
If j=1 Then
If i=0:1»touche
l2[t]+1»l2[t]
If l2[t]={2,3,3,4,5}[t] Then
¨ modif
PxlText "Touchå-coulå !",1,74
¨ modif
RclPic jeuxswar1,92-8*b,12+8*a+100*abs(1-j)
If i=0 Then
0»ntir
0»touche
EndIf
Else
¨ modif
PxlText "Touchå ! ",1,74
If i=0:1»touche
¨ modif
RclPic jeuxswar1,92-8*b,12+8*a+100*abs(1-j)
EndIf
EndIf
Else
¨ modif
PxlText "Dans l'eau ! ",1,74
EndIf
EndIf
¨ modif
RclPic jeuxswar2,92-8*b,12+8*a+100*abs(1-j)
For ˆ,1,200
EndFor
EndPrgm
Define recap()=Prgm
5»lmax
If l2[5]=5 Then
4»lmax
If l2[4]=4 Then
3»lmax
If l2[3]=3 and l2[2]=3 Then
2»lmax
EndIf
EndIf
EndIf
If ntir=0 and touche=0 Then
rand(5)*2»b
rand(10)»a
If fPart(a/2)=abs(1-w1)/2:b-1»b
EndIf
If touche=1 and ntir=0 Then
{a,b}»coord1
1»ntir
Lbl un
rand(4)»r
{0,ª1,1,0}[r]»rr1
{1,0,0,ª1}[r]»rr2
a+rr1»a1
b+rr2»b1
If a1<1 or a1>10 or b1<1 or b1>10:Goto un
If iPart(fPart(mat[a1,b1]/10)*10)=5 or iPart(fPart(mat[a1,b1]/10)*10)=6:Goto un
Return
EndIf
If touche=0 and ntir=1 Then
Lbl deux
rand(4)»r
{0,ª1,1,0}[r]»rr1
{1,0,0,ª1}[r]»rr2
coord1[1]+rr1»a1
coord1[2]+rr2»b1
If a1<1 or a1>10 or b1<1 or b1>10:Goto deux
If iPart(fPart(mat[a1,b1]/10)*10)=5 or iPart(fPart(mat[a1,b1]/10)*10)=6:Goto deux
Return
EndIf
If touche=1 and ntir=1 Then
{a,b}»coord2
If coord2[1]=coord1[1]:1»s
If coord2[2]=coord1[2]:2»s
newList(lmax*2-1)»liste1
liste1»liste2
liste2»liste3
liste1»liste10
liste2»liste20
liste3»liste30
Fill 1,liste3
If s=1 Then
Fill a,liste1
For ˆ,ªlmax+1,lmax-1
ˆ+b»liste2[ˆ+lmax]
EndFor
EndIf
If s=2 Then
Fill b,liste2
For ˆ,ªlmax+1,lmax-1
ˆ+a»liste1[ˆ+lmax]
EndFor
EndIf
0»ff
For ˆ,1,dim(liste1)
Try
If liste1[ˆ]<1 Then
mid(liste1,ˆ+1)»liste10
mid(liste2,ˆ+1)»liste20
mid(liste3,ˆ+1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,1,dim(liste2)
Try
If liste2[ˆ]<1 Then
mid(liste1,ˆ+1)»liste10
mid(liste2,ˆ+1)»liste20
mid(liste3,ˆ+1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,dim(liste2),1,ª1
Try
If liste2[ˆ]>10 Then
left(liste1,ˆ-1)»liste10
left(liste2,ˆ-1)»liste20
left(liste3,ˆ-1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,dim(liste1),1,ª1
Try
If liste1[ˆ]>10 Then
left(liste1,ˆ-1)»liste10
left(liste2,ˆ-1)»liste20
left(liste3,ˆ-1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,1,dim(liste3)
Try
liste1[ˆ]»u
liste2[ˆ]»v
mat[u,v]»f
If iPart(fPart(f/10)*10)=5 or iPart(fPart(f/10)*10)=6 Then
If iPart(fPart(f/100)*10)=1 Then
5»liste3[ˆ]
Else
0»liste3[ˆ]
EndIf
EndIf
Else
EndTry
EndFor
0»ff
For ˆ,1,lmax-1
Try
If liste3[ˆ]=0 Then
mid(liste3,ˆ+1)»liste30
mid(liste2,ˆ+1)»liste20
mid(liste1,ˆ+1)»liste10
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
For ˆ,0,lmax-2
Try
If liste3[dim(liste3)-ˆ]=0 Then
left(liste3,dim(liste3)-ˆ-1)»liste30
left(liste2,dim(liste3)-ˆ-1)»liste20
left(liste1,dim(liste3)-ˆ-1)»liste10
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»a1
0»b1
rand(2)-1»r
If r=0 Then
For ˆ,1,dim(liste3)
Try
If liste3[ˆ]=5 and a1=0 Then
{ª1,1}[rand(2)]»rr2
If ˆ=1:1»rr2
If ˆ=dim(liste3):ª1»rr2
If liste3[ˆ+rr2]=1 Then
liste1[ˆ+rr2]»a1
liste2[ˆ+rr2]»b1
ˆ+rr2»ˆ1
Else
If ˆ=1:ª1»rr2
If ˆ=dim(liste3):1»rr2
If liste3[ˆ-rr2]=1 Then
liste1[ˆ-rr2]»a1
liste2[ˆ-rr2]»b1
ˆ-rr2»ˆ1
EndIf
EndIf
EndIf
Else
EndTry
EndFor
Else
For ˆ,dim(liste3),1,ª1
Try
If liste3[ˆ]=5 and a1=0 Then
{ª1,1}[rand(2)]»rr2
If ˆ=1:1»rr2
If ˆ=dim(liste3):ª1»rr2
If liste3[ˆ+rr2]=1 Then
liste1[ˆ+rr2]»a1
liste2[ˆ+rr2]»b1
ˆ+rr2»ˆ1
Else
If ˆ=1:ª1»rr2
If ˆ=dim(liste3):1»rr2
If liste3[ˆ-rr2]=1 Then
liste1[ˆ-rr2]»a1
liste2[ˆ-rr2]»b1
ˆ-rr2»ˆ1
EndIf
EndIf
EndIf
Else
EndTry
EndFor
EndIf
2»ntir
Return
EndIf
If ntir=2 Then
0»ff
For ˆ,1,dim(liste1)
Try
If liste1[ˆ]<1 Then
mid(liste1,ˆ+1)»liste10
mid(liste2,ˆ+1)»liste20
mid(liste3,ˆ+1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,1,dim(liste2)
Try
If liste2[ˆ]<1 Then
mid(liste1,ˆ+1)»liste10
mid(liste2,ˆ+1)»liste20
mid(liste3,ˆ+1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,dim(liste2),1,ª1
Try
If liste2[ˆ]>10 Then
left(liste1,ˆ-1)»liste10
left(liste2,ˆ-1)»liste20
left(liste3,ˆ-1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,dim(liste1),1,ª1
Try
If liste1[ˆ]>10 Then
left(liste1,ˆ-1)»liste10
left(liste2,ˆ-1)»liste20
left(liste3,ˆ-1)»liste30
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»ff
For ˆ,1,dim(liste3)
Try
liste1[ˆ]»u
liste2[ˆ]»v
mat[u,v]»f
If iPart(fPart(f/10)*10)=5 or iPart(fPart(f/10)*10)=6 Then
If iPart(fPart(f/100)*10)=1 Then
5»liste3[ˆ]
Else
0»liste3[ˆ]
EndIf
EndIf
Else
EndTry
EndFor
0»ff
For ˆ,1,lmax-1
Try
If liste3[ˆ]=0 Then
mid(liste3,ˆ+1)»liste30
mid(liste2,ˆ+1)»liste20
mid(liste1,ˆ+1)»liste10
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
For ˆ,0,lmax-2
Try
If liste3[dim(liste3)-ˆ]=0 Then
left(liste3,dim(liste3)-ˆ-1)»liste30
left(liste2,dim(liste3)-ˆ-1)»liste20
left(liste1,dim(liste3)-ˆ-1)»liste10
1»ff
EndIf
Else
EndTry
EndFor
If ff=1 Then
liste30»liste3
liste20»liste2
liste10»liste1
EndIf
0»a1
0»b1
rand(2)-1»r
If r=0 Then
For ˆ,1,dim(liste3)
Try
If liste3[ˆ]=5 and a1=0 Then
{ª1,1}[rand(2)]»rr2
If ˆ=1:1»rr2
If ˆ=dim(liste3):ª1»rr2
If liste3[ˆ+rr2]=1 Then
liste1[ˆ+rr2]»a1
liste2[ˆ+rr2]»b1
ˆ+rr2»ˆ1
Else
If ˆ=1:ª1»rr2
If ˆ=dim(liste3):1»rr2
If liste3[ˆ-rr2]=1 Then
liste1[ˆ-rr2]»a1
liste2[ˆ-rr2]»b1
ˆ-rr2»ˆ1
EndIf
EndIf
EndIf
Else
EndTry
EndFor
Else
For ˆ,dim(liste3),1,ª1
Try
If liste3[ˆ]=5 and a1=0 Then
{ª1,1}[rand(2)]»rr2
If ˆ=1:1»rr2
If ˆ=dim(liste3):ª1»rr2
If liste3[ˆ+rr2]=1 Then
liste1[ˆ+rr2]»a1
liste2[ˆ+rr2]»b1
ˆ+rr2»ˆ1
Else
If ˆ=1:ª1»rr2
If ˆ=dim(liste3):1»rr2
If liste3[ˆ-rr2]=1 Then
liste1[ˆ-rr2]»a1
liste2[ˆ-rr2]»b1
ˆ-rr2»ˆ1
EndIf
EndIf
EndIf
Else
EndTry
EndFor
EndIf
2»ntir
Return
EndIf
EndPrgm
Define autotir()=Prgm
a1»a
b1»b
If ntir=0 Then
rand(5)*2»b
rand(10)»a
If fPart(a/2)=abs(1-w1)/2:b-1»b
EndIf
EndPrgm
coord1[2]»b
grille()
PxlText " ",1,1
StoPic grillepi
rand(2)-1»w1
0»q
0»o
0»ntir
newMat(10,10)»mat
newMat(3,3)»m2
For j,0,i
If j=1 and i=1 Then
ClrDraw
RclPic grillepi
EndIf
For l1,5,1,ª1
l1»l
If l1=2:3»l
If l1=1:2»l
If l=5:PxlText "Placer porte-avions",1-ti,1-ti
If l=4:PxlText "Placer frågate ",1-ti,1-ti
If l=3:PxlText "Placer sous marins ",1-ti,1-ti
If l=2:PxlText "Placer navette ",1-ti,1-ti
Lbl test
selec()
If ok=0:Goto fin
sens()
test()
If erreur=1:Goto test
bateau()
EndFor
If j=1 and i=1 Then
ClrDraw
RclPic grillepi
EndIf
EndFor
If i=0 Then
If ti=0:PxlText "Placement de l'ordinateur:",1,1
For l1,5,1,ª1
l1»l
If l1=2:3»l
If l1=1:2»l
If ti=0 Then
If l=5:PxlText " porte-avions",1,159
If l=4:PxlText " frågate ",1,159
If l=3:PxlText " sous marins ",1,159
If l=2:PxlText " navette ",1,159
Else
If l=5:PxlText "¡ porte-avions",0,0
If l=4:PxlText "¡ frågate ",0,0
If l=3:PxlText "¡ sous marins ",0,0
If l=2:PxlText "¡ navette ",0,0
EndIf
Lbl test2
autosel()
test()
If erreur=1:Goto test2
bateau()
EndFor
EndIf
PxlText " ",1,1
newList(5)»l1
newList(5)»l2
Lbl tir
For j,0,i
Lbl tir2
PxlText "Tir:"&{"joueur","joueur 1","joueur 2"}[j+i+1]&" sålectionnez une case. ",1,1
abs(j-1)»j
selec()
If ok=0:Goto fin
abs(1-j)»j
tir()
If erreur=1:Goto tir2
EndFor
If i=0 Then
1»j
Lbl tir3
PxlText "Tir ordinateur. ",1,1
autotir()
tir()
If erreur=1:Goto tir3
recap()
EndIf
sum(l1)»n1
sum(l2)»n2
If n1=17 or n2=17 Then
0»g
0»g1
If n1=17:1»g
If n2=17:2»g
If n1=17 and n2=17:1»g1
g+3*g1»g
Dialog
Title "*** 'Tophe's SeaWar ***"
Text ""
Text " "&{"Gagnant :"," Egalitå !"}[g1+1]&{"joueur","ordinateur","joueur 1","joueur 2","","",""}[g+2*i]
Text ""
EndDlog
Dialog
Title "*** 'Tophe's SeaWar ***"
Text ""
Text " Rejouer ?"
Text ""
EndDlog
If ok=0:Goto fin
If ok=1:Goto debut
EndIf
If n1?17 and n2?17:Goto tir
Lbl fin
i»nj
DelVar mat,erreur,ntir,a1,b1,ff,coord1,coord2,liste1,liste2,liste3,liste10,liste20,liste30,a,b,f,g,i,g1,j,l,l1,l2,lmax,m2,mat,m1,m2o,g,r,rr1,rr2,s,t,touche,u,v,w1,ˆ,ˆ1,ˆ5,ˆ6,n1,n2,o,q
Lock ti,nj
setFold(#rep1)
EndPrgm