Advertisement
g0ku

Untitled

Feb 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.38 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9. StdCtrls, CustomDrawnControls,customdrawn_common, MaskEdit;
  10.  
  11. type
  12.  
  13. { TForm1 }
  14.  
  15. TForm1 = class(TForm)
  16. CDButton1: TCDButton;
  17. CDButton2: TCDButton;
  18. CDButton3: TCDButton;
  19. Label1: TLabel;
  20. cTurn: TShape;
  21. pTurn: TShape;
  22. procedure CDButton1Click(Sender: TObject);
  23. procedure CDButton2Click(Sender: TObject);
  24. procedure FormCreate(Sender: TObject);
  25. procedure pShapeMouseDown(Sender: TObject; Button: TMouseButton;
  26. Shift: TShiftState; X, Y: Integer);
  27. function pOdigraj(p,q:integer):boolean;
  28. function desno(x,y,tip:integer):integer;
  29. function levo(x,y,tip:integer):integer;
  30. function gore(x,y,tip:integer):integer;
  31. function dole(x,y,tip:integer):integer;
  32. function adesno(x,y:integer):integer;
  33. function alevo(x,y:integer):integer;
  34. function agore(x,y:integer):integer;
  35. function adole(x,y:integer):integer;
  36. function isPotopljen(x,y,tip:integer):boolean;
  37. procedure boji(x,y,tip:integer);
  38. procedure zameni(var a,b:integer; max:integer);
  39. procedure cOdigraj;
  40. function Racunaj(x,y,max:integer):integer ;
  41. procedure kraj;
  42.  
  43. private
  44. { private declarations }
  45. public
  46.  
  47. end;
  48.  
  49. var
  50. Form1: TForm1;
  51. pBoard,pShots,cBoard,cShots: array[0..9,0..9] of integer;
  52.  
  53. PMat,CMat:array[0..9,0..9] of TShape;
  54. mode:integer;
  55. prob:array[0..9,0..9] of integer;
  56. maxprob:array[0..100]of integer;
  57. prethodni:integer;
  58. pships,cships:array[1..4]of integer;
  59. uzast,smer,ort:integer; {ort=0 horizontalno smer=-1 levo smer=1 desno
  60. ort=1 vertikalno smer=-1 gore smer=1 dole}
  61.  
  62. implementation
  63.  
  64. {$R *.lfm}
  65.  
  66. { TForm1 }
  67.  
  68. procedure TForm1.FormCreate(Sender: TObject); {Pravi matricu shapeova i podesava pocetne vrednosti}
  69. var i,j:integer;
  70. begin
  71. for i:=0 to 9 do
  72. for j:=0 to 9 do
  73. begin pMat[i,j]:= TShape.Create(Form1);
  74. with pMat[i,j] do
  75. begin
  76. width:=30;
  77. height:=30;
  78. left:=j*30+30;
  79. top:=i*30+30;
  80. visible:=true;
  81. parent:=Form1;
  82. shape:=stRectangle;
  83. name:='shapeA'+ IntToStr(i)+Inttostr(j);
  84. brush.color:=clwhite;
  85. brush.style:=bsSolid;
  86. pen.color:=clblack;
  87. pen.style:=psSolid;
  88. pen.width:=1;
  89. enabled:=true;
  90.  
  91.  
  92. end;
  93. end;
  94. for i:=0 to 9 do
  95. for j:=0 to 9 do
  96. begin cMat[i,j]:= TShape.Create(Form1);
  97. with cMat[i,j] do
  98. begin
  99. width:=30;
  100. height:=30;
  101. left:=j*30+420;
  102. top:=i*30+30;
  103. visible:=true;
  104. parent:=Form1;
  105. shape:=stRectangle;
  106. name:='shapeB'+ IntToStr(i)+Inttostr(j);
  107. brush.color:=clwhite;
  108. brush.style:=bsSolid;
  109. pen.color:=clblack;
  110. pen.style:=psSolid;
  111. pen.width:=1;
  112. enabled:=true;
  113. OnMouseDown:=@Form1.pShapeMouseDown;
  114.  
  115.  
  116. end;
  117.  
  118. end;
  119.  
  120.  
  121. end;
  122. procedure TForm1.kraj;
  123. var i,j:integer;
  124. begin
  125. if pTurn.Brush.color=clRed then
  126. Showmessage('DEFEAT')
  127. else
  128. Showmessage('VICTORY');
  129.  
  130. pTurn.Brush.color:=clGreen;
  131. cTurn.Brush.color:=clRed;
  132. for i:=0 to 9 do
  133. for j:=0 to 9 do
  134. begin
  135. cBoard[i,j]:=0;
  136. cMat[i,j].brush.color:=clWhite;
  137. cMat[i,j].enabled:=true;
  138. end;
  139. for i:=0 to 9 do
  140. for j:=0 to 9 do
  141. begin
  142. PBoard[i,j]:=0;
  143. PMat[i,j].brush.color:=clwhite;
  144. end;
  145. for i:=1 to 4 do
  146. begin
  147. cships[i]:=4-i+1;
  148. pships[i]:=4-i+1
  149. end;
  150. prethodni:=0;
  151. uzast:=0;
  152. mode:=1;
  153.  
  154. end;
  155.  
  156. function TForm1.desno(x,y,tip:integer):integer;
  157. var br:integer;
  158. begin
  159. br:=0;
  160. if tip=1 then
  161. begin
  162. if x+1<=9 then
  163. begin
  164. if pShots[x,y]=1 then
  165. br:=1+desno(x+1,y,1)
  166. else br:=0;
  167. end
  168. else br:=0;
  169. end;
  170.  
  171. if tip=2 then
  172. begin
  173. if x+1<=9 then
  174. begin
  175. if cShots[x,y]=1 then
  176. br:=1+desno(x+1,y,2)
  177. else br:=0;
  178. end
  179. else br:=0;
  180. end;
  181. desno:=br;
  182. end;
  183. function TForm1.levo(x,y,tip:integer):integer;
  184. var br:integer;
  185. begin
  186. br:=0;
  187. if tip=1 then
  188. begin
  189. if x-1>=0 then
  190. begin
  191. if pShots[x,y]=1 then
  192. br:=1+levo(x-1,y,1)
  193. else br:=0;
  194. end
  195. else br:=0;
  196. end;
  197.  
  198. if tip=2 then
  199. begin
  200. if x-1>=0 then
  201. begin
  202. if cShots[x,y]=1 then
  203. br:=1+levo(x-1,y,2)
  204. else br:=0;
  205. end
  206. else br:=0;
  207. end;
  208. levo:=br;
  209. end;
  210. function TForm1.gore(x,y,tip:integer):integer;
  211. var br:integer;
  212. begin
  213. br:=0;
  214. if tip=1 then
  215. begin
  216. if y-1>=0 then
  217. begin
  218. if pShots[x,y]=1 then
  219. br:=1+gore(x,y-1,1)
  220. else br:=0;
  221. end
  222. else br:=0;
  223. end;
  224.  
  225. if tip=2 then
  226. begin
  227. if y-1>=0 then
  228. begin
  229. if cShots[x,y]=1 then
  230. br:=1+gore(x,y-1,2)
  231. else br:=0;
  232. end
  233. else br:=0;
  234. end;
  235. gore:=br;
  236. end;
  237. function TForm1.dole(x,y,tip:integer):integer;
  238. var br:integer;
  239. begin
  240. br:=0;
  241. if tip=1 then
  242. begin
  243. if y+1<=9 then
  244. begin
  245. if pShots[x,y]=1 then
  246. br:=1+dole(x,y+1,1)
  247. else br:=0;
  248. end
  249. else br:=0;
  250. end;
  251.  
  252. if tip=2 then
  253. begin
  254. if y+1<=9 then
  255. begin
  256. if cShots[x,y]=1 then
  257. br:=1+dole(x,y+1,2)
  258. else br:=0;
  259. end
  260. else br:=0;
  261. end;
  262. dole:=br;
  263. end;
  264. function TForm1.isPotopljen(x,y,tip:integer):boolean;
  265. begin
  266. if tip=1 then
  267. begin
  268. 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
  269. begin
  270. isPotopljen:=true;
  271. cships[cBoard[x,y]]:=cships[cBoard[x,y]]-1;
  272. end
  273. else isPotopljen:=false;
  274. end;
  275.  
  276. if tip=2 then
  277. begin
  278. 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
  279. begin
  280. isPotopljen:=true;
  281. pships[pBoard[x,y]]:=pships[pBoard[x,y]]-1;
  282. end
  283. else isPotopljen:=false;
  284. end;
  285.  
  286. end;
  287. procedure TForm1.boji(x,y,tip:integer);
  288. var l,i,k:integer;
  289. begin
  290. if tip=1 then
  291. begin
  292. l:=cBoard[x,y];
  293. if l=1 then
  294. begin
  295. cMat[x,y].Brush.color:=clRed;
  296. if x-1>=0 then
  297. cMat[x-1,y].brush.color:=clGray;
  298. if x+1<=9 then
  299. cMat[x+l,y].brush.color:=clGray;
  300. if y-1>=0 then
  301. cMat[x,y-1].brush.color:=clGray;
  302. if y+1<=9 then
  303. cMat[x,y+1].brush.color:=clGray;
  304. end;
  305. 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
  306. begin
  307. k:=x-levo(x,y,1)+1;
  308. if k-1>=0 then
  309. cMat[k-1,y].brush.color:=clGray;
  310. if k+l<=9 then
  311. cMat[k+l,y].brush.color:=clGray;
  312. for i:=0 to l-1 do
  313. cMat[k+i,y].brush.color:=clRed;
  314. end;
  315. 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
  316. begin
  317. k:=y-gore(x,y,1)+1;
  318. if k-1>=0 then
  319. cMat[x,k-1].brush.color:=clGray;
  320. if k+l<=9 then
  321. cMat[x,k+l].brush.color:=clGray;
  322. for i:=0 to l-1 do
  323. cMat[x,k+i].brush.color:=clRed;
  324. end;
  325. end;
  326.  
  327. if tip=2 then
  328. begin
  329. l:=pBoard[x,y];
  330. if l=1 then
  331. begin
  332. pMat[x,y].Brush.color:=clRed;
  333. if x-1>=0 then
  334. pMat[x-1,y].brush.color:=clGray;
  335. if x+1<=9 then
  336. pMat[x+l,y].brush.color:=clGray;
  337. if y-1>=0 then
  338. pMat[x,y-1].brush.color:=clGray;
  339. if y+1<=9 then
  340. pMat[x,y+1].brush.color:=clGray;
  341. end;
  342. 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
  343. begin
  344. k:=x-levo(x,y,2)+1;
  345. if k-1>=0 then
  346. pMat[k-1,y].brush.color:=clGray;
  347. if k+l<=9 then
  348. pMat[k+l,y].brush.color:=clGray;
  349. for i:=0 to l-1 do
  350. pMat[k+i,y].brush.color:=clRed;
  351. end;
  352. 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
  353. begin
  354. k:=y-gore(x,y,1)+1;
  355. if k-1>=0 then
  356. pMat[x,k-1].brush.color:=clGray;
  357. if k+l<=9 then
  358. pMat[x,k+l].brush.color:=clGray;
  359. for i:=0 to l-1 do
  360. pMat[x,k+i].brush.color:=clRed;
  361. end;
  362. end;
  363. end;
  364. function TForm1.agore(x,y:integer):integer;
  365. var br:integer;
  366. begin
  367. br:=0;
  368.  
  369. if y-1>=0 then
  370. begin
  371. if cShots[x,y-1]=0 then
  372. br:=1+agore(x,y-1)
  373. else br:=0;
  374. end
  375. else br:=0;
  376. if br>3 then
  377. agore:=3
  378. else agore:=br;
  379. end;
  380.  
  381. function TForm1.adole(x,y:integer):integer;
  382. var br:integer;
  383. begin
  384. br:=0;
  385.  
  386. if y+1<=9 then
  387. begin
  388. if cShots[x,y+1]=0 then
  389. br:=1+adole(x,y+1)
  390. else br:=0;
  391. end
  392. else br:=0;
  393. if br>3 then
  394. adole:=3
  395. else adole:=br;
  396. end;
  397.  
  398. function TForm1.alevo(x,y:integer):integer;
  399. var br:integer;
  400. begin
  401. br:=0;
  402.  
  403. if x-1>=0 then
  404. begin
  405. if cShots[x-1,y]=0 then
  406. br:=1+alevo(x,y-1)
  407. else br:=0;
  408. end
  409. else br:=0;
  410. if br>3 then
  411. alevo:=3
  412. else alevo:=br;
  413. end;
  414.  
  415. function TForm1.adesno(x,y:integer):integer;
  416. var br:integer;
  417. begin
  418. br:=0;
  419.  
  420. if x+1<=9 then
  421. begin
  422. if cShots[x+1,y]=0 then
  423. br:=1+adesno(x+1,y)
  424. else br:=0;
  425. end
  426. else br:=0;
  427. if br>3 then
  428. adesno:=3
  429. else adesno:=br;
  430. end;
  431. procedure TForm1.zameni(var a,b:integer; max:integer);
  432. var pom:integer;
  433. begin
  434. if b>a then
  435. begin
  436. pom:=b;
  437. b:=a;
  438. a:=pom;
  439. end;
  440. if a>max-1 then
  441. a:=max-1;
  442. if b>max-1 then
  443. b:=max-1;
  444.  
  445. end;
  446.  
  447.  
  448. function TForm1.Racunaj(x,y,max:integer):integer;
  449. var a,b,h,v,pom:integer;
  450. begin
  451. if max=1 then
  452. racunaj:=1;
  453.  
  454. if max=2 then
  455. begin
  456. a:=alevo(x,y);
  457. b:=adesno(x,y);
  458. zameni(a,b,max);
  459. if a=1 then
  460. begin
  461. if b=1 then
  462. h:=2;
  463. if b=0 then
  464. h:=1;
  465. end
  466. else h:=0;
  467.  
  468. a:=agore(x,y);
  469. b:=adole(x,y);
  470. zameni(a,b,max);
  471. if a=1 then
  472. begin
  473. if b=1 then
  474. v:=2;
  475. if b=0 then
  476. v:=1;
  477. end
  478. else v:=0;
  479. racunaj:=h+v;
  480. end;
  481.  
  482. if max=3 then
  483. begin
  484. a:=alevo(x,y);
  485. b:=adesno(x,y);
  486. zameni(a,b,max);
  487. if a=1 then
  488. begin
  489. if b=1 then
  490. h:=1;
  491. if b=0 then
  492. h:=0;
  493. end;
  494.  
  495. if a=2 then
  496. begin
  497. if b=2 then
  498. h:=3;
  499. if b=1 then
  500. h:=2;
  501. if b=0 then
  502. h:=1;
  503. end;
  504.  
  505. if a=0 then
  506. h:=0;
  507.  
  508. a:=agore(x,y);
  509. b:=adole(x,y);
  510. zameni(a,b,max);
  511. if a=1 then
  512. begin
  513. if b=1 then
  514. v:=1;
  515. if b=0 then
  516. v:=0;
  517. end;
  518.  
  519. if a=2 then
  520. begin
  521. if b=2 then
  522. v:=3;
  523. if b=1 then
  524. v:=2;
  525. if b=0 then
  526. v:=1;
  527. end;
  528.  
  529. if a=0 then
  530. v:=0;
  531.  
  532. racunaj:=h+v;
  533. end;
  534.  
  535. if max=4 then
  536. begin
  537. a:=alevo(x,y);
  538. b:=adesno(x,y);
  539. zameni(a,b,max);
  540. if a=1 then
  541. h:=0;
  542.  
  543. if a=2 then
  544. begin
  545. if b=2 then
  546. h:=2;
  547. if b=1 then
  548. h:=1;
  549. if b=0 then
  550. h:=0;
  551. end;
  552.  
  553. if a=3 then
  554. begin
  555. if b=3 then
  556. h:=4;
  557. if b=2 then
  558. h:=3;
  559. if b=1 then
  560. h:=2;
  561. if b=0 then
  562. h:=1;
  563. end;
  564.  
  565. if a=0 then
  566. h:=0;
  567.  
  568. a:=agore(x,y);
  569. b:=adole(x,y);
  570. zameni(a,b,max);
  571. if a=1 then
  572. v:=0;
  573.  
  574. if a=2 then
  575. begin
  576. if b=2 then
  577. v:=2;
  578. if b=1 then
  579. v:=1;
  580. if b=0 then
  581. v:=0;
  582. end;
  583.  
  584. if a=3 then
  585. begin
  586. if b=3 then
  587. v:=4;
  588. if b=2 then
  589. v:=3;
  590. if b=1 then
  591. v:=2;
  592. if b=0 then
  593. v:=1;
  594. end;
  595.  
  596. if a=0 then
  597. v:=0;
  598. racunaj:=h+v;
  599. end;
  600.  
  601. end;
  602.  
  603. procedure TForm1.cOdigraj;
  604. var
  605. 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}
  606. begin
  607. if mode=1 then
  608. begin
  609. for i:=1 to 4 do
  610. if pships[i]<>0 then
  611. max:=i;
  612. for i:=0 to 9 do
  613. for j:=0 to 9 do
  614. prob[i,j]:=Racunaj(i,j,max);
  615.  
  616. maks:=0;
  617. for i:=0 to 9 do
  618. for j:=0 to 9 do
  619. if prob[i,j]>maks then
  620. maks:=prob[i,j];
  621. br:=0;
  622. for i:=0 to 9 do
  623. for j:=0 to 9 do
  624. if prob[i,j]=maks then
  625. begin
  626. maxprob[br]:=i*10+j;
  627. br:=br+1;
  628. end;
  629. k:=random(br);
  630. k:=maxprob[k];
  631. m1:=k div 10;
  632. m2:=k mod 10;
  633.  
  634.  
  635.  
  636. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  637. begin
  638. cShots[m1,m2]:=1;
  639. pMat[m1,m2].Brush.Color:=clYellow;
  640.  
  641. if m1-1>=0 then
  642. begin
  643. if m2-1>=0 then
  644. begin
  645. pMat[m1-1,m2-1].Brush.Color:=clGray;
  646.  
  647. cShots[m1-1,m2-1]:=2;
  648. end;
  649. if m2+1<=9 then
  650. begin
  651. pMat[m1-1,m2+1].Brush.Color:=clGray;
  652.  
  653. cShots[m1-1,m2+1]:=2;
  654. end;
  655. end;
  656. if m1+1<=9 then
  657. begin
  658. if m2-1>=0 then
  659. begin
  660. pMat[m1+1,m2-1].Brush.Color:=clGray;
  661.  
  662. cShots[m1+1,m2-1]:=2;
  663. end;
  664. if m2+1<=9 then
  665. begin
  666. pMat[m1+1,m2+1].Brush.Color:=clGray;
  667.  
  668. cShots[m1+1,m2+1]:=2;
  669. end;
  670. end;
  671. if isPotopljen(m1,m2,2) then
  672. begin
  673. boji(m1,m2,2);
  674. pships[1]:=pships[1]-1;
  675. br:=0;
  676. uzast:=0;
  677. for i:=1 to 4 do
  678. br:=br+pships[i];
  679. if br=0 then
  680. kraj
  681. else
  682. begin
  683.  
  684. cOdigraj;
  685.  
  686.  
  687. end;
  688.  
  689. end
  690. else
  691. begin
  692. prethodni:=k;
  693. uzast:=1;
  694. mode:=2;
  695. cOdigraj;
  696. end;
  697.  
  698. end
  699. else
  700. begin
  701. cShots[m1,m2]:=2;
  702. pMat[m1,m2].brush.color:=clGray;
  703. pTurn.Brush.color:=clGreen;
  704. cTurn.Brush.color:=clRed;
  705.  
  706. end;
  707. end;
  708.  
  709. if mode=2 then
  710. begin
  711. if uzast=1 then {DRUGO GADJANJE}
  712. begin
  713. a:=prethodni div 10;
  714. b:=prethodni mod 10;
  715.  
  716. if (adesno(a,b)+alevo(a,b))>=(agore(a,b)+adole(a,b)) then {KEKEKEK}
  717. begin
  718. if alevo(a,b)>=adesno(a,b) then
  719. begin
  720. m1:=a-1;
  721. m2:=b;
  722. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  723. begin
  724. cShots[m1,m2]:=1;
  725. pMat[m1,m2].Brush.Color:=clYellow;
  726.  
  727. if m1-1>=0 then
  728. begin
  729. if m2-1>=0 then
  730. begin
  731. pMat[m1-1,m2-1].Brush.Color:=clGray;
  732.  
  733. cShots[m1-1,m2-1]:=2;
  734. end;
  735. if m2+1<=9 then
  736. begin
  737. pMat[m1-1,m2+1].Brush.Color:=clGray;
  738.  
  739. cShots[m1-1,m2+1]:=2;
  740. end;
  741. end;
  742. if m1+1<=9 then
  743. begin
  744. if m2-1>=0 then
  745. begin
  746. pMat[m1+1,m2-1].Brush.Color:=clGray;
  747.  
  748. cShots[m1+1,m2-1]:=2;
  749. end;
  750. if m2+1<=9 then
  751. begin
  752. pMat[m1+1,m2+1].Brush.Color:=clGray;
  753.  
  754. cShots[m1+1,m2+1]:=2;
  755. end;
  756. end;
  757. if isPotopljen(m1,m2,2) then
  758. begin
  759. boji(m1,m2,2);
  760. pships[2]:=pships[2]-1;
  761. br:=0;
  762. mode:=1;
  763. uzast:=0;
  764. for i:=1 to 4 do
  765. br:=br+pships[i];
  766. if br=0 then
  767. kraj
  768. else
  769.  
  770. cOdigraj;
  771.  
  772. end
  773. else
  774. begin
  775. uzast:=2;
  776. ort:=0;
  777. smer:=-1;
  778. prethodni:=m1*10+m2;
  779. cOdigraj;
  780. end;
  781. end
  782. else
  783. begin
  784. cShots[m1,m2]:=2;
  785. pMat[m1,m2].brush.color:=clGray;
  786. pTurn.Brush.color:=clGreen;
  787. cTurn.Brush.color:=clRed;
  788. end;
  789. end
  790. else
  791. begin
  792. m1:=a+1;
  793. m2:=b;
  794. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  795. begin
  796. cShots[m1,m2]:=1;
  797. pMat[m1,m2].Brush.Color:=clYellow;
  798.  
  799. if m1-1>=0 then
  800. begin
  801. if m2-1>=0 then
  802. begin
  803. pMat[m1-1,m2-1].Brush.Color:=clGray;
  804.  
  805. cShots[m1-1,m2-1]:=2;
  806. end;
  807. if m2+1<=9 then
  808. begin
  809. pMat[m1-1,m2+1].Brush.Color:=clGray;
  810.  
  811. cShots[m1-1,m2+1]:=2;
  812. end;
  813. end;
  814. if m1+1<=9 then
  815. begin
  816. if m2-1>=0 then
  817. begin
  818. pMat[m1+1,m2-1].Brush.Color:=clGray;
  819.  
  820. cShots[m1+1,m2-1]:=2;
  821. end;
  822. if m2+1<=9 then
  823. begin
  824. pMat[m1+1,m2+1].Brush.Color:=clGray;
  825.  
  826. cShots[m1+1,m2+1]:=2;
  827. end;
  828. end;
  829. if isPotopljen(m1,m2,2) then
  830. begin
  831. boji(m1,m2,2);
  832. pships[2]:=pships[2]-1;
  833. br:=0;
  834. mode:=1;
  835. uzast:=0;
  836. for i:=1 to 4 do
  837. br:=br+pships[i];
  838. if br=0 then
  839. kraj
  840. else
  841. cOdigraj;
  842. end
  843. else
  844. begin
  845. uzast:=2;
  846. ort:=0;
  847. smer:=1;
  848. prethodni:=m1*10+m2;
  849. cOdigraj;
  850. end;
  851. end
  852. else
  853. begin
  854. cShots[m1,m2]:=2;
  855. pMat[m1,m2].brush.color:=clGray;
  856. pTurn.Brush.color:=clGreen;
  857. cTurn.Brush.color:=clRed;
  858. end;
  859. end;
  860. end
  861. else begin
  862. if agore(a,b)>=adole(a,b) then
  863. begin
  864. m1:=a;
  865. m2:=b-1;
  866. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  867. begin
  868. cShots[m1,m2]:=1;
  869. pMat[m1,m2].Brush.Color:=clYellow;
  870.  
  871. if m1-1>=0 then
  872. begin
  873. if m2-1>=0 then
  874. begin
  875. pMat[m1-1,m2-1].Brush.Color:=clGray;
  876.  
  877. cShots[m1-1,m2-1]:=2;
  878. end;
  879. if m2+1<=9 then
  880. begin
  881. pMat[m1-1,m2+1].Brush.Color:=clGray;
  882.  
  883. cShots[m1-1,m2+1]:=2;
  884. end;
  885. end;
  886. if m1+1<=9 then
  887. begin
  888. if m2-1>=0 then
  889. begin
  890. pMat[m1+1,m2-1].Brush.Color:=clGray;
  891.  
  892. cShots[m1+1,m2-1]:=2;
  893. end;
  894. if m2+1<=9 then
  895. begin
  896. pMat[m1+1,m2+1].Brush.Color:=clGray;
  897.  
  898. cShots[m1+1,m2+1]:=2;
  899. end;
  900. end;
  901. if isPotopljen(m1,m2,2) then
  902. begin
  903. boji(m1,m2,2);
  904. br:=0;
  905. mode:=1;
  906. uzast:=0;
  907. for i:=1 to 4 do
  908. br:=br+pships[i];
  909. if br=0 then
  910. kraj
  911. else
  912. cOdigraj;
  913. end
  914. else
  915. begin
  916. uzast:=2;
  917. ort:=1;
  918. smer:=-1;
  919. prethodni:=m1*10+m2;
  920. cOdigraj;
  921. end;
  922. end
  923. else
  924. begin
  925. cShots[m1,m2]:=2;
  926. pMat[m1,m2].brush.color:=clGray;
  927. pTurn.Brush.color:=clGreen;
  928. cTurn.Brush.color:=clRed;
  929. end;
  930. end
  931. else
  932. begin
  933. m1:=a;
  934. m2:=b+1;
  935. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  936. begin
  937. cShots[m1,m2]:=1;
  938. pMat[m1,m2].Brush.Color:=clYellow;
  939.  
  940. if m1-1>=0 then
  941. begin
  942. if m2-1>=0 then
  943. begin
  944. pMat[m1-1,m2-1].Brush.Color:=clGray;
  945.  
  946. cShots[m1-1,m2-1]:=2;
  947. end;
  948. if m2+1<=9 then
  949. begin
  950. pMat[m1-1,m2+1].Brush.Color:=clGray;
  951.  
  952. cShots[m1-1,m2+1]:=2;
  953. end;
  954. end;
  955. if m1+1<=9 then
  956. begin
  957. if m2-1>=0 then
  958. begin
  959. pMat[m1+1,m2-1].Brush.Color:=clGray;
  960.  
  961. cShots[m1+1,m2-1]:=2;
  962. end;
  963. if m2+1<=9 then
  964. begin
  965. pMat[m1+1,m2+1].Brush.Color:=clGray;
  966.  
  967. cShots[m1+1,m2+1]:=2;
  968. end;
  969. end;
  970. if isPotopljen(m1,m2,2) then
  971. begin
  972. boji(m1,m2,2);
  973. pships[2]:=pships[2]-1;
  974. br:=0;
  975. mode:=1;
  976. uzast:=0;
  977. for i:=1 to 4 do
  978. br:=br+pships[i];
  979. if br=0 then
  980. kraj
  981. else
  982. cOdigraj;
  983. end
  984. else
  985. begin
  986. uzast:=2;
  987. ort:=1;
  988. smer:=1;
  989. prethodni:=m1*10+m2;
  990. cOdigraj;
  991. end;
  992. end
  993. else
  994. begin
  995. cShots[m1,m2]:=2;
  996. pMat[m1,m2].brush.color:=clGray;
  997. pTurn.Brush.color:=clGreen;
  998. cTurn.Brush.color:=clRed;
  999. end;
  1000. end;
  1001. end;
  1002.  
  1003. end;
  1004.  
  1005. if uzast=2 then {TRECE GADJANJE}
  1006. begin
  1007. a:=prethodni div 10;
  1008. b:=prethodni mod 10;
  1009. if ort=0 then {HORIZONTALNO}
  1010. begin
  1011. if smer=-1 then
  1012. begin
  1013. if alevo(a,b)<>0 then
  1014. begin
  1015. m1:=a-1;
  1016. m2:=b;
  1017.  
  1018. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1019. begin
  1020. cShots[m1,m2]:=1;
  1021. pMat[m1,m2].Brush.Color:=clYellow;
  1022.  
  1023. if m1-1>=0 then
  1024. begin
  1025. if m2-1>=0 then
  1026. begin
  1027. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1028.  
  1029. cShots[m1-1,m2-1]:=2;
  1030. end;
  1031. if m2+1<=9 then
  1032. begin
  1033. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1034.  
  1035. cShots[m1-1,m2+1]:=2;
  1036. end;
  1037. end;
  1038. if m1+1<=9 then
  1039. begin
  1040. if m2-1>=0 then
  1041. begin
  1042. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1043.  
  1044. cShots[m1+1,m2-1]:=2;
  1045. end;
  1046. if m2+1<=9 then
  1047. begin
  1048. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1049.  
  1050. cShots[m1+1,m2+1]:=2;
  1051. end;
  1052. end;
  1053. if isPotopljen(m1,m2,2) then
  1054. begin
  1055. boji(m1,m2,2);
  1056. pships[3]:=pships[3]-1;
  1057. br:=0;
  1058. mode:=1;
  1059. uzast:=0;
  1060. for i:=1 to 4 do
  1061. br:=br+pships[i];
  1062. if br=0 then
  1063. kraj
  1064. else
  1065. cOdigraj;
  1066. end
  1067. else
  1068. begin
  1069. uzast:=3;
  1070. smer:=-1;
  1071. prethodni:=m1*10+m2;
  1072. cOdigraj;
  1073. end;
  1074. end
  1075. else
  1076. begin
  1077. smer:=1;
  1078. prethodni:=(a+1)*10+b;
  1079. cShots[m1,m2]:=2;
  1080. pMat[m1,m2].brush.color:=clGray;
  1081. pTurn.Brush.color:=clGreen;
  1082. cTurn.Brush.color:=clRed;
  1083.  
  1084. end;
  1085. end
  1086. else
  1087.  
  1088.  
  1089.  
  1090. begin
  1091. m1:=a+2;
  1092. m2:=b;
  1093. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1094. begin
  1095. cShots[m1,m2]:=1;
  1096. pMat[m1,m2].Brush.Color:=clYellow;
  1097.  
  1098. if m1-1>=0 then
  1099. begin
  1100. if m2-1>=0 then
  1101. begin
  1102. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1103.  
  1104. cShots[m1-1,m2-1]:=2;
  1105. end;
  1106. if m2+1<=9 then
  1107. begin
  1108. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1109.  
  1110. cShots[m1-1,m2+1]:=2;
  1111. end;
  1112. end;
  1113. if m1+1<=9 then
  1114. begin
  1115. if m2-1>=0 then
  1116. begin
  1117. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1118.  
  1119. cShots[m1+1,m2-1]:=2;
  1120. end;
  1121. if m2+1<=9 then
  1122. begin
  1123. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1124.  
  1125. cShots[m1+1,m2+1]:=2;
  1126. end;
  1127. end;
  1128. if isPotopljen(m1,m2,2) then
  1129. begin
  1130. boji(m1,m2,2);
  1131. pships[3]:=pships[3]-1;
  1132. br:=0;
  1133. mode:=1;
  1134. uzast:=0;
  1135. for i:=1 to 4 do
  1136. br:=br+pships[i];
  1137. if br=0 then
  1138. kraj
  1139. else
  1140. cOdigraj;
  1141. end
  1142. else
  1143. begin
  1144. uzast:=3;
  1145. smer:=1;
  1146. prethodni:=m1*10+m2;
  1147. cOdigraj;
  1148. end;
  1149. end
  1150.  
  1151.  
  1152. end;
  1153. end
  1154. else
  1155. begin
  1156.  
  1157. if adesno(a,b)<>0 then
  1158. begin
  1159. m1:=a+1;
  1160. m2:=b;
  1161.  
  1162. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1163. begin
  1164. cShots[m1,m2]:=1;
  1165. pMat[m1,m2].Brush.Color:=clYellow;
  1166.  
  1167. if m1-1>=0 then
  1168. begin
  1169. if m2-1>=0 then
  1170. begin
  1171. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1172.  
  1173. cShots[m1-1,m2-1]:=2;
  1174. end;
  1175. if m2+1<=9 then
  1176. begin
  1177. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1178.  
  1179. cShots[m1-1,m2+1]:=2;
  1180. end;
  1181. end;
  1182. if m1+1<=9 then
  1183. begin
  1184. if m2-1>=0 then
  1185. begin
  1186. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1187.  
  1188. cShots[m1+1,m2-1]:=2;
  1189. end;
  1190. if m2+1<=9 then
  1191. begin
  1192. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1193.  
  1194. cShots[m1+1,m2+1]:=2;
  1195. end;
  1196. end;
  1197. if isPotopljen(m1,m2,2) then
  1198. begin
  1199. boji(m1,m2,2);
  1200. pships[3]:=pships[3]-1;
  1201. br:=0;
  1202. mode:=1;
  1203. uzast:=0;
  1204. for i:=1 to 4 do
  1205. br:=br+pships[i];
  1206. if br=0 then
  1207. kraj
  1208. else
  1209. cOdigraj;
  1210. end
  1211. else
  1212. begin
  1213. uzast:=3;
  1214. smer:=1;
  1215. prethodni:=m1*10+m2;
  1216. cOdigraj;
  1217. end;
  1218. end
  1219. else
  1220. begin
  1221. smer:=-1;
  1222. prethodni:=(a-1)*10+b;
  1223. cShots[m1,m2]:=2;
  1224. pMat[m1,m2].brush.color:=clGray;
  1225. pTurn.Brush.color:=clGreen;
  1226. cTurn.Brush.color:=clRed;
  1227.  
  1228. end;
  1229. end
  1230. else
  1231.  
  1232.  
  1233.  
  1234. begin
  1235. m1:=a-2;
  1236. m2:=b;
  1237. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1238. begin
  1239. cShots[m1,m2]:=1;
  1240. pMat[m1,m2].Brush.Color:=clYellow;
  1241.  
  1242. if m1-1>=0 then
  1243. begin
  1244. if m2-1>=0 then
  1245. begin
  1246. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1247.  
  1248. cShots[m1-1,m2-1]:=2;
  1249. end;
  1250. if m2+1<=9 then
  1251. begin
  1252. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1253.  
  1254. cShots[m1-1,m2+1]:=2;
  1255. end;
  1256. end;
  1257. if m1+1<=9 then
  1258. begin
  1259. if m2-1>=0 then
  1260. begin
  1261. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1262.  
  1263. cShots[m1+1,m2-1]:=2;
  1264. end;
  1265. if m2+1<=9 then
  1266. begin
  1267. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1268.  
  1269. cShots[m1+1,m2+1]:=2;
  1270. end;
  1271. end;
  1272. if isPotopljen(m1,m2,2) then
  1273. begin
  1274. boji(m1,m2,2);
  1275. pships[3]:=pships[3]-1;
  1276. br:=0;
  1277. mode:=1;
  1278. uzast:=0;
  1279. for i:=1 to 4 do
  1280. br:=br+pships[i];
  1281. if br=0 then
  1282. kraj
  1283. else
  1284. cOdigraj;
  1285. end
  1286. else
  1287. begin
  1288. uzast:=3;
  1289. smer:=-1;
  1290. prethodni:=m1*10+m2;
  1291. cOdigraj;
  1292. end;
  1293. end
  1294.  
  1295.  
  1296. end;
  1297.  
  1298. end;
  1299. end;
  1300.  
  1301. if ort=1 then {VERTIKALNO}
  1302. begin
  1303. if smer=-1 then
  1304. begin
  1305. if agore(a,b)<>0 then
  1306. begin
  1307. m1:=a;
  1308. m2:=b-1;
  1309.  
  1310. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1311. begin
  1312. cShots[m1,m2]:=1;
  1313. pMat[m1,m2].Brush.Color:=clYellow;
  1314.  
  1315. if m1-1>=0 then
  1316. begin
  1317. if m2-1>=0 then
  1318. begin
  1319. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1320.  
  1321. cShots[m1-1,m2-1]:=2;
  1322. end;
  1323. if m2+1<=9 then
  1324. begin
  1325. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1326.  
  1327. cShots[m1-1,m2+1]:=2;
  1328. end;
  1329. end;
  1330. if m1+1<=9 then
  1331. begin
  1332. if m2-1>=0 then
  1333. begin
  1334. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1335.  
  1336. cShots[m1+1,m2-1]:=2;
  1337. end;
  1338. if m2+1<=9 then
  1339. begin
  1340. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1341.  
  1342. cShots[m1+1,m2+1]:=2;
  1343. end;
  1344. end;
  1345. if isPotopljen(m1,m2,2) then
  1346. begin
  1347. boji(m1,m2,2);
  1348. pships[3]:=pships[3]-1;
  1349. br:=0;
  1350. mode:=1;
  1351. uzast:=0;
  1352. for i:=1 to 4 do
  1353. br:=br+pships[i];
  1354. if br=0 then
  1355. kraj
  1356. else
  1357. cOdigraj;
  1358. end
  1359. else
  1360. begin
  1361. uzast:=3;
  1362. smer:=-1;
  1363. prethodni:=m1*10+m2;
  1364. cOdigraj;
  1365. end;
  1366. end
  1367. else
  1368. begin
  1369. smer:=1;
  1370. prethodni:=a*10+b+1;
  1371. cShots[m1,m2]:=2;
  1372. pMat[m1,m2].brush.color:=clGray;
  1373. pTurn.Brush.color:=clGreen;
  1374. cTurn.Brush.color:=clRed;
  1375.  
  1376. end;
  1377. end
  1378. else
  1379.  
  1380.  
  1381.  
  1382. begin
  1383. m1:=a;
  1384. m2:=b+1;
  1385. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1386. begin
  1387. cShots[m1,m2]:=1;
  1388. pMat[m1,m2].Brush.Color:=clYellow;
  1389.  
  1390. if m1-1>=0 then
  1391. begin
  1392. if m2-1>=0 then
  1393. begin
  1394. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1395.  
  1396. cShots[m1-1,m2-1]:=2;
  1397. end;
  1398. if m2+1<=9 then
  1399. begin
  1400. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1401.  
  1402. cShots[m1-1,m2+1]:=2;
  1403. end;
  1404. end;
  1405. if m1+1<=9 then
  1406. begin
  1407. if m2-1>=0 then
  1408. begin
  1409. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1410.  
  1411. cShots[m1+1,m2-1]:=2;
  1412. end;
  1413. if m2+1<=9 then
  1414. begin
  1415. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1416.  
  1417. cShots[m1+1,m2+1]:=2;
  1418. end;
  1419. end;
  1420. if isPotopljen(m1,m2,2) then
  1421. begin
  1422. boji(m1,m2,2);
  1423. pships[3]:=pships[3]-1;
  1424. br:=0;
  1425. mode:=1;
  1426. uzast:=0;
  1427. for i:=1 to 4 do
  1428. br:=br+pships[i];
  1429. if br=0 then
  1430. kraj
  1431. else
  1432. cOdigraj;
  1433. end
  1434. else
  1435. begin
  1436. uzast:=3;
  1437. smer:=1;
  1438. prethodni:=m1*10+m2;
  1439. cOdigraj;
  1440. end;
  1441. end
  1442.  
  1443.  
  1444. end;
  1445. end
  1446. else
  1447. begin
  1448.  
  1449. if adole(a,b)<>0 then
  1450. begin
  1451. m1:=a;
  1452. m2:=b+1;
  1453.  
  1454. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1455. begin
  1456. cShots[m1,m2]:=1;
  1457. pMat[m1,m2].Brush.Color:=clYellow;
  1458.  
  1459. if m1-1>=0 then
  1460. begin
  1461. if m2-1>=0 then
  1462. begin
  1463. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1464.  
  1465. cShots[m1-1,m2-1]:=2;
  1466. end;
  1467. if m2+1<=9 then
  1468. begin
  1469. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1470.  
  1471. cShots[m1-1,m2+1]:=2;
  1472. end;
  1473. end;
  1474. if m1+1<=9 then
  1475. begin
  1476. if m2-1>=0 then
  1477. begin
  1478. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1479.  
  1480. cShots[m1+1,m2-1]:=2;
  1481. end;
  1482. if m2+1<=9 then
  1483. begin
  1484. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1485.  
  1486. cShots[m1+1,m2+1]:=2;
  1487. end;
  1488. end;
  1489. if isPotopljen(m1,m2,2) then
  1490. begin
  1491. boji(m1,m2,2);
  1492. pships[3]:=pships[3]-1;
  1493. br:=0;
  1494. mode:=1;
  1495. uzast:=0;
  1496. for i:=1 to 4 do
  1497. br:=br+pships[i];
  1498. if br=0 then
  1499. kraj
  1500. else
  1501. cOdigraj;
  1502. end
  1503. else
  1504. begin
  1505. uzast:=3;
  1506. smer:=1;
  1507. prethodni:=m1*10+m2;
  1508. cOdigraj;
  1509. end;
  1510. end
  1511. else
  1512. begin
  1513. smer:=-1;
  1514. prethodni:=a*10+b-1;
  1515. cShots[m1,m2]:=2;
  1516. pMat[m1,m2].brush.color:=clGray;
  1517. pTurn.Brush.color:=clGreen;
  1518. cTurn.Brush.color:=clRed;
  1519.  
  1520. end;
  1521. end
  1522. else
  1523.  
  1524.  
  1525.  
  1526. begin
  1527. m1:=a;
  1528. m2:=b-1;
  1529. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1530. begin
  1531. cShots[m1,m2]:=1;
  1532. pMat[m1,m2].Brush.Color:=clYellow;
  1533.  
  1534. if m1-1>=0 then
  1535. begin
  1536. if m2-1>=0 then
  1537. begin
  1538. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1539.  
  1540. cShots[m1-1,m2-1]:=2;
  1541. end;
  1542. if m2+1<=9 then
  1543. begin
  1544. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1545.  
  1546. cShots[m1-1,m2+1]:=2;
  1547. end;
  1548. end;
  1549. if m1+1<=9 then
  1550. begin
  1551. if m2-1>=0 then
  1552. begin
  1553. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1554.  
  1555. cShots[m1+1,m2-1]:=2;
  1556. end;
  1557. if m2+1<=9 then
  1558. begin
  1559. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1560.  
  1561. cShots[m1+1,m2+1]:=2;
  1562. end;
  1563. end;
  1564. if isPotopljen(m1,m2,2) then
  1565. begin
  1566. boji(m1,m2,2);
  1567. pships[3]:=pships[3]-1;
  1568. br:=0;
  1569. mode:=1;
  1570. uzast:=0;
  1571. for i:=1 to 4 do
  1572. br:=br+pships[i];
  1573. if br=0 then
  1574. kraj
  1575. else
  1576. cOdigraj;
  1577. end
  1578. else
  1579. begin
  1580. uzast:=3;
  1581. smer:=-1;
  1582. prethodni:=m1*10+m2;
  1583. cOdigraj;
  1584. end;
  1585. end
  1586.  
  1587.  
  1588. end;
  1589.  
  1590. end;
  1591. end;
  1592. end;
  1593.  
  1594. if uzast=3 then {CETVRTO GADJANjE}
  1595. begin
  1596. a:=prethodni div 10;
  1597. b:=prethodni mod 10;
  1598. if ort=0 then {HORIZONTALNO}
  1599. begin
  1600. if smer=-1 then
  1601. begin
  1602. if alevo(a,b)<>0 then
  1603. begin
  1604. m1:=a-1;
  1605. m2:=b;
  1606.  
  1607. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1608. begin
  1609. cShots[m1,m2]:=1;
  1610. pMat[m1,m2].Brush.Color:=clYellow;
  1611.  
  1612. if m1-1>=0 then
  1613. begin
  1614. if m2-1>=0 then
  1615. begin
  1616. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1617.  
  1618. cShots[m1-1,m2-1]:=2;
  1619. end;
  1620. if m2+1<=9 then
  1621. begin
  1622. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1623.  
  1624. cShots[m1-1,m2+1]:=2;
  1625. end;
  1626. end;
  1627. if m1+1<=9 then
  1628. begin
  1629. if m2-1>=0 then
  1630. begin
  1631. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1632.  
  1633. cShots[m1+1,m2-1]:=2;
  1634. end;
  1635. if m2+1<=9 then
  1636. begin
  1637. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1638.  
  1639. cShots[m1+1,m2+1]:=2;
  1640. end;
  1641. end;
  1642. if isPotopljen(m1,m2,2) then
  1643. begin
  1644. boji(m1,m2,2);
  1645. pships[4]:=pships[4]-1;
  1646. br:=0;
  1647. mode:=1;
  1648. uzast:=0;
  1649. for i:=1 to 4 do
  1650. br:=br+pships[i];
  1651. if br=0 then
  1652. kraj
  1653. else
  1654. cOdigraj;
  1655. end;
  1656. end
  1657. else
  1658. begin
  1659. smer:=1;
  1660. prethodni:=(a+2)*10+b;
  1661. cShots[m1,m2]:=2;
  1662. pMat[m1,m2].brush.color:=clGray;
  1663. pTurn.Brush.color:=clGreen;
  1664. cTurn.Brush.color:=clRed;
  1665.  
  1666. end;
  1667. end
  1668. else
  1669.  
  1670.  
  1671.  
  1672. begin
  1673. m1:=a+3;
  1674. m2:=b;
  1675. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1676. begin
  1677. cShots[m1,m2]:=1;
  1678. pMat[m1,m2].Brush.Color:=clYellow;
  1679.  
  1680. if m1-1>=0 then
  1681. begin
  1682. if m2-1>=0 then
  1683. begin
  1684. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1685.  
  1686. cShots[m1-1,m2-1]:=2;
  1687. end;
  1688. if m2+1<=9 then
  1689. begin
  1690. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1691.  
  1692. cShots[m1-1,m2+1]:=2;
  1693. end;
  1694. end;
  1695. if m1+1<=9 then
  1696. begin
  1697. if m2-1>=0 then
  1698. begin
  1699. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1700.  
  1701. cShots[m1+1,m2-1]:=2;
  1702. end;
  1703. if m2+1<=9 then
  1704. begin
  1705. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1706.  
  1707. cShots[m1+1,m2+1]:=2;
  1708. end;
  1709. end;
  1710. if isPotopljen(m1,m2,2) then
  1711. begin
  1712. boji(m1,m2,2);
  1713. pships[4]:=pships[4]-1;
  1714. br:=0;
  1715. mode:=1;
  1716. uzast:=0;
  1717. for i:=1 to 4 do
  1718. br:=br+pships[i];
  1719. if br=0 then
  1720. kraj
  1721. else
  1722. cOdigraj;
  1723. end;
  1724. end
  1725.  
  1726.  
  1727. end;
  1728. end
  1729. else
  1730. begin
  1731.  
  1732. if adesno(a,b)<>0 then
  1733. begin
  1734. m1:=a+1;
  1735. m2:=b;
  1736.  
  1737. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1738. begin
  1739. cShots[m1,m2]:=1;
  1740. pMat[m1,m2].Brush.Color:=clYellow;
  1741.  
  1742. if m1-1>=0 then
  1743. begin
  1744. if m2-1>=0 then
  1745. begin
  1746. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1747.  
  1748. cShots[m1-1,m2-1]:=2;
  1749. end;
  1750. if m2+1<=9 then
  1751. begin
  1752. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1753.  
  1754. cShots[m1-1,m2+1]:=2;
  1755. end;
  1756. end;
  1757. if m1+1<=9 then
  1758. begin
  1759. if m2-1>=0 then
  1760. begin
  1761. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1762.  
  1763. cShots[m1+1,m2-1]:=2;
  1764. end;
  1765. if m2+1<=9 then
  1766. begin
  1767. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1768.  
  1769. cShots[m1+1,m2+1]:=2;
  1770. end;
  1771. end;
  1772. if isPotopljen(m1,m2,2) then
  1773. begin
  1774. boji(m1,m2,2);
  1775. pships[4]:=pships[4]-1;
  1776. br:=0;
  1777. mode:=1;
  1778. uzast:=0;
  1779. for i:=1 to 4 do
  1780. br:=br+pships[i];
  1781. if br=0 then
  1782. kraj
  1783. else
  1784. cOdigraj;
  1785. end;
  1786. end
  1787. else
  1788. begin
  1789. smer:=-1;
  1790. prethodni:=(a-2)*10+b;
  1791. cShots[m1,m2]:=2;
  1792. pMat[m1,m2].brush.color:=clGray;
  1793. pTurn.Brush.color:=clGreen;
  1794. cTurn.Brush.color:=clRed;
  1795.  
  1796. end;
  1797. end
  1798. else
  1799.  
  1800.  
  1801.  
  1802. begin
  1803. m1:=a-3;
  1804. m2:=b;
  1805. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1806. begin
  1807. cShots[m1,m2]:=1;
  1808. pMat[m1,m2].Brush.Color:=clYellow;
  1809.  
  1810. if m1-1>=0 then
  1811. begin
  1812. if m2-1>=0 then
  1813. begin
  1814. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1815.  
  1816. cShots[m1-1,m2-1]:=2;
  1817. end;
  1818. if m2+1<=9 then
  1819. begin
  1820. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1821.  
  1822. cShots[m1-1,m2+1]:=2;
  1823. end;
  1824. end;
  1825. if m1+1<=9 then
  1826. begin
  1827. if m2-1>=0 then
  1828. begin
  1829. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1830.  
  1831. cShots[m1+1,m2-1]:=2;
  1832. end;
  1833. if m2+1<=9 then
  1834. begin
  1835. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1836.  
  1837. cShots[m1+1,m2+1]:=2;
  1838. end;
  1839. end;
  1840. if isPotopljen(m1,m2,2) then
  1841. begin
  1842. boji(m1,m2,2);
  1843. pships[4]:=pships[4]-1;
  1844. br:=0;
  1845. mode:=1;
  1846. uzast:=0;
  1847. for i:=1 to 4 do
  1848. br:=br+pships[i];
  1849. if br=0 then
  1850. kraj
  1851. else
  1852. cOdigraj;
  1853. end;
  1854.  
  1855.  
  1856. end;
  1857.  
  1858.  
  1859. end;
  1860.  
  1861. end;
  1862. end;
  1863.  
  1864. if ort=1 then {VERTIKALNO}
  1865. begin
  1866. if smer=-1 then
  1867. begin
  1868. if agore(a,b)<>0 then
  1869. begin
  1870. m1:=a;
  1871. m2:=b-1;
  1872.  
  1873. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1874. begin
  1875. cShots[m1,m2]:=1;
  1876. pMat[m1,m2].Brush.Color:=clYellow;
  1877.  
  1878. if m1-1>=0 then
  1879. begin
  1880. if m2-1>=0 then
  1881. begin
  1882. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1883.  
  1884. cShots[m1-1,m2-1]:=2;
  1885. end;
  1886. if m2+1<=9 then
  1887. begin
  1888. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1889.  
  1890. cShots[m1-1,m2+1]:=2;
  1891. end;
  1892. end;
  1893. if m1+1<=9 then
  1894. begin
  1895. if m2-1>=0 then
  1896. begin
  1897. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1898.  
  1899. cShots[m1+1,m2-1]:=2;
  1900. end;
  1901. if m2+1<=9 then
  1902. begin
  1903. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1904.  
  1905. cShots[m1+1,m2+1]:=2;
  1906. end;
  1907. end;
  1908. if isPotopljen(m1,m2,2) then
  1909. begin
  1910. boji(m1,m2,2);
  1911. pships[4]:=pships[4]-1;
  1912. br:=0;
  1913. mode:=1;
  1914. uzast:=0;
  1915. for i:=1 to 4 do
  1916. br:=br+pships[i];
  1917. if br=0 then
  1918. kraj
  1919. else
  1920. cOdigraj;
  1921. end;
  1922. end
  1923. else
  1924. begin
  1925. smer:=1;
  1926. prethodni:=a*10+b+2;
  1927. cShots[m1,m2]:=2;
  1928. pMat[m1,m2].brush.color:=clGray;
  1929. pTurn.Brush.color:=clGreen;
  1930. cTurn.Brush.color:=clRed;
  1931.  
  1932. end;
  1933. end
  1934. else
  1935.  
  1936.  
  1937.  
  1938. begin
  1939. m1:=a;
  1940. m2:=b+3;
  1941. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  1942. begin
  1943. cShots[m1,m2]:=1;
  1944. pMat[m1,m2].Brush.Color:=clYellow;
  1945.  
  1946. if m1-1>=0 then
  1947. begin
  1948. if m2-1>=0 then
  1949. begin
  1950. pMat[m1-1,m2-1].Brush.Color:=clGray;
  1951.  
  1952. cShots[m1-1,m2-1]:=2;
  1953. end;
  1954. if m2+1<=9 then
  1955. begin
  1956. pMat[m1-1,m2+1].Brush.Color:=clGray;
  1957.  
  1958. cShots[m1-1,m2+1]:=2;
  1959. end;
  1960. end;
  1961. if m1+1<=9 then
  1962. begin
  1963. if m2-1>=0 then
  1964. begin
  1965. pMat[m1+1,m2-1].Brush.Color:=clGray;
  1966.  
  1967. cShots[m1+1,m2-1]:=2;
  1968. end;
  1969. if m2+1<=9 then
  1970. begin
  1971. pMat[m1+1,m2+1].Brush.Color:=clGray;
  1972.  
  1973. cShots[m1+1,m2+1]:=2;
  1974. end;
  1975. end;
  1976. if isPotopljen(m1,m2,2) then
  1977. begin
  1978. boji(m1,m2,2);
  1979. pships[3]:=pships[3]-1;
  1980. br:=0;
  1981. mode:=1;
  1982. uzast:=0;
  1983. for i:=1 to 4 do
  1984. br:=br+pships[i];
  1985. if br=0 then
  1986. kraj
  1987. else
  1988. cOdigraj;
  1989. end;
  1990. end;
  1991.  
  1992.  
  1993.  
  1994. end;
  1995. end
  1996. else
  1997. begin
  1998.  
  1999. if adole(a,b)<>0 then
  2000. begin
  2001. m1:=a;
  2002. m2:=b+1;
  2003.  
  2004. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  2005. begin
  2006. cShots[m1,m2]:=1;
  2007. pMat[m1,m2].Brush.Color:=clYellow;
  2008.  
  2009. if m1-1>=0 then
  2010. begin
  2011. if m2-1>=0 then
  2012. begin
  2013. pMat[m1-1,m2-1].Brush.Color:=clGray;
  2014.  
  2015. cShots[m1-1,m2-1]:=2;
  2016. end;
  2017. if m2+1<=9 then
  2018. begin
  2019. pMat[m1-1,m2+1].Brush.Color:=clGray;
  2020.  
  2021. cShots[m1-1,m2+1]:=2;
  2022. end;
  2023. end;
  2024. if m1+1<=9 then
  2025. begin
  2026. if m2-1>=0 then
  2027. begin
  2028. pMat[m1+1,m2-1].Brush.Color:=clGray;
  2029.  
  2030. cShots[m1+1,m2-1]:=2;
  2031. end;
  2032. if m2+1<=9 then
  2033. begin
  2034. pMat[m1+1,m2+1].Brush.Color:=clGray;
  2035.  
  2036. cShots[m1+1,m2+1]:=2;
  2037. end;
  2038. end;
  2039. if isPotopljen(m1,m2,2) then
  2040. begin
  2041. boji(m1,m2,2);
  2042. pships[4]:=pships[4]-1;
  2043. br:=0;
  2044. mode:=1;
  2045. uzast:=0;
  2046. for i:=1 to 4 do
  2047. br:=br+pships[i];
  2048. if br=0 then
  2049. kraj
  2050. else
  2051. cOdigraj;
  2052. end
  2053.  
  2054. end
  2055. else
  2056. begin
  2057. smer:=-1;
  2058. prethodni:=a*10+b-2;
  2059. cShots[m1,m2]:=2;
  2060. pMat[m1,m2].brush.color:=clGray;
  2061. pTurn.Brush.color:=clGreen;
  2062. cTurn.Brush.color:=clRed;
  2063.  
  2064. end;
  2065. end
  2066. else
  2067.  
  2068.  
  2069.  
  2070. begin
  2071. m1:=a;
  2072. m2:=b-3;
  2073. if (pBoard[m1,m2]<>0)and(pBoard[m1,m2]<>5) then
  2074. begin
  2075. cShots[m1,m2]:=1;
  2076. pMat[m1,m2].Brush.Color:=clYellow;
  2077.  
  2078. if m1-1>=0 then
  2079. begin
  2080. if m2-1>=0 then
  2081. begin
  2082. pMat[m1-1,m2-1].Brush.Color:=clGray;
  2083.  
  2084. cShots[m1-1,m2-1]:=2;
  2085. end;
  2086. if m2+1<=9 then
  2087. begin
  2088. pMat[m1-1,m2+1].Brush.Color:=clGray;
  2089.  
  2090. cShots[m1-1,m2+1]:=2;
  2091. end;
  2092. end;
  2093. if m1+1<=9 then
  2094. begin
  2095. if m2-1>=0 then
  2096. begin
  2097. pMat[m1+1,m2-1].Brush.Color:=clGray;
  2098.  
  2099. cShots[m1+1,m2-1]:=2;
  2100. end;
  2101. if m2+1<=9 then
  2102. begin
  2103. pMat[m1+1,m2+1].Brush.Color:=clGray;
  2104.  
  2105. cShots[m1+1,m2+1]:=2;
  2106. end;
  2107. end;
  2108. if isPotopljen(m1,m2,2) then
  2109. begin
  2110. boji(m1,m2,2);
  2111. pships[3]:=pships[3]-1;
  2112. br:=0;
  2113. mode:=1;
  2114. uzast:=0;
  2115. for i:=1 to 4 do
  2116. br:=br+pships[i];
  2117. if br=0 then
  2118. kraj
  2119. else
  2120. cOdigraj;
  2121. end;
  2122. end;
  2123.  
  2124.  
  2125. end;
  2126.  
  2127. end;
  2128. end;
  2129. end;
  2130. end;
  2131. end;
  2132. procedure TForm1.pShapeMouseDown(Sender: TObject; Button: TMouseButton; {Boji polje u zavisnosti da li je pogodjeno ili ne i unosi vrednosti u pShots}
  2133. Shift: TShiftState; X, Y: Integer);
  2134. var m1,m2,i,j,k:integer;
  2135. begin
  2136. if pTurn.Brush.color=clGreen then
  2137. begin
  2138.  
  2139. m1:=0;
  2140. m2:=0;
  2141. for i:=0 to 9 do
  2142. for j:=0 to 9 do
  2143. if Sender=cMat[i,j] then
  2144. begin
  2145. m1:=i;
  2146. m2:=j;
  2147. end;
  2148.  
  2149. if (cBoard[m1,m2]<>0)and(cBoard[m1,m2]<>5) then
  2150. begin
  2151. pShots[m1,m2]:=1;
  2152. cMat[m1,m2].Brush.Color:=clYellow;
  2153. cMat[m1,m2].enabled:=false;
  2154. if m1-1>=0 then
  2155. begin
  2156. if m2-1>=0 then
  2157. begin
  2158. cMat[m1-1,m2-1].Brush.Color:=clGray;
  2159. cMat[m1-1,m2-1].enabled:=false;
  2160. end;
  2161. if m2+1<=9 then
  2162. begin
  2163. cMat[m1-1,m2+1].Brush.Color:=clGray;
  2164. cMat[m1-1,m2+1].enabled:=false;
  2165. end;
  2166. end;
  2167. if m1+1<=9 then
  2168. begin
  2169. if m2-1>=0 then
  2170. begin
  2171. cMat[m1+1,m2-1].Brush.Color:=clGray;
  2172. cMat[m1+1,m2-1].enabled:=false;
  2173. end;
  2174. if m2+1<=9 then
  2175. begin
  2176. cMat[m1+1,m2+1].Brush.Color:=clGray;
  2177. cMat[m1+1,m2+1].enabled:=false;
  2178. end;
  2179. end;
  2180.  
  2181. if isPotopljen(m1,m2,1) then
  2182. begin
  2183. ShowMessage(inttostr(cBoard[m1,m2]));
  2184.  
  2185. ShowMessage('brod potopljen');
  2186. boji(m1,m2,1);
  2187. k:=0;
  2188. for i:=1 to 4 do
  2189. k:=k+cships[i];
  2190. if k=0 then
  2191. kraj;
  2192.  
  2193. end;
  2194. end
  2195. else
  2196. begin
  2197. pShots[m1,m2]:=2;
  2198. cMat[m1,m2].Brush.Color:=clGray;
  2199. cMat[m1,m2].enabled:=false;
  2200. pTurn.Brush.color:=clRed;
  2201. cTurn.Brush.color:=clGreen;
  2202. cOdigraj;
  2203. end;
  2204.  
  2205.  
  2206.  
  2207. end;
  2208. end;
  2209.  
  2210.  
  2211. function TForm1.pOdigraj(p, q: integer): boolean;
  2212. begin
  2213. if cBoard[p,q]=1 then
  2214. pOdigraj:=true
  2215. else
  2216. pOdigraj:=false;
  2217. end;
  2218.  
  2219.  
  2220.  
  2221. function PCheckForShip(m,k,x,l:integer):boolean;
  2222. var ok:boolean;
  2223. br,i,j:integer;
  2224.  
  2225. begin
  2226. ok:=false;
  2227. if x=0 then
  2228. begin
  2229. br:=0;
  2230. if m>=l then
  2231. begin
  2232. for i:=m-l+1 to m do
  2233. if pBoard[i,k]=0 then
  2234. br:=br+1;
  2235. if br=l then
  2236. ok:=true;
  2237.  
  2238. end;
  2239. end;
  2240.  
  2241. if x=1 then
  2242. begin
  2243. br:=0;
  2244. if m+l-1<=9 then
  2245. begin
  2246. for i:=m to m+l-1 do
  2247. if PBoard[i,k]=0 then
  2248. br:=br+1;
  2249. if br=l then
  2250. ok:=true;
  2251.  
  2252. end;
  2253. end;
  2254.  
  2255. if x=2 then
  2256. begin
  2257. br:=0;
  2258. if k>=l then
  2259. begin
  2260. for j:=k-l+1 to k do
  2261. if PBoard[m,j]=0 then
  2262. br:=br+1;
  2263. if br=l then
  2264. ok:=true;
  2265.  
  2266. end;
  2267. end;
  2268.  
  2269. if x=3 then
  2270. begin
  2271. br:=0;
  2272. if k+l-1<=9 then
  2273. begin
  2274. for j:=k to k+l-1 do
  2275. if PBoard[m,j]=0 then
  2276. br:=br+1;
  2277. if br=l then
  2278. ok:=true;
  2279.  
  2280. end;
  2281. end;
  2282.  
  2283. PCheckForShip:=ok;
  2284. end;
  2285.  
  2286. procedure PSetShip(m,k,x,l:integer);
  2287. var i,j:integer;
  2288. begin
  2289. if x=0 then
  2290. begin
  2291. for i:=m-l to m+1 do
  2292. for j:=k-1 to k+1 do
  2293. 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
  2294. PBoard[i,j]:=5;
  2295. for i:=m-l+1 to m do
  2296. begin
  2297. PBoard[i,k]:=l;
  2298. PMat[i,k].brush.color:=clblue;
  2299. end;
  2300. end;
  2301. if x=1 then
  2302. begin
  2303. for i:=m-1 to m+l do
  2304. for j:=k-1 to k+1 do
  2305. 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
  2306. PBoard[i,j]:=5;
  2307. for i:=m to m+l-1 do
  2308. begin
  2309. PBoard[i,k]:=l;
  2310. PMat[i,k].brush.color:=clblue;
  2311. end;
  2312. end;
  2313. if x=2 then
  2314. begin
  2315. for i:=m-1 to m+1 do
  2316. for j:=k-l to k+1 do
  2317. 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
  2318. PBoard[i,j]:=5;
  2319. for j:=k-l+1 to k do
  2320. begin
  2321. PBoard[m,j]:=l;
  2322. PMat[m,j].brush.color:=clblue;
  2323. end;
  2324. end;
  2325. if x=3 then
  2326. begin
  2327. for i:=m-1 to m+1 do
  2328. for j:=k-1 to k+l do
  2329. 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
  2330. PBoard[i,j]:=5;
  2331. for j:=k to k+l-1 do
  2332. begin
  2333. PBoard[m,j]:=l;
  2334. PMat[m,j].brush.color:=clblue;
  2335. end;
  2336. end;
  2337.  
  2338. end;
  2339.  
  2340. procedure PGenerateRandom;
  2341. var
  2342. x,l,m,k,i,j:integer;
  2343. begin
  2344.  
  2345. for l:=4 downto 1 do
  2346. begin
  2347. j:=4-l+1;
  2348.  
  2349. for i:=1 to j do
  2350. begin
  2351. repeat
  2352. randomize;
  2353. m:=random(9);
  2354. k:=random(9);
  2355. until PCheckForShip(m,k,0,l) OR PCheckForShip(m,k,1,l) OR PCheckForShip(m,k,2,l) OR PCheckForShip(m,k,3,l);
  2356.  
  2357. repeat
  2358. x:=random(3);
  2359. until PCheckForShip(m,k,x,l);
  2360.  
  2361. PSetShip(m,k,x,l);
  2362.  
  2363. end;
  2364.  
  2365.  
  2366.  
  2367.  
  2368. end;
  2369.  
  2370. end;
  2371. function cCheckForShip(m,k,x,l:integer):boolean;
  2372. var ok:boolean;
  2373. br,i,j:integer;
  2374.  
  2375. begin
  2376. ok:=false;
  2377. if x=0 then
  2378. begin
  2379. br:=0;
  2380. if m>=l then
  2381. begin
  2382. for i:=m-l+1 to m do
  2383. if cBoard[i,k]=0 then
  2384. br:=br+1;
  2385. if br=l then
  2386. ok:=true;
  2387.  
  2388. end;
  2389. end;
  2390.  
  2391. if x=1 then
  2392. begin
  2393. br:=0;
  2394. if m+l-1<=9 then
  2395. begin
  2396. for i:=m to m+l-1 do
  2397. if cBoard[i,k]=0 then
  2398. br:=br+1;
  2399. if br=l then
  2400. ok:=true;
  2401.  
  2402. end;
  2403.  
  2404. end;
  2405.  
  2406. if x=2 then
  2407. begin
  2408. br:=0;
  2409. if k>=l then
  2410. begin
  2411. for j:=k-l+1 to k do
  2412. if cBoard[m,j]=0 then
  2413. br:=br+1;
  2414. if br=l then
  2415. ok:=true;
  2416.  
  2417. end;
  2418. end;
  2419.  
  2420. if x=3 then
  2421. begin
  2422. br:=0;
  2423. if k+l-1<=9 then
  2424. begin
  2425. for j:=k to k+l-1 do
  2426. if cBoard[m,j]=0 then
  2427. br:=br+1;
  2428. if br=l then
  2429. ok:=true;
  2430.  
  2431. end;
  2432.  
  2433. end;
  2434.  
  2435. cCheckForShip:=ok;
  2436. end;
  2437. procedure cSetShip(m,k,x,l:integer);
  2438. var i,j:integer;
  2439. begin
  2440. if x=0 then
  2441. begin
  2442.  
  2443. for i:=m-l to m+1 do
  2444. for j:=k-1 to k+1 do
  2445. 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
  2446. cBoard[i,j]:=5;
  2447. for i:=m-l+1 to m do
  2448.  
  2449. cBoard[i,k]:=l;
  2450.  
  2451. end;
  2452. if x=1 then
  2453. begin
  2454.  
  2455. for i:=m-1 to m+l do
  2456. for j:=k-1 to k+1 do
  2457. 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
  2458. cBoard[i,j]:=5;
  2459. for i:=m to m+l-1 do
  2460.  
  2461. cBoard[i,k]:=l;
  2462.  
  2463. end;
  2464. if x=2 then
  2465. begin
  2466.  
  2467. for i:=m-1 to m+1 do
  2468. for j:=k-l to k+1 do
  2469. 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
  2470. cBoard[i,j]:=5;
  2471. for j:=k-l+1 to k do
  2472.  
  2473. cBoard[m,j]:=l;
  2474.  
  2475. end;
  2476. if x=3 then
  2477. begin
  2478.  
  2479. for i:=m-1 to m+1 do
  2480. for j:=k-1 to k+l do
  2481. 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
  2482. cBoard[i,j]:=5;
  2483. for j:=k to k+l-1 do
  2484. cBoard[m,j]:=l;
  2485. end;
  2486.  
  2487. end;
  2488. procedure cGenerateRandom;
  2489. var
  2490. x,l,m,k,i,j:integer;
  2491. begin
  2492.  
  2493. for l:=4 downto 1 do
  2494. begin
  2495. j:=4-l+1;
  2496.  
  2497. for i:=1 to j do
  2498. begin
  2499. repeat
  2500. randomize;
  2501. m:=random(9);
  2502. k:=random(9);
  2503. until CCheckForShip(m,k,0,l) OR CCheckForShip(m,k,1,l) OR CCheckForShip(m,k,2,l) OR CCheckForShip(m,k,3,l);
  2504.  
  2505. repeat
  2506. x:=random(3);
  2507. until CCheckForShip(m,k,x,l);
  2508.  
  2509. CSetShip(m,k,x,l);
  2510.  
  2511. end;
  2512.  
  2513.  
  2514.  
  2515. end;
  2516.  
  2517. end;
  2518.  
  2519. procedure TForm1.CDButton1Click(Sender: TObject);
  2520.  
  2521. begin
  2522.  
  2523.  
  2524. cGenerateRandom;
  2525. pGenerateRandom;
  2526.  
  2527. end;
  2528.  
  2529. procedure TForm1.CDButton2Click(Sender: TObject);
  2530. var i,j:integer;
  2531. begin
  2532. pTurn.Brush.color:=clGreen;
  2533. cTurn.Brush.color:=clRed;
  2534. for i:=0 to 9 do
  2535. for j:=0 to 9 do
  2536. begin
  2537. cBoard[i,j]:=0;
  2538. cMat[i,j].brush.color:=clWhite;
  2539. cMat[i,j].enabled:=true;
  2540. end;
  2541. for i:=0 to 9 do
  2542. for j:=0 to 9 do
  2543. begin
  2544. PBoard[i,j]:=0;
  2545. PMat[i,j].brush.color:=clwhite;
  2546. end;
  2547. for i:=1 to 4 do
  2548. begin
  2549. cships[i]:=4-i+1;
  2550. pships[i]:=4-i+1
  2551. end;
  2552. prethodni:=0;
  2553. uzast:=0;
  2554. mode:=1;
  2555. end;
  2556.  
  2557. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement