ARKENOID.PAS 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. Uses CRT,Graph,DOS;
  2. Procedure LITTFONT;external;
  3. {$L litt.obj}
  4. Procedure VGADRV;external;
  5. {$L vgadrv.obj}
  6. Procedure SansFont;external;
  7. {$L sans.obj}
  8. Procedure tripFont;external;
  9. {$L trip.obj}
  10. const
  11. path = '';
  12. Type Block = record
  13. x,y:Integer;
  14. style:byte;
  15. End;
  16. Type Hiscore = record
  17. Name : array[1..10] of string[13];
  18. Score : array[1..10] of Word;
  19. end;
  20. Var
  21. Tbl : file of HiScore;
  22. MAX : HiScore;
  23. rcrd : boolean;
  24. level : text;
  25. numoflev : byte;
  26. Score : word;
  27. MainX,MainY,Beg_of_pad : Integer;
  28. BallPos,LastPos :PointType;
  29. AddX,AddY,count_of_bricks,NUM:Integer;
  30. Side :boolean;
  31. blocks : array [1..84] of block;
  32. size :word;
  33. b,p :pointer;
  34. brick : array [1..3] of pointer;
  35. s : SearchRec;
  36. {----------------------------------------------------------------------}
  37. Procedure DrawPad;forward;
  38. Procedure DrawBlocks(numlev : byte);forward;
  39. Procedure GamOvr;forward;
  40. {----------------------------------}
  41. Procedure Recrd(i : byte);
  42. Var t : byte;
  43. Begin
  44. if rcrd then begin
  45. RestoreCRTMode;
  46. ClrScr;
  47. GotoXY(30,10);
  48. if i = 10 then max.score[10] := score
  49. else
  50. for t := 9 downto i do begin
  51. max.score[t+1] := max.score[t];
  52. max.name[t+1] := max.name[t]
  53. end;
  54. max.score[i] := score;
  55. TextColor(cyan);
  56. Write('П О З Д Р А В Л Я Ю');
  57. GotoXY(30,12);
  58. TextColor(Blue);
  59. Write('Вы поставили рекорд');
  60. GotoXY(12,17);
  61. TextColor(Yellow);
  62. Write('Введите свое имя до 13 символов ');
  63. TextColor(lightgreen);
  64. Read(max.name[i]);
  65. Seek(tbl,0);
  66. Write(tbl,max);
  67. Close(tbl);
  68. SetGraphMode(GetGraphMode);
  69. end;
  70. end;
  71. {-----------------------------------------------------------}
  72. Procedure NextLev;
  73. Var
  74. nameoflev : string;
  75. Begin
  76. inc(numoflev);
  77. Str(numoflev,nameoflev);
  78. assign(level,concat('level',nameoflev));
  79. {$I-}
  80. reset(level);
  81. if IOResult <> 0 then GamOvr;
  82. {$I+}
  83. PutImage(beg_of_pad,460,P^,XORPut);
  84. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  85. setcolor(black);
  86. setfillstyle(solidfill,black);
  87. bar(2,2,448,400);
  88. SetColor(Yellow);
  89. SetTextStyle(SansSerifFont,HorizDir,6);
  90. OutTextXY(150,200,concat('Level ',nameoflev));
  91. readkey;
  92. setcolor(black);
  93. setfillstyle(solidfill,black);
  94. bar(2,2,448,400);
  95. bar(535,350,556,380);
  96. SetColor(cyan);
  97. SetTextStyle(TriplexFont,HorizDir,2);
  98. OutTextXY(540,350,nameoflev);
  99. DrawBlocks(numoflev);
  100. Beg_of_pad := 155;
  101. BallPos.X := 190;
  102. BallPos.Y := 455;
  103. PutImage(beg_of_pad,460,P^,XORPut);
  104. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  105. End;
  106. {-----------------------------------------}
  107. Procedure GamOvr;
  108. Var
  109. k :byte;
  110. Begin
  111. Rcrd := true;
  112. For k := 1 to 10 do
  113. if score > max.score[k] then begin
  114. Recrd(k);
  115. rcrd := false;
  116. end;
  117. ClearDevice;
  118. SetTextStyle(3,0,8);
  119. SetColor(Magenta);
  120. OutTextXY(100,180,'Game Over');
  121. ReadLn;
  122. CloseGraph;
  123. Halt(1);
  124. End;{GamOvr}
  125. {----------------------------------}
  126. Function TestBricks:Boolean;
  127. Var
  128. i:Integer;
  129. Begin
  130. TestBricks:=false;
  131. For i := 1 to 84 do
  132. begin
  133. With blocks[i] do
  134. begin
  135. if style <> 0 then
  136. begin
  137. if (BallPos.X+6 > X) and (BallPos.X < X + 30) and
  138. (BallPos.Y+6 > Y) and (BallPos.Y<y+15) then
  139. begin
  140. TestBricks:=True;
  141. AddX:=X;
  142. AddY:=Y;
  143. Num:=I;
  144. if (LastPos.X+6>X)and(LastPos.X<X+30) then
  145. Side:=false
  146. else
  147. Side:=True;
  148. end;
  149. end;
  150. end;
  151. End;
  152. End;{TestBricks}
  153. {-----------------------------------}
  154. Procedure DrawBlocks(numlev : byte);
  155. Var
  156. i,j:Byte;
  157. Begin
  158. count_of_bricks := 0;
  159. i := 1;
  160. while not EOF(level) and (i <= 84) do
  161. begin
  162. read(level,blocks[i].style);
  163. inc(i);
  164. end;
  165. AddX:=17;
  166. AddY:=15;
  167. for i := 0 to 6 do
  168. begin
  169. For j := 1 to 12 do
  170. begin
  171. case blocks[i*12+j].style of
  172. 1: begin
  173. PutImage(AddX,AddY,Brick[1]^,XorPut);
  174. inc(count_of_bricks);
  175. end;
  176. 2: begin
  177. PutImage(AddX,AddY,Brick[2]^,XorPut);
  178. Inc(count_of_bricks);
  179. end;
  180. 3: PutImage(AddX,AddY,Brick[3]^,XorPut);
  181. end;
  182. With blocks[i*12+j] do
  183. begin
  184. x := AddX;
  185. y := AddY;
  186. end;
  187. AddX:=AddX+35
  188. end;
  189. AddX:=17;
  190. AddY:=AddY+20
  191. end;
  192. End;{DrawBlocks}
  193. {------------------------------}
  194. Procedure Initg;
  195. Var
  196. j,Gd,Gm:Integer;
  197. addscore :string;
  198. Begin
  199. if (RegisterBGIFont(@TRIPFONT) < 1) or
  200. (RegisterBGIFont(@LITTFONT) < 1) or
  201. (RegisterBGIFont(@sansFONT) < 1) then Halt(1);
  202. if RegisterBGIDriver(@VGADRV) < 1 then Halt(1);
  203. Gd := VGA;Gm:=VGAhi;
  204. InitGraph(Gd, Gm,path);
  205. if GraphResult <> grOk then
  206. Write(GraphErrorMsg(GraphResult))
  207. else begin
  208. numoflev := 0;
  209. score := 0;
  210. {-==-}
  211. assign(Tbl,'arkscore.dat');
  212. {$I-}
  213. Reset(Tbl);
  214. {$I+}
  215. if IOResult <> 0 then
  216. ReWrite(tbl);
  217. FindFirst('arkscore.dat',AnyFile,s);
  218. if s.size = 0 then
  219. begin
  220. max.Score[1] := 9;
  221. max.name[1] := 'Coder';
  222. Seek(tbl,0);
  223. Write(tbl,max);
  224. Close(tbl);
  225. Reset(tbl);
  226. end;
  227. {$I-}
  228. Read(tbl,max);
  229. {$I+}
  230. If IOResult <> 0 then Halt;
  231. SetColor(LightRed);
  232. SetTextStyle(SmallFont,0,5);
  233. for j := 1 to 10 do
  234. begin
  235. Str(max.score[j],Addscore);
  236. OutTextXY(470,100+j*20,max.name[j]);
  237. OutTextXY(580,100+j*20,addscore);
  238. end;
  239. SetColor(Blue);
  240. Settextstyle(SansSerifFont,0,4);
  241. OutTextXY(500,80,'BEST''s');
  242. {-==-}
  243. SetLineStyle(SolidLn,1,123);
  244. SetColor(Blue);
  245. Rectangle(0,0,450,GetMaxY);
  246. Rectangle(1,1,449,GetMaxY-1);
  247. SetColor(Green);
  248. Rectangle(451,0,GetMaxX,GetMaxY);
  249. Rectangle(452,1,GetMaxX-1,GetMaxY-1);
  250. {-==-}
  251. SetTextStyle(SansSerifFont,HorizDir,4);
  252. SetColor(Yellow);
  253. OutTextXY(475,10,'ARKENOID');
  254. SetTextStyle(SmallFont,HorizDir,4);
  255. SetColor(LightGreen);
  256. OutTextXY(475,50,'Written by Kesha Enikeew');
  257. SetTextStyle(TriplexFont,HorizDir,2);
  258. SetColor(Cyan);
  259. OutTextXY(475,350,'Level');
  260. OutTextXY(475,400,'Score 0');
  261. {-==-}
  262. SetColor(LightMagenta);
  263. SetFillStyle(BkSlashFill,Magenta);
  264. Bar3d(100,100,130,115,0,false);
  265. Size:=ImageSize(100,100,130,115);
  266. GetMem(Brick[1],size);
  267. GetImage(100,100,130,115,Brick[1]^);
  268. PutImage(100,100,Brick[1]^,XORPut);
  269. {-==-}
  270. SetColor(LightGreen);
  271. SetFillStyle(XHatchFill,Green);
  272. Bar3d(100,100,130,115,0,false);
  273. Size:=ImageSize(100,100,130,115);
  274. GetMem(Brick[2],size);
  275. GetImage(100,100,130,115,Brick[2]^);
  276. PutImage(100,100,Brick[2]^,XORPut);
  277. {-==-}
  278. SetColor(White);
  279. SetFillStyle(SolidFill,White);
  280. Bar(100,100,130,115);
  281. Size:=ImageSize(100,100,130,115);
  282. GetMem(Brick[3],size);
  283. GetImage(100,100,130,115,Brick[3]^);
  284. PutImage(100,100,Brick[3]^,XORPut);
  285. {-==-}
  286. SetColor(LightGreen);
  287. Circle(100,100,3);
  288. SetColor(LightBlue);
  289. Circle(100,100,2);
  290. SetColor(LightMagenta);
  291. Circle(100,100,1);
  292. Size:=ImageSize(97,97,103,103);
  293. GetMem(B,Size);
  294. GetImage(97,97,103,103,b^);
  295. PutImage(97,97,B^,XORPut);
  296. Beg_of_pad := 155;
  297. BallPos.X := 190;
  298. BallPos.Y := 455;
  299. MainX:=2;
  300. MainY:=-2;
  301. DrawPad;
  302. Size:=ImageSize(155,460,225,470);
  303. GetMem(P,Size);
  304. GetImage(155,460,225,470,P^);
  305. PutImage(BallPos.x,BallPos.Y,B^,XORPut);
  306. end;
  307. End;{initg}
  308. {---------------------------------------}
  309. Procedure DrawPad;
  310. Begin
  311. SetFillStyle(1,LightGreen);
  312. Bar(Beg_of_pad,460,Beg_of_pad+70,470);
  313. SetFillStyle(1,Yellow);
  314. Bar(Beg_of_pad+5,463,Beg_of_pad+65,467);
  315. End;{DrawPad}
  316. {-----------------------------------------------}
  317. Procedure MovePad(value:Integer);
  318. Begin
  319. PutImage(Beg_of_pad,460,P^,XORPut);
  320. if Beg_of_pad + value >= 377
  321. then Beg_of_pad:=377
  322. else
  323. if Beg_of_pad + value <= 2
  324. then Beg_of_pad := 2
  325. else Beg_of_pad:=Beg_of_pad+value;
  326. PutImage(Beg_of_pad,460,P^,XORPut);
  327. End;{MovePad}
  328. {------------------------------------}
  329. Procedure MoveBall;
  330. var Sscore : string;
  331. Begin
  332. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  333. case BallPos.Y of
  334. 456 .. 480 : begin
  335. if (BallPos.X>Beg_of_pad-6)and(BallPos.X<Beg_of_pad+70)
  336. then begin
  337. MainY:=-(random(2)+1);
  338. if MainX > 0 then MainX := random(2)+1
  339. else MainX := -(random(2)+1);
  340. End;
  341. if (BallPos.X < Beg_of_pad-2) or (BallPos.X > Beg_of_pad+70) then GamOvr;
  342. end;
  343. 0 .. 2 : begin
  344. MainY := Random(2)+1;
  345. if MainX > 0 then MainX := Random(2)+1
  346. else MainX := -(Random(2)+1);
  347. end;
  348. end;
  349. if (BallPos.X < 3) or (BallPos.X > 442) then MainX:=-MainX;
  350. if TestBricks then
  351. begin
  352. case blocks[num].style of
  353. 1: begin
  354. PutImage(AddX,AddY,Brick[1]^,XORPut);
  355. blocks[NUM].style:=0;
  356. Dec(Count_of_bricks);
  357. inc(score,15);
  358. end;
  359. 2: begin
  360. PutImage(AddX,AddY,Brick[2]^,XORPut);
  361. PutImage(AddX,AddY,Brick[1]^,XORPut);
  362. blocks[num].style := 1;
  363. inc(score,10);
  364. end;
  365. 3: inc(score,5);
  366. end;
  367. if side then MainX:=-MainX else MainY:=-MainY;
  368. Str(score,Sscore);
  369. SetColor(Black);
  370. SetFillStyle(SolidFill,Black);
  371. bar(535,400,636,430);
  372. SetColor(cyan);
  373. SetTextStyle(TriplexFont,HorizDir,2);
  374. OutTextXY(540,400,Sscore);
  375. end;
  376. LastPos.X:=BallPos.X;
  377. LastPos.Y:=BallPos.Y;
  378. BallPos.X:=BallPos.X+MainX;
  379. BallPos.Y:=BallPos.Y+MainY;
  380. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  381. Delay(100);
  382. End;{MoveBall}
  383. {---------------------------------}
  384. Procedure Play;
  385. Var
  386. w:word;
  387. c:char;
  388. Begin
  389. nextlev;
  390. repeat
  391. if count_of_bricks = 0 then nextlev;
  392. moveball;
  393. if keypressed then
  394. begin
  395. c := readkey;
  396. if c = #27 then GamOvr;
  397. if c = #0 then w := ord(readkey);
  398. case w of
  399. 77 : movepad(15);
  400. 75 : movepad(-15);
  401. end;
  402. end;
  403. until false;
  404. End;{Play}
  405. {--------------------------------------}
  406. Begin
  407. Randomize;
  408. Initg;
  409. Play;
  410. End.