Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
- StdCtrls, CustomDrawnControls,customdrawn_common, MaskEdit;
- type
- { TForm1 }
- TForm1 = class(TForm)
- CDButton1: TCDButton;
- CDButton2: TCDButton;
- CDButton3: TCDButton;
- Label1: TLabel;
- cTurn: TShape;
- pTurn: TShape;
- procedure CDButton1Click(Sender: TObject);
- procedure CDButton2Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure pShapeMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- function pOdigraj(p,q:integer):boolean;
- function desno(x,y,tip:integer):integer;
- function levo(x,y,tip:integer):integer;
- function gore(x,y,tip:integer):integer;
- function dole(x,y,tip:integer):integer;
- function adesno(x,y:integer):integer;
- function alevo(x,y:integer):integer;
- function agore(x,y:integer):integer;
- function adole(x,y:integer):integer;
- function isPotopljen(x,y,tip:integer):boolean;
- procedure boji(x,y,tip:integer);
- procedure zameni(var a,b:integer; max:integer);
- procedure cOdigraj;
- function Racunaj(x,y,max:integer):integer ;
- procedure kraj;
- private
- { private declarations }
- public
- end;
- var
- Form1: TForm1;
- pBoard,pShots,cBoard,cShots: array[0..9,0..9] of integer;
- PMat,CMat:array[0..9,0..9] of TShape;
- mode:integer;
- prob:array[0..9,0..9] of integer;
- maxprob:array[0..100]of integer;
- prethodni:integer;
- pships,cships:array[1..4]of integer;
- uzast,smer,ort:integer; {ort=0 horizontalno smer=-1 levo smer=1 desno
- ort=1 vertikalno smer=-1 gore smer=1 dole}
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.FormCreate(Sender: TObject); {Pravi matricu shapeova i podesava pocetne vrednosti}
- var i,j:integer;
- begin
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin pMat[i,j]:= TShape.Create(Form1);
- with pMat[i,j] do
- begin
- width:=30;
- height:=30;
- left:=j*30+30;
- top:=i*30+30;
- visible:=true;
- parent:=Form1;
- shape:=stRectangle;
- name:='shapeA'+ IntToStr(i)+Inttostr(j);
- brush.color:=clwhite;
- brush.style:=bsSolid;
- pen.color:=clblack;
- pen.style:=psSolid;
- pen.width:=1;
- enabled:=true;
- end;
- end;
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin cMat[i,j]:= TShape.Create(Form1);
- with cMat[i,j] do
- begin
- width:=30;
- height:=30;
- left:=j*30+420;
- top:=i*30+30;
- visible:=true;
- parent:=Form1;
- shape:=stRectangle;
- name:='shapeB'+ IntToStr(i)+Inttostr(j);
- brush.color:=clwhite;
- brush.style:=bsSolid;
- pen.color:=clblack;
- pen.style:=psSolid;
- pen.width:=1;
- enabled:=true;
- OnMouseDown:=@Form1.pShapeMouseDown;
- end;
- end;
- end;
- procedure TForm1.kraj;
- var i,j:integer;
- begin
- if pTurn.Brush.color=clRed then
- Showmessage('DEFEAT')
- else
- Showmessage('VICTORY');
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin
- cBoard[i,j]:=0;
- cMat[i,j].brush.color:=clWhite;
- cMat[i,j].enabled:=true;
- end;
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin
- PBoard[i,j]:=0;
- PMat[i,j].brush.color:=clwhite;
- end;
- for i:=1 to 4 do
- begin
- cships[i]:=4-i+1;
- pships[i]:=4-i+1
- end;
- prethodni:=0;
- uzast:=0;
- mode:=1;
- end;
- function TForm1.desno(x,y,tip:integer):integer;
- var br:integer;
- begin
- br:=0;
- if tip=1 then
- begin
- if x+1<=9 then
- begin
- if pShots[x,y]=1 then
- br:=1+desno(x+1,y,1)
- else br:=0;
- end
- else br:=0;
- end;
- if tip=2 then
- begin
- if x+1<=9 then
- begin
- if cShots[x,y]=1 then
- br:=1+desno(x+1,y,2)
- else br:=0;
- end
- else br:=0;
- end;
- desno:=br;
- end;
- function TForm1.levo(x,y,tip:integer):integer;
- var br:integer;
- begin
- br:=0;
- if tip=1 then
- begin
- if x-1>=0 then
- begin
- if pShots[x,y]=1 then
- br:=1+levo(x-1,y,1)
- else br:=0;
- end
- else br:=0;
- end;
- if tip=2 then
- begin
- if x-1>=0 then
- begin
- if cShots[x,y]=1 then
- br:=1+levo(x-1,y,2)
- else br:=0;
- end
- else br:=0;
- end;
- levo:=br;
- end;
- function TForm1.gore(x,y,tip:integer):integer;
- var br:integer;
- begin
- br:=0;
- if tip=1 then
- begin
- if y-1>=0 then
- begin
- if pShots[x,y]=1 then
- br:=1+gore(x,y-1,1)
- else br:=0;
- end
- else br:=0;
- end;
- if tip=2 then
- begin
- if y-1>=0 then
- begin
- if cShots[x,y]=1 then
- br:=1+gore(x,y-1,2)
- else br:=0;
- end
- else br:=0;
- end;
- gore:=br;
- end;
- function TForm1.dole(x,y,tip:integer):integer;
- var br:integer;
- begin
- br:=0;
- if tip=1 then
- begin
- if y+1<=9 then
- begin
- if pShots[x,y]=1 then
- br:=1+dole(x,y+1,1)
- else br:=0;
- end
- else br:=0;
- end;
- if tip=2 then
- begin
- if y+1<=9 then
- begin
- if cShots[x,y]=1 then
- br:=1+dole(x,y+1,2)
- else br:=0;
- end
- else br:=0;
- end;
- dole:=br;
- end;
- function TForm1.isPotopljen(x,y,tip:integer):boolean;
- begin
- if tip=1 then
- begin
- if (gore(x,y,1)+dole(x,y,1)-1=cBoard[x,y])or(levo(x,y,1)+desno(x,y,1)-1=cBoard[x,y])or(levo(x,y,1)=cBoard[x,y])or(dole(x,y,1)=cBoard[x,y])or(desno(x,y,1)=cBoard[x,y])or(gore(x,y,1)=cBoard[x,y])then
- begin
- isPotopljen:=true;
- cships[cBoard[x,y]]:=cships[cBoard[x,y]]-1;
- end
- else isPotopljen:=false;
- end;
- if tip=2 then
- begin
- if (gore(x,y,2)+dole(x,y,2)-1=pBoard[x,y])or(levo(x,y,2)+desno(x,y,2)-1=pBoard[x,y])or(levo(x,y,2)=pBoard[x,y])or(dole(x,y,2)=pBoard[x,y])or(desno(x,y,2)=pBoard[x,y])or(gore(x,y,2)=pBoard[x,y])then
- begin
- isPotopljen:=true;
- pships[pBoard[x,y]]:=pships[pBoard[x,y]]-1;
- end
- else isPotopljen:=false;
- end;
- end;
- procedure TForm1.boji(x,y,tip:integer);
- var l,i,k:integer;
- begin
- if tip=1 then
- begin
- l:=cBoard[x,y];
- if l=1 then
- begin
- cMat[x,y].Brush.color:=clRed;
- if x-1>=0 then
- cMat[x-1,y].brush.color:=clGray;
- if x+1<=9 then
- cMat[x+l,y].brush.color:=clGray;
- if y-1>=0 then
- cMat[x,y-1].brush.color:=clGray;
- if y+1<=9 then
- cMat[x,y+1].brush.color:=clGray;
- end;
- if (((levo(x,y,1)+desno(x,y,1))>(gore(x,y,1)+dole(x,y,1)))or(levo(x,y,1)=l)or(desno(x,y,1)=l))and (l<>1)then
- begin
- k:=x-levo(x,y,1)+1;
- if k-1>=0 then
- cMat[k-1,y].brush.color:=clGray;
- if k+l<=9 then
- cMat[k+l,y].brush.color:=clGray;
- for i:=0 to l-1 do
- cMat[k+i,y].brush.color:=clRed;
- end;
- if (((gore(x,y,1)+dole(x,y,1))>(levo(x,y,1)+desno(x,y,1)))or(gore(x,y,1)=l)or(dole(x,y,1)=l))and (l<>1) then
- begin
- k:=y-gore(x,y,1)+1;
- if k-1>=0 then
- cMat[x,k-1].brush.color:=clGray;
- if k+l<=9 then
- cMat[x,k+l].brush.color:=clGray;
- for i:=0 to l-1 do
- cMat[x,k+i].brush.color:=clRed;
- end;
- end;
- if tip=2 then
- begin
- l:=pBoard[x,y];
- if l=1 then
- begin
- pMat[x,y].Brush.color:=clRed;
- if x-1>=0 then
- pMat[x-1,y].brush.color:=clGray;
- if x+1<=9 then
- pMat[x+l,y].brush.color:=clGray;
- if y-1>=0 then
- pMat[x,y-1].brush.color:=clGray;
- if y+1<=9 then
- pMat[x,y+1].brush.color:=clGray;
- end;
- if (((levo(x,y,2)+desno(x,y,2))>(gore(x,y,2)+dole(x,y,2)))or(levo(x,y,2)=l)or(desno(x,y,2)=l))and (l<>1)then
- begin
- k:=x-levo(x,y,2)+1;
- if k-1>=0 then
- pMat[k-1,y].brush.color:=clGray;
- if k+l<=9 then
- pMat[k+l,y].brush.color:=clGray;
- for i:=0 to l-1 do
- pMat[k+i,y].brush.color:=clRed;
- end;
- if (((gore(x,y,2)+dole(x,y,2))>(levo(x,y,2)+desno(x,y,2)))or(gore(x,y,2)=l)or(dole(x,y,2)=l))and (l<>1) then
- begin
- k:=y-gore(x,y,1)+1;
- if k-1>=0 then
- pMat[x,k-1].brush.color:=clGray;
- if k+l<=9 then
- pMat[x,k+l].brush.color:=clGray;
- for i:=0 to l-1 do
- pMat[x,k+i].brush.color:=clRed;
- end;
- end;
- end;
- function TForm1.agore(x,y:integer):integer;
- var br:integer;
- begin
- br:=0;
- if y-1>=0 then
- begin
- if cShots[x,y-1]=0 then
- br:=1+agore(x,y-1)
- else br:=0;
- end
- else br:=0;
- if br>3 then
- agore:=3
- else agore:=br;
- end;
- function TForm1.adole(x,y:integer):integer;
- var br:integer;
- begin
- br:=0;
- if y+1<=9 then
- begin
- if cShots[x,y+1]=0 then
- br:=1+adole(x,y+1)
- else br:=0;
- end
- else br:=0;
- if br>3 then
- adole:=3
- else adole:=br;
- end;
- function TForm1.alevo(x,y:integer):integer;
- var br:integer;
- begin
- br:=0;
- if x-1>=0 then
- begin
- if cShots[x-1,y]=0 then
- br:=1+alevo(x,y-1)
- else br:=0;
- end
- else br:=0;
- if br>3 then
- alevo:=3
- else alevo:=br;
- end;
- function TForm1.adesno(x,y:integer):integer;
- var br:integer;
- begin
- br:=0;
- if x+1<=9 then
- begin
- if cShots[x+1,y]=0 then
- br:=1+adesno(x+1,y)
- else br:=0;
- end
- else br:=0;
- if br>3 then
- adesno:=3
- else adesno:=br;
- end;
- procedure TForm1.zameni(var a,b:integer; max:integer);
- var pom:integer;
- begin
- if b>a then
- begin
- pom:=b;
- b:=a;
- a:=pom;
- end;
- if a>max-1 then
- a:=max-1;
- if b>max-1 then
- b:=max-1;
- end;
- function TForm1.Racunaj(x,y,max:integer):integer;
- var a,b,h,v,pom:integer;
- begin
- if max=1 then
- racunaj:=1;
- if max=2 then
- begin
- a:=alevo(x,y);
- b:=adesno(x,y);
- zameni(a,b,max);
- if a=1 then
- begin
- if b=1 then
- h:=2;
- if b=0 then
- h:=1;
- end
- else h:=0;
- a:=agore(x,y);
- b:=adole(x,y);
- zameni(a,b,max);
- if a=1 then
- begin
- if b=1 then
- v:=2;
- if b=0 then
- v:=1;
- end
- else v:=0;
- racunaj:=h+v;
- end;
- if max=3 then
- begin
- a:=alevo(x,y);
- b:=adesno(x,y);
- zameni(a,b,max);
- if a=1 then
- begin
- if b=1 then
- h:=1;
- if b=0 then
- h:=0;
- end;
- if a=2 then
- begin
- if b=2 then
- h:=3;
- if b=1 then
- h:=2;
- if b=0 then
- h:=1;
- end;
- if a=0 then
- h:=0;
- a:=agore(x,y);
- b:=adole(x,y);
- zameni(a,b,max);
- if a=1 then
- begin
- if b=1 then
- v:=1;
- if b=0 then
- v:=0;
- end;
- if a=2 then
- begin
- if b=2 then
- v:=3;
- if b=1 then
- v:=2;
- if b=0 then
- v:=1;
- end;
- if a=0 then
- v:=0;
- racunaj:=h+v;
- end;
- if max=4 then
- begin
- a:=alevo(x,y);
- b:=adesno(x,y);
- zameni(a,b,max);
- if a=1 then
- h:=0;
- if a=2 then
- begin
- if b=2 then
- h:=2;
- if b=1 then
- h:=1;
- if b=0 then
- h:=0;
- end;
- if a=3 then
- begin
- if b=3 then
- h:=4;
- if b=2 then
- h:=3;
- if b=1 then
- h:=2;
- if b=0 then
- h:=1;
- end;
- if a=0 then
- h:=0;
- a:=agore(x,y);
- b:=adole(x,y);
- zameni(a,b,max);
- if a=1 then
- v:=0;
- if a=2 then
- begin
- if b=2 then
- v:=2;
- if b=1 then
- v:=1;
- if b=0 then
- v:=0;
- end;
- if a=3 then
- begin
- if b=3 then
- v:=4;
- if b=2 then
- v:=3;
- if b=1 then
- v:=2;
- if b=0 then
- v:=1;
- end;
- if a=0 then
- v:=0;
- racunaj:=h+v;
- end;
- end;
- procedure TForm1.cOdigraj;
- var
- a,b,i,j,max,maks,br,k,m1,m2:integer; {max je najveca dostupna duzina broda, a maks je najveci element u prob matrici}
- begin
- if mode=1 then
- begin
- for i:=1 to 4 do
- if pships[i]<>0 then
- max:=i;
- for i:=0 to 9 do
- for j:=0 to 9 do
- prob[i,j]:=Racunaj(i,j,max);
- maks:=0;
- for i:=0 to 9 do
- for j:=0 to 9 do
- if prob[i,j]>maks then
- maks:=prob[i,j];
- br:=0;
- for i:=0 to 9 do
- for j:=0 to 9 do
- if prob[i,j]=maks then
- begin
- maxprob[br]:=i*10+j;
- br:=br+1;
- end;
- k:=random(br);
- k:=maxprob[k];
- m1:=k div 10;
- m2:=k mod 10;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[1]:=pships[1]-1;
- br:=0;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- begin
- cOdigraj;
- end;
- end
- else
- begin
- prethodni:=k;
- uzast:=1;
- mode:=2;
- cOdigraj;
- end;
- end
- else
- begin
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end;
- if mode=2 then
- begin
- if uzast=1 then {DRUGO GADJANJE}
- begin
- a:=prethodni div 10;
- b:=prethodni mod 10;
- if (adesno(a,b)+alevo(a,b))>=(agore(a,b)+adole(a,b)) then {KEKEKEK}
- begin
- if alevo(a,b)>=adesno(a,b) then
- begin
- m1:=a-1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[2]:=pships[2]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=2;
- ort:=0;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a+1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[2]:=pships[2]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=2;
- ort:=0;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end;
- end
- else begin
- if agore(a,b)>=adole(a,b) then
- begin
- m1:=a;
- m2:=b-1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=2;
- ort:=1;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a;
- m2:=b+1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[2]:=pships[2]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=2;
- ort:=1;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end;
- end;
- end;
- if uzast=2 then {TRECE GADJANJE}
- begin
- a:=prethodni div 10;
- b:=prethodni mod 10;
- if ort=0 then {HORIZONTALNO}
- begin
- if smer=-1 then
- begin
- if alevo(a,b)<>0 then
- begin
- m1:=a-1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- smer:=1;
- prethodni:=(a+1)*10+b;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a+2;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- end;
- end
- else
- begin
- if adesno(a,b)<>0 then
- begin
- m1:=a+1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- smer:=-1;
- prethodni:=(a-1)*10+b;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a-2;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- end;
- end;
- end;
- if ort=1 then {VERTIKALNO}
- begin
- if smer=-1 then
- begin
- if agore(a,b)<>0 then
- begin
- m1:=a;
- m2:=b-1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- smer:=1;
- prethodni:=a*10+b+1;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a;
- m2:=b+1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- end;
- end
- else
- begin
- if adole(a,b)<>0 then
- begin
- m1:=a;
- m2:=b+1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- else
- begin
- smer:=-1;
- prethodni:=a*10+b-1;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a;
- m2:=b-1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- else
- begin
- uzast:=3;
- smer:=-1;
- prethodni:=m1*10+m2;
- cOdigraj;
- end;
- end
- end;
- end;
- end;
- end;
- if uzast=3 then {CETVRTO GADJANjE}
- begin
- a:=prethodni div 10;
- b:=prethodni mod 10;
- if ort=0 then {HORIZONTALNO}
- begin
- if smer=-1 then
- begin
- if alevo(a,b)<>0 then
- begin
- m1:=a-1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end
- else
- begin
- smer:=1;
- prethodni:=(a+2)*10+b;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a+3;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end
- end;
- end
- else
- begin
- if adesno(a,b)<>0 then
- begin
- m1:=a+1;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end
- else
- begin
- smer:=-1;
- prethodni:=(a-2)*10+b;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a-3;
- m2:=b;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end;
- end;
- end;
- end;
- if ort=1 then {VERTIKALNO}
- begin
- if smer=-1 then
- begin
- if agore(a,b)<>0 then
- begin
- m1:=a;
- m2:=b-1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end
- else
- begin
- smer:=1;
- prethodni:=a*10+b+2;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a;
- m2:=b+3;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end;
- end;
- end
- else
- begin
- if adole(a,b)<>0 then
- begin
- m1:=a;
- m2:=b+1;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[4]:=pships[4]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end
- end
- else
- begin
- smer:=-1;
- prethodni:=a*10+b-2;
- cShots[m1,m2]:=2;
- pMat[m1,m2].brush.color:=clGray;
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- end;
- end
- else
- begin
- m1:=a;
- m2:=b-3;
- if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
- begin
- cShots[m1,m2]:=1;
- pMat[m1,m2].Brush.Color:=clYellow;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1-1,m2-1].Brush.Color:=clGray;
- cShots[m1-1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1-1,m2+1].Brush.Color:=clGray;
- cShots[m1-1,m2+1]:=2;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- pMat[m1+1,m2-1].Brush.Color:=clGray;
- cShots[m1+1,m2-1]:=2;
- end;
- if m2+1<=9 then
- begin
- pMat[m1+1,m2+1].Brush.Color:=clGray;
- cShots[m1+1,m2+1]:=2;
- end;
- end;
- if isPotopljen(m1,m2,2) then
- begin
- boji(m1,m2,2);
- pships[3]:=pships[3]-1;
- br:=0;
- mode:=1;
- uzast:=0;
- for i:=1 to 4 do
- br:=br+pships[i];
- if br=0 then
- kraj
- else
- cOdigraj;
- end;
- end;
- end;
- end;
- end;
- end;
- end;
- end;
- procedure TForm1.pShapeMouseDown(Sender: TObject; Button: TMouseButton; {Boji polje u zavisnosti da li je pogodjeno ili ne i unosi vrednosti u pShots}
- Shift: TShiftState; X, Y: Integer);
- var m1,m2,i,j,k:integer;
- begin
- if pTurn.Brush.color=clGreen then
- begin
- m1:=0;
- m2:=0;
- for i:=0 to 9 do
- for j:=0 to 9 do
- if Sender=cMat[i,j] then
- begin
- m1:=i;
- m2:=j;
- end;
- if (cBoard[m1,m2]<>0)and(cBoard[m1,m2]<>5) then
- begin
- pShots[m1,m2]:=1;
- cMat[m1,m2].Brush.Color:=clYellow;
- cMat[m1,m2].enabled:=false;
- if m1-1>=0 then
- begin
- if m2-1>=0 then
- begin
- cMat[m1-1,m2-1].Brush.Color:=clGray;
- cMat[m1-1,m2-1].enabled:=false;
- end;
- if m2+1<=9 then
- begin
- cMat[m1-1,m2+1].Brush.Color:=clGray;
- cMat[m1-1,m2+1].enabled:=false;
- end;
- end;
- if m1+1<=9 then
- begin
- if m2-1>=0 then
- begin
- cMat[m1+1,m2-1].Brush.Color:=clGray;
- cMat[m1+1,m2-1].enabled:=false;
- end;
- if m2+1<=9 then
- begin
- cMat[m1+1,m2+1].Brush.Color:=clGray;
- cMat[m1+1,m2+1].enabled:=false;
- end;
- end;
- if isPotopljen(m1,m2,1) then
- begin
- ShowMessage(inttostr(cBoard[m1,m2]));
- ShowMessage('brod potopljen');
- boji(m1,m2,1);
- k:=0;
- for i:=1 to 4 do
- k:=k+cships[i];
- if k=0 then
- kraj;
- end;
- end
- else
- begin
- pShots[m1,m2]:=2;
- cMat[m1,m2].Brush.Color:=clGray;
- cMat[m1,m2].enabled:=false;
- pTurn.Brush.color:=clRed;
- cTurn.Brush.color:=clGreen;
- cOdigraj;
- end;
- end;
- end;
- function TForm1.pOdigraj(p, q: integer): boolean;
- begin
- if cBoard[p,q]=1 then
- pOdigraj:=true
- else
- pOdigraj:=false;
- end;
- function PCheckForShip(m,k,x,l:integer):boolean;
- var ok:boolean;
- br,i,j:integer;
- begin
- ok:=false;
- if x=0 then
- begin
- br:=0;
- if m>=l then
- begin
- for i:=m-l+1 to m do
- if pBoard[i,k]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=1 then
- begin
- br:=0;
- if m+l-1<=9 then
- begin
- for i:=m to m+l-1 do
- if PBoard[i,k]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=2 then
- begin
- br:=0;
- if k>=l then
- begin
- for j:=k-l+1 to k do
- if PBoard[m,j]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=3 then
- begin
- br:=0;
- if k+l-1<=9 then
- begin
- for j:=k to k+l-1 do
- if PBoard[m,j]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- PCheckForShip:=ok;
- end;
- procedure PSetShip(m,k,x,l:integer);
- var i,j:integer;
- begin
- if x=0 then
- begin
- for i:=m-l to m+1 do
- for j:=k-1 to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(pBoard[i,j]<>1)and(pBoard[i,j]<>2)and(pBoard[i,j]<>3)and(pBoard[i,j]<>4) then
- PBoard[i,j]:=5;
- for i:=m-l+1 to m do
- begin
- PBoard[i,k]:=l;
- PMat[i,k].brush.color:=clblue;
- end;
- end;
- if x=1 then
- begin
- for i:=m-1 to m+l do
- for j:=k-1 to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(pBoard[i,j]<>1)and(pBoard[i,j]<>2)and(pBoard[i,j]<>3)and(pBoard[i,j]<>4) then
- PBoard[i,j]:=5;
- for i:=m to m+l-1 do
- begin
- PBoard[i,k]:=l;
- PMat[i,k].brush.color:=clblue;
- end;
- end;
- if x=2 then
- begin
- for i:=m-1 to m+1 do
- for j:=k-l to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(pBoard[i,j]<>1)and(pBoard[i,j]<>2)and(pBoard[i,j]<>3)and(pBoard[i,j]<>4) then
- PBoard[i,j]:=5;
- for j:=k-l+1 to k do
- begin
- PBoard[m,j]:=l;
- PMat[m,j].brush.color:=clblue;
- end;
- end;
- if x=3 then
- begin
- for i:=m-1 to m+1 do
- for j:=k-1 to k+l do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(pBoard[i,j]<>1)and(pBoard[i,j]<>2)and(pBoard[i,j]<>3)and(pBoard[i,j]<>4) then
- PBoard[i,j]:=5;
- for j:=k to k+l-1 do
- begin
- PBoard[m,j]:=l;
- PMat[m,j].brush.color:=clblue;
- end;
- end;
- end;
- procedure PGenerateRandom;
- var
- x,l,m,k,i,j:integer;
- begin
- for l:=4 downto 1 do
- begin
- j:=4-l+1;
- for i:=1 to j do
- begin
- repeat
- randomize;
- m:=random(9);
- k:=random(9);
- until PCheckForShip(m,k,0,l) OR PCheckForShip(m,k,1,l) OR PCheckForShip(m,k,2,l) OR PCheckForShip(m,k,3,l);
- repeat
- x:=random(3);
- until PCheckForShip(m,k,x,l);
- PSetShip(m,k,x,l);
- end;
- end;
- end;
- function cCheckForShip(m,k,x,l:integer):boolean;
- var ok:boolean;
- br,i,j:integer;
- begin
- ok:=false;
- if x=0 then
- begin
- br:=0;
- if m>=l then
- begin
- for i:=m-l+1 to m do
- if cBoard[i,k]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=1 then
- begin
- br:=0;
- if m+l-1<=9 then
- begin
- for i:=m to m+l-1 do
- if cBoard[i,k]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=2 then
- begin
- br:=0;
- if k>=l then
- begin
- for j:=k-l+1 to k do
- if cBoard[m,j]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- if x=3 then
- begin
- br:=0;
- if k+l-1<=9 then
- begin
- for j:=k to k+l-1 do
- if cBoard[m,j]=0 then
- br:=br+1;
- if br=l then
- ok:=true;
- end;
- end;
- cCheckForShip:=ok;
- end;
- procedure cSetShip(m,k,x,l:integer);
- var i,j:integer;
- begin
- if x=0 then
- begin
- for i:=m-l to m+1 do
- for j:=k-1 to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(cBoard[i,j]<>1)and(cBoard[i,j]<>2)and(cBoard[i,j]<>3)and(cBoard[i,j]<>4) then
- cBoard[i,j]:=5;
- for i:=m-l+1 to m do
- cBoard[i,k]:=l;
- end;
- if x=1 then
- begin
- for i:=m-1 to m+l do
- for j:=k-1 to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(cBoard[i,j]<>1)and(cBoard[i,j]<>2)and(cBoard[i,j]<>3)and(cBoard[i,j]<>4) then
- cBoard[i,j]:=5;
- for i:=m to m+l-1 do
- cBoard[i,k]:=l;
- end;
- if x=2 then
- begin
- for i:=m-1 to m+1 do
- for j:=k-l to k+1 do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(cBoard[i,j]<>1)and(cBoard[i,j]<>2)and(cBoard[i,j]<>3)and(cBoard[i,j]<>4) then
- cBoard[i,j]:=5;
- for j:=k-l+1 to k do
- cBoard[m,j]:=l;
- end;
- if x=3 then
- begin
- for i:=m-1 to m+1 do
- for j:=k-1 to k+l do
- if (i>=0)and(i<=9)and(j>=0)and(j<=9)and(cBoard[i,j]<>1)and(cBoard[i,j]<>2)and(cBoard[i,j]<>3)and(cBoard[i,j]<>4) then
- cBoard[i,j]:=5;
- for j:=k to k+l-1 do
- cBoard[m,j]:=l;
- end;
- end;
- procedure cGenerateRandom;
- var
- x,l,m,k,i,j:integer;
- begin
- for l:=4 downto 1 do
- begin
- j:=4-l+1;
- for i:=1 to j do
- begin
- repeat
- randomize;
- m:=random(9);
- k:=random(9);
- until CCheckForShip(m,k,0,l) OR CCheckForShip(m,k,1,l) OR CCheckForShip(m,k,2,l) OR CCheckForShip(m,k,3,l);
- repeat
- x:=random(3);
- until CCheckForShip(m,k,x,l);
- CSetShip(m,k,x,l);
- end;
- end;
- end;
- procedure TForm1.CDButton1Click(Sender: TObject);
- begin
- cGenerateRandom;
- pGenerateRandom;
- end;
- procedure TForm1.CDButton2Click(Sender: TObject);
- var i,j:integer;
- begin
- pTurn.Brush.color:=clGreen;
- cTurn.Brush.color:=clRed;
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin
- cBoard[i,j]:=0;
- cMat[i,j].brush.color:=clWhite;
- cMat[i,j].enabled:=true;
- end;
- for i:=0 to 9 do
- for j:=0 to 9 do
- begin
- PBoard[i,j]:=0;
- PMat[i,j].brush.color:=clwhite;
- end;
- for i:=1 to 4 do
- begin
- cships[i]:=4-i+1;
- pships[i]:=4-i+1
- end;
- prethodni:=0;
- uzast:=0;
- mode:=1;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement