XO.BAK 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. uses GRAPH,CRT,VGA;
  2. Const
  3. n = 20;
  4. NameX = 'Rod';
  5. NameO = 'Rod2';
  6. ColorX = LightBlue;
  7. ColorO = LightRed;
  8. PoleY1 = 110;
  9. PoleL = 460-PoleY1;
  10. Cell = PoleL / n;
  11. PoleX1 = round(320 - (Cell*n) / 2);
  12. PoleX2 = round(320 + (Cell*n) / 2);
  13. PoleY2 = round(PoleY1+n*cell);
  14. TimeT = 5*25*2;
  15. DelX = round(TimeT/Cell/2);
  16. DelO = round(TimeT/360);
  17. Type TPole = array [-4..n+4,-4..n+4] of byte;
  18. type
  19. {mo = array [1..n,1..n] of 0..2;}
  20. mo = TPole;
  21. mo2 = array [1..9] of byte;
  22. Var
  23. Pole : TPole;
  24. TP : Tpole;
  25. Ex : boolean;
  26. Win : byte;
  27. xc,yc : byte;
  28. count : 0..n*n+1;
  29. ENDS : array [1..5] of pointtype;
  30. {$I Rod.inc}
  31. {$I rod2.inc}
  32. Type TurnProc = procedure(cx:byte;var x,y:byte);
  33. const
  34. TurnX : TurnProc=RodNewTurn;
  35. TurnO : TurnProc=RodOldTurn;
  36. {---------------------------}
  37. Procedure Init;
  38. Var
  39. i,j : integer;
  40. Begin
  41. for i := 1 to n do for j:= 1 to n do pole[i,j] :=0;
  42. InitVGA;
  43. SetTextStyle(TriplexFont,HORIZDIR,4);
  44. SetTextJustify(CenterText,BottomText);
  45. SetFillStyle(XHATCHFILL,Blue);
  46. Bar(0,0,GetMaxX,GetMaxY);
  47. SetFillStyle(SolidFill,Black);
  48. Bar(10,10,630,470);
  49. SetCOlor(White);
  50. OutTextXY(320,40,'�¨â¢  ¯à®£à ¬¬.');
  51. OutTextXY(320,40+TextHeight('�')+5,'Šà¥á⨪¨-�®«¨ª¨.');
  52. SetColor(ColorX);
  53. SetTextJustify(LeftText,BottomText);
  54. OutTextXY(10,100,NameX);
  55. SetLineStyle(SolidLn,0,ThickWidth);
  56. Line(30,20,70,60);
  57. Line(70,20,30,60);
  58. SetColor(ColorO);
  59. Arc(590,40,0,360,20);
  60. SetTextJustify(RightText,BottomText);
  61. OutTextXY(630,100,NameO);
  62. SetLineStyle(SolidLn,0,NormWidth);
  63. SetColor(LightGray);
  64. For i := 0 to n do begin
  65. Line(round(PoleX1+Cell*i),PoleY1,round(PoleX1+Cell*i),PoleY2);
  66. Line(PoleX1,round(PoleY1+Cell*i),PoleX2,round(PoleY1+Cell*i));
  67. end;
  68. End;{Init}
  69. {--------------------------}
  70. Procedure DrawTurn(cn,x,y:byte);
  71. Var
  72. i,size : integer;
  73. Begin
  74. if cn = 1 then
  75. begin
  76. SetColor(ColorX);
  77. size := round(cell-2)-1;
  78. MoveTo(round(PoleX1+(x-1)*Cell+1),round(PoleY1+(y-1)*Cell+1));
  79. For i := 1 to size do begin LineRel(1,1);delay(delX);end;
  80. MoveTo(round(PoleX1+x*Cell-1),round(PoleY1+(y-1)*Cell+1));
  81. For i := 1 to size do begin LineRel(-1,1);delay(delX);end;
  82. Pole[x,y] := 1;
  83. end
  84. else
  85. begin
  86. setColor(ColorO);
  87. For i := 360 downto 1 do begin
  88. Arc(round(PoleX1+(x-1)*Cell+(Cell / 2)),round(PoleY1+(y-1)*Cell+(Cell / 2))
  89. ,i-1,i,round((cell-2) / 2-1));
  90. delay(DelO);
  91. end;
  92. Pole[x,y] := 2;
  93. end;
  94. End;{DrawTurn}
  95. {---------------------------}
  96. Function IsWin(x,y:byte):byte;
  97. var
  98. x1,y1 : byte;
  99. k1,k2,l1,l2 : byte;
  100. res : byte;
  101. begin
  102. res := 0;
  103. if x-4<1 then k1 := 1 else k1 := x - 4;
  104. if x+4>n then k2 := n else k2 := x + 4;
  105. if y-4<1 then l1 := 1 else l1 := y - 4;
  106. if y+4>n then l2 := n else l2 := y + 4;
  107. for x1 := k1 to k2 do
  108. for y1 := l1 to l2 do
  109. if (pole[x1,y1]<>0) then begin
  110. if ((pole[x1,y1]=pole[x1,y1-2]) and
  111. (pole[x1,y1]=pole[x1,y1-1]) and
  112. (pole[x1,y1]=pole[x1,y1+1]) and
  113. (pole[x1,y1]=pole[x1,y1+2])) then
  114. begin
  115. res := pole[x1,y1];
  116. ENDS[1].x := x1;
  117. ENDS[1].y := y1-2;
  118. ENDS[2].x := x1;
  119. ENDS[2].y := y1-1;
  120. ENDS[3].x := x1;
  121. ENDS[3].y := y1;
  122. ENDS[4].x := x1;
  123. ENDS[4].y := y1+1;
  124. ENDS[5].x := x1;
  125. ENDS[5].y := y1+2;
  126. end;
  127. if ((pole[x1,y1]=pole[x1-2,y1]) and
  128. (pole[x1,y1]=pole[x1-1,y1]) and
  129. (pole[x1,y1]=pole[x1+1,y1]) and
  130. (pole[x1,y1]=pole[x1+2,y1])) then
  131. begin
  132. res := pole[x1,y1];
  133. ENDS[1].x := x1-2;
  134. ENDS[1].y := y1;
  135. ENDS[2].x := x1-1;
  136. ENDS[2].y := y1;
  137. ENDS[3].x := x1;
  138. ENDS[3].y := y1;
  139. ENDS[4].x := x1+1;
  140. ENDS[4].y := y1;
  141. ENDS[5].x := x1+2;
  142. ENDS[5].y := y1;
  143. end;
  144. if ((pole[x1,y1]=pole[x1-2,y1-2]) and
  145. (pole[x1,y1]=pole[x1-1,y1-1]) and
  146. (pole[x1,y1]=pole[x1+1,y1+1]) and
  147. (pole[x1,y1]=pole[x1+2,y1+2])) then
  148. begin
  149. res := pole[x1,y1];
  150. ENDS[1].x := x1-2;
  151. ENDS[1].y := y1-2;
  152. ENDS[2].x := x1-1;
  153. ENDS[2].y := y1-1;
  154. ENDS[3].x := x1;
  155. ENDS[3].y := y1;
  156. ENDS[4].x := x1+1;
  157. ENDS[4].y := y1+1;
  158. ENDS[5].x := x1+2;
  159. ENDS[5].y := y1+2;
  160. end;
  161. if ((pole[x1,y1]=pole[x1+2,y1-2]) and
  162. (pole[x1,y1]=pole[x1+1,y1-1]) and
  163. (pole[x1,y1]=pole[x1-1,y1+1]) and
  164. (pole[x1,y1]=pole[x1-2,y1+2])) then
  165. begin
  166. res := pole[x1,y1];
  167. ENDS[1].x := x1+2;
  168. ENDS[1].y := y1-2;
  169. ENDS[2].x := x1+1;
  170. ENDS[2].y := y1-1;
  171. ENDS[3].x := x1;
  172. ENDS[3].y := y1;
  173. ENDS[4].x := x1-1;
  174. ENDS[4].y := y1+1;
  175. ENDS[5].x := x1-2;
  176. ENDS[5].y := y1+2;
  177. end;
  178. end;
  179. IsWin := Res;
  180. end;{IsWin}
  181. {---------------------------}
  182. Function IsLeg(x,y:byte):boolean;
  183. var res:boolean; i,j : byte;
  184. begin
  185. res := true;
  186. if not (x in [1..n]) then
  187. res := false;
  188. if not (y in [1..n]) then
  189. res := false;
  190. for i := 1 to n do for j := 1 to n do if pole[i,j] <> tp[i,j] then
  191. res := false;
  192. if tp[x,y] <> 0 then
  193. res := false;
  194. pole := tp;
  195. IsLeg:=res;
  196. end;{IsLeg}
  197. {-------------------------}
  198. Procedure DrawWin;
  199. var i : byte;
  200. Begin
  201. SetColor(LightGreen);
  202. for i := 1 to 5 do Rectangle(round(PoleX1+(ENDS[i].x-1)*cell),
  203. round(PoleY1+(ENDS[i].y-1)*cell),
  204. round(PoleX1+(ENDS[i].x)*cell),
  205. round(PoleY1+(ENDS[i].y)*cell));
  206. SetColor(White);
  207. Rectangle(round(PoleX1+(xc-1)*cell),
  208. round(PoleY1+(yc-1)*cell),
  209. round(PoleX1+(xc)*cell),
  210. round(PoleY1+(yc)*cell));
  211. End;
  212. {-------------------------}
  213. Procedure GameOver(c : byte);
  214. Var
  215. sc,s1 : string;
  216. Begin
  217. SetTextStyle(TriplexFont,HorizDir,3);
  218. SetTextJustify(1,1);
  219. str(count,sc);
  220. Case c of
  221. 1: begin
  222. DrawWin;
  223. SetColor(11);
  224. sc := '�®¡¥¤¨«  ª®¬ ­¤  '+NameX+' ­  '+sc+' 室ã';
  225. OutTextXY(320,300,sc);
  226. Ex := true;
  227. end;
  228. 2: begin
  229. DrawWin;
  230. SetColor(11);
  231. sc := '�®¡¥¤¨«  ª®¬ ­¤  '+NameO+' ­  '+sc+' 室ã';
  232. OutTextXY(320,300,sc);
  233. Ex := true;
  234. end;
  235. 3: begin
  236. sc := '�®¡¥¤¨«  ª®¬ ­¤  '+NameO;
  237. s1 := '¢á«¥¤á⢨¥ â¥å. ¯®à ¦¥­¨ï ª®¬ ­¤ë '+NameX;
  238. SetColor(11);
  239. OutTextXY(320,300,sc);
  240. OutTextXY(320,320,s1);
  241. Ex := true;
  242. end;
  243. 4: begin
  244. sc := '�®¡¥¤¨«  ª®¬ ­¤  '+NameX;
  245. s1 := '¢á«¥¤á⢨¥ â¥å. ¯®à ¦¥­¨ï ª®¬ ­¤ë '+NameO;
  246. SetColor(11);
  247. OutTextXY(320,300,sc);
  248. OutTextXY(320,320,s1);
  249. Ex := true;
  250. end;
  251. 5: begin
  252. sc := '�¨çìï!';
  253. SetColor(11);
  254. OutTextXY(320,300,sc);
  255. Ex := true;
  256. end;
  257. end;
  258. SetTextStyle(TriplexFont,HorizDir,8);
  259. SetColor(Yellow);
  260. OutTextXY(320,200,'ˆ£à  Žª®­ç¥­ !');
  261. End;{GameOver}
  262. {------------------------}
  263. BEGIN
  264. Init;
  265. ex := false;
  266. count := 0;
  267. repeat
  268. if KeyPressed then begin if ReadKey = #27 then GameOver(5) end else begin
  269. tp := pole;
  270. xc:=165;
  271. yc:=165;
  272. TurnX(1,xc,yc);
  273. if not isLeg(xc,yc) then GameOver(3)
  274. else begin
  275. inc(count);
  276. DrawTurn(1,xc,yc);
  277. win := iswin(xc,yc);
  278. if (count=n*n) then GameOver(5) else begin
  279. if Win <> 0 then GameOver(1) else
  280. begin
  281. tp := pole;
  282. xc:=165;
  283. yc:=165;
  284. TurnO(2,xc,yc);
  285. if not isLeg(xc,yc) then gameover(4)
  286. else
  287. begin
  288. DrawTurn(2,xc,yc);
  289. Inc(count);
  290. win := iswin(xc,yc);
  291. if (count=n*n) then GameOver(5) else begin
  292. if Win <> 0 then GameOver(2);
  293. end;
  294. end;
  295. end;
  296. end;
  297. end;
  298. end;
  299. until Ex;
  300. ReadKey;
  301. CloseGraph;
  302. END.