PITON3.PAS 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. Uses CRT,Graph,DOS;
  2. Type Hiscore = record
  3. Name : array[1..10] of string[18];
  4. Score : array[1..10] of Word;
  5. Sp : byte;
  6. end;
  7. Var
  8. test : boolean;
  9. now, cl : byte;
  10. rcrd : boolean;
  11. s : SearchRec;
  12. Tbl : file of HiScore;
  13. MAX,col : HiScore;
  14. C : char;
  15. lt, rt : Byte;
  16. W, e : word;
  17. Dir, b : byte;
  18. Num : integer;
  19. en : array [1..2] of byte;
  20. bg : array [1..2] of byte;
  21. a : array [20..80, 2..25] of integer;
  22. i,j,k,l,r : byte;
  23. {-----------------======================-----------------}
  24. Procedure ClnBuf;forward;
  25. Procedure Setup; forward;
  26. Procedure Stat1(bg1,bg2:byte); forward;
  27. Procedure Apple ; forward;
  28. Procedure Ext ; forward;
  29. Procedure StartUp; forward;
  30. Procedure DrawTable; forward;
  31. Procedure Game; forward;
  32. {---------------------------------------------------------}
  33. Function Last(n:word):integer;
  34. Var p,o : byte;
  35. Begin
  36. for p := WhereY-3 to WhereY+3 do
  37. for o := Wherex - 3 to WhereX + 3 do
  38. if a[o,p] = n + 1 then
  39. Last := p * 100 + o;
  40. end;{last}
  41. {---------------------------------------------------------}
  42. Procedure ClnBuf;
  43. var
  44. z : char;
  45. v : byte;
  46. p : boolean;
  47. begin
  48. p := false;
  49. c := #1;
  50. w := 0;
  51. Repeat
  52. if KeyPressed then
  53. z := ReadKey;
  54. if z = #0 then v := ord(readKey);
  55. if (v = 77) or (z = #27) or (z = 'p') or (z = 'P') or (v = 75) then
  56. begin
  57. p := true;
  58. c := z;
  59. w := v;
  60. end;
  61. if p then exit;
  62. until not keypressed;
  63. end;{clnbuf}
  64. {---------------------------------------------------------}
  65. Procedure FullClnBuf;
  66. begin
  67. Repeat
  68. if KeyPressed then
  69. ReadKey;
  70. until not keypressed;
  71. end;{clnbuf}
  72. {----------------------------------------------------------}
  73. Procedure Recrd(i : byte);
  74. Var t : byte;
  75. Begin
  76. t := 0;
  77. if rcrd then begin
  78. ClrScr;
  79. GotoXY(30,10);
  80. if i = 10 then max.score[10] := col.score[1]
  81. else
  82. for t := 9 downto i do begin
  83. max.score[t+1] := max.score[t];
  84. max.name[t+1] := max.name[t]
  85. end;
  86. max.score[i] := col.score[1];
  87. TextColor(cyan);
  88. Write('П О З Д Р А В Л Я Ю');
  89. GotoXY(30,12);
  90. TextColor(Blue);
  91. Write('Вы поставили рекорд');
  92. GotoXY(12,17);
  93. TextColor(Yellow);
  94. Write('Введите свое имя до 20 символов ');
  95. TextColor(lightgreen);
  96. Readln(max.name[i]);
  97. TextColor(7);
  98. Seek(tbl,0);
  99. Write(tbl,max);
  100. Close(tbl);
  101. Reset(tbl);
  102. end;
  103. end;{Recrd}
  104. {-----------------------------------------------------------}
  105. Procedure SetCursorSize(size:word);
  106. var
  107. reg : registers;
  108. begin
  109. with reg do begin
  110. AH := $01;
  111. CH := hi(size);
  112. CL := lo(size);
  113. Intr($10,reg);
  114. end;
  115. end;
  116. {------------------------------------------------------------}
  117. Procedure Setup;
  118. begin
  119. CloseGraph;
  120. ClrScr;
  121. TextMode(CO80);
  122. SetCursorSize(16*256);
  123. GotoXY(10, 5);
  124. Write('1 : Скорость');
  125. {GotoXY(10, 10);
  126. Write('2 : Установить Клавиши');}
  127. GotoXY(10, 15);
  128. Write('3 : Завершить настроики');
  129. GotoXY(1,1);
  130. Case readkey of
  131. '1' : begin
  132. GotoXY(12,20);
  133. Write('Введите скорость 1..10 (5) ');
  134. repeat
  135. Readln(max.sp);
  136. until (max.sp > 0) and (max.sp < 11);
  137. end;
  138. '2' : begin
  139. end;
  140. end;
  141. end;{setup}
  142. {--------------------------------------------------------}
  143. Procedure Stat1;
  144. begin
  145. TextColor(Yellow);
  146. GotoXY(15,3);
  147. Write(' ');
  148. GotoXY(15,3);
  149. Write(bg1-21);
  150. GotoXY(15,5);
  151. Write(' ');
  152. GotoXY(15,5);
  153. Write(bg2-2);
  154. GotoXY(15,7);
  155. Write(col.score[1]);
  156. GotoXY(15,9);
  157. Write(num);
  158. GotoXY(bg1,bg2);
  159. TextColor(cl);
  160. end; {stat}
  161. {--------------------------------------------------------}
  162. Procedure StatMain;
  163. Var n,k : byte;
  164. begin
  165. N := 0;
  166. DrawTable;
  167. TextColor(Yellow);
  168. GotoXY(1,3);
  169. Write('X : ');
  170. GotoXY(1,5);
  171. Write('Y : ');
  172. GotoXY(1,7);
  173. Write('Длина змея : ');
  174. GotoXY(1,9);
  175. Write('Число ходов : ');
  176. GotoXY(7,12);
  177. TextColor(LightBlue);
  178. Write('Лучшие ');
  179. TextColor(LightGreen);
  180. for n := 1 to 10 do begin
  181. GotoXY(2,13 + n);
  182. Write(max.name[n], Max.score[n]:(17 - length(max.name[n])));
  183. end;
  184. for n := 3 to 24 do
  185. for k := 21 to 79 do
  186. a[k,n] := 0;
  187. end; {StatMain}
  188. {------------------------------------------------}
  189. Procedure Apple;
  190. Var i,j,c,b1,b2 : byte;
  191. begin
  192. randomize;
  193. cl := now;
  194. repeat
  195. i := random(78);
  196. j := random(23);
  197. c := random(9);
  198. r := random(14);
  199. until (i > 20) and (i < 80) and (j > 2 ) and (j < 25)
  200. and (c <> 0) and (a[i,j] = 0) and (r <> 0) and (r <> 7) and (r <> cl);
  201. b1 := WhereX;
  202. b2 := WhereY;
  203. GotoXY(i,j);
  204. TextColor(r);
  205. Now := r;
  206. Write(c);
  207. TextColor(cl);
  208. a[i,j] := - c;
  209. now := r;
  210. GotoXY(b1,b2);
  211. end;
  212. {-------------------------------------------------------}
  213. Procedure Ext;
  214. var
  215. Gd, Gm :integer;
  216. k : byte;
  217. begin
  218. Sound(100);
  219. Delay(2000);
  220. Nosound;
  221. Rcrd := true;
  222. For k := 1 to 10 do
  223. if col.score[1] > max.score[k] then begin
  224. Recrd(k);
  225. rcrd := false;
  226. end;
  227. FullClnbuf;
  228. Gd := Detect;
  229. InitGraph(Gd, Gm, '');
  230. if GraphResult <> grOk then Halt(1);
  231. ClearDevice;
  232. SetColor(Magenta);
  233. SetTextStyle(TriplexFont, HorizDir,10);
  234. OutTextXY(150,100,'Game');
  235. OutTextXY(170,200,'OveR');
  236. SetColor(Green);
  237. SetTextStyle(SmallFont, HorizDir,20);
  238. OutTextXY(180,430,'Another Game ? ');
  239. if (readkey = 'y') or (readkey = 'Y') then
  240. begin
  241. CloseGraph;
  242. Game;
  243. end;
  244. Close(Tbl);
  245. Halt;
  246. end; {Ext}
  247. {-------------------------------------------------------}
  248. Procedure StartUp;
  249. var
  250. Gd, Gm : Integer;
  251. begin
  252. Gd := Detect;
  253. InitGraph(Gd, Gm, '');
  254. if GraphResult <> grOk then Halt(1);
  255. ClearDevice;
  256. SetColor(Blue);
  257. SetTextStyle(3, HorizDir,8);
  258. OutTextXY(80,100,'Game Piton');
  259. SetTextStyle(2,HorizDir,5);
  260. SetColor(LightGreen);
  261. OutTextXY(230,460,'Game PITON written in 1998 by Kesha Enikeew AKA ROD');
  262. SetColor(White);
  263. SetTextStyle(1,HorizDir,2);
  264. OutTextXY(20,400,'Press "S" for Setup, "Q" to Quit, any other to continue');
  265. case ReadKey of
  266. 's','S' : setup;
  267. 'q','Q' : begin
  268. CloseGraph;
  269. halt;
  270. end;
  271. end;
  272. CloseGraph
  273. end; {StartUp}
  274. {------------------==================-------------------}
  275. Procedure DrawTable;
  276. var y:integer;
  277. begin
  278. clrscr;
  279. TextColor(blue);
  280. GotoXY(40,2);
  281. Write('Game PITON');
  282. TextColor(7);
  283. for y := 20 to 79 do
  284. begin
  285. GotoXY(y, 3);
  286. Write('═');
  287. GotoXY(y, 25);
  288. Write('═');
  289. end;
  290. Write('╝');
  291. GotoXY(80, 2);
  292. Write('╗');
  293. For y := 3 to 23 do
  294. begin
  295. GotoXY(20, y);
  296. Write ('║');
  297. GotoXY(WhereX-1, WhereY + 1);
  298. Write('╚');
  299. GotoXY(80, y);
  300. Write ('║')
  301. end;
  302. GotoXY(20,2);
  303. Write('╔');
  304. end; {DrawTable}
  305. {-------------------------------------------------------}
  306. Procedure Game;
  307. begin
  308. Now := 7;
  309. SetCursorSize(16*256);
  310. ClrScr;
  311. TextBackGround(0);
  312. assign(Tbl,'hiscore.dat');
  313. {$I-}
  314. Reset(Tbl);
  315. {$I+}
  316. if IOResult <> 0 then
  317. ReWrite(tbl);
  318. FindFirst('Hiscore.dat',AnyFile,s);
  319. if s.size = 0 then
  320. begin
  321. if max.sp = 0 then
  322. max.sp := 5 ;
  323. max.Score[1] := 9;
  324. max.name[1] := 'Coder';
  325. Seek(tbl,0);
  326. Write(tbl,max);
  327. Close(tbl);
  328. Reset(tbl);
  329. end;
  330. {$I-}
  331. Read(tbl,max);
  332. {$I+}
  333. If IOResult <> 0 then Halt;
  334. StatMain;
  335. cl := 7;
  336. TextColor(7);
  337. e := 1;
  338. en[1] := 39;
  339. en[2] := 13;
  340. Num := 1;
  341. Dir := 1;
  342. b := 10;
  343. FullClnBuf;
  344. col.score[1] := 9;
  345. a[39,13] := 1;
  346. GotoXY(40,13);
  347. repeat
  348. l := 0;
  349. if keypressed or (c = #27) or (w = 77) or (w = 75) then
  350. begin
  351. if (c <> #27) and (w <> 77) and (W <> 75) and (c <> 'p') and (c <> 'P')
  352. then c := readkey;
  353. if c = #0 then
  354. Begin
  355. if (w <> 77) and (w <> 75) then w := ord(readkey);
  356. if (w = 77) or (w = 75) then
  357. begin
  358. l := 1;
  359. case w of
  360. 77 : case dir of
  361. 1 : begin
  362. if WhereX > 79 then ext;
  363. if a[whereX,WhereY] > 0 then ext;
  364. if a[WhereX,WhereY] < 0 then
  365. begin
  366. b := b - a[WhereX,WhereY];
  367. inc(col.score[1],-a[whereX,WhereY]);
  368. TextColor(now);
  369. end;
  370. Write('╗');
  371. inc(num);
  372. a[WhereX-1,WhereY] := Num;
  373. dir := 2;
  374. if b > 0 then dec(b);
  375. end;
  376. 2 : begin
  377. if (WhereY + 1) > 23 then ext;
  378. if a[whereX-1,WhereY+1] > 0 then ext;
  379. if a[WhereX-1,WhereY+1] < 0 then
  380. begin
  381. b := b - a[WhereX-1,WhereY+1];
  382. inc(col.score[1], -a[WhereX-1,WhereY+1]);
  383. TextColor(now);
  384. end;
  385. GotoXY(WhereX-1,WhereY+1);
  386. Write('╝');
  387. inc(num);
  388. a[WhereX-1,WhereY] := Num;
  389. dir := 3;
  390. if b > 0 then dec(b);
  391. end;
  392. 3 : begin
  393. if (WhereX - 2) < 21 then ext;
  394. if a[whereX-2,WhereY] > 0 then ext;
  395. if a[WhereX-2,WhereY] < 0 then
  396. begin
  397. b := b - a[WhereX-2,WhereY];
  398. inc(col.score[1], -a[WhereX-2,WhereY]);
  399. TextColor(now);
  400. end;
  401. GotoXY(WhereX-2,WhereY);
  402. Write('╚');
  403. inc(num);
  404. a[WhereX-1,WhereY] := num;
  405. if b > 0 then dec(b);
  406. Dir := 4
  407. end;
  408. 4 : begin
  409. if (WhereY - 1) < 3 then ext;
  410. if a[whereX-1,WhereY-1] > 0 then ext;
  411. if a[WhereX-1,WhereY-1] < 0 then
  412. begin
  413. b := b - a[WhereX-1,WhereY-1];
  414. inc(col.score[1], -a[WhereX-1,WhereY-1]);
  415. TextColor(now);
  416. end;
  417. GotoXY(WhereX-1,WhereY-1);
  418. Write('╔');
  419. inc(num);
  420. a[WhereX-1,WhereY] := Num;
  421. if b > 0 then dec(b);
  422. Dir := 1
  423. end;
  424. end;
  425. 75 : case dir of
  426. 1 : begin
  427. if WhereX > 79 then ext;
  428. if a[whereX,WhereY] > 0 then ext;
  429. if a[WhereX,WhereY] < 0 then
  430. begin
  431. b := b - a[WhereX,WhereY];
  432. inc(col.score[1], -a[WhereX,WhereY]);
  433. TextColor(now);
  434. end;
  435. Write('╝');
  436. inc(num);
  437. a[WhereX-1,WhereY] := Num ;
  438. if b > 0 then dec(b);
  439. dir := 4
  440. end;
  441. 2 : begin
  442. if WhereY + 1 > 23 then ext;
  443. if a[whereX-1,WhereY+1] > 0 then ext;
  444. if a[WhereX-1,WhereY+1] < 0 then
  445. begin
  446. b := b - a[WhereX-1,WhereY+1];
  447. inc(col.score[1], -a[WhereX-1,WhereY+1]);
  448. TextColor(now);
  449. end;
  450. GotoXY(WhereX-1,WhereY + 1);
  451. Write('╚');
  452. inc(num);
  453. a[WhereX-1,WhereY] := Num;
  454. if b > 0 then dec(b);
  455. dir := 1;
  456. end;
  457. 3 : begin
  458. if WhereX - 2 < 21 then ext;
  459. if a[whereX-2,WhereY] > 0 then ext;
  460. if a[WhereX-2,WhereY] < 0 then
  461. begin
  462. inc(b, - a[WhereX-2,WhereY]);
  463. inc(col.score[1], -a[WhereX-2,WhereY]);
  464. TextColor(now);
  465. end;
  466. GotoXY(WhereX-2,WhereY);
  467. Write('╔');
  468. inc(num);
  469. a[WhereX-1,WhereY] := num;
  470. if b > 0 then dec(b);
  471. Dir := 2
  472. end;
  473. 4 : begin
  474. if WhereY - 1 < 3 then ext;
  475. if a[whereX-1,WhereY-1] > 0 then ext;
  476. if a[WhereX-1,WhereY-1] < 0 then
  477. begin
  478. b := b - a[WhereX-1,WhereY-1];
  479. inc(col.score[1], -a[WhereX-1,WhereY-1]);
  480. TextColor(now);
  481. end;
  482. GotoXY(WhereX-1,WhereY - 1);
  483. Write('╗');
  484. inc(num);
  485. a[WhereX-1,WhereY] := num ;
  486. if b > 0 then dec(b);
  487. Dir := 3
  488. end;
  489. end;
  490. end;
  491. end;
  492. end
  493. else if c = #27 then Ext;
  494. end;
  495. begin
  496. if l = 0 then
  497. begin
  498. case dir of
  499. 1 : if WhereX > 79 then ext
  500. else
  501. if a[WhereX,WhereY] > 0 then ext
  502. else
  503. begin
  504. if a[WhereX,WhereY] < 0 then
  505. begin
  506. b:=b-a[WhereX,WhereY];
  507. inc(col.score[1],-a[whereX,WhereY]);
  508. TextColor(now);
  509. end;
  510. Write('');
  511. GotoXY(WhereX-2,WhereY);
  512. Write('═');
  513. GotoXY(WhereX+1,WhereY);
  514. inc(num);
  515. a[WhereX-1,WhereY] := Num;
  516. if b > 0 then b := b - 1;
  517. end;
  518. 2: if (WhereY + 1) > 23 then ext
  519. else
  520. if a[WhereX-1,WhereY+1] > 0 then ext
  521. else
  522. begin
  523. if a[WhereX-1,WhereY+1] < 0 then
  524. begin
  525. b := b-a[WhereX-1,WhereY+1];
  526. inc(col.score[1], -a[WhereX-1,WhereY+1]);
  527. TextColor(now);
  528. end;
  529. GotoXY(WhereX-1,WhereY+1);
  530. Write('');
  531. GotoXY(WhereX-1,WhereY-1);
  532. Write('║');
  533. GotoXY(WhereX,WhereY+1);
  534. inc(num);
  535. a[WhereX-1,WhereY] := Num;
  536. if b > 0 then b := b - 1;
  537. end;
  538. 3 : if (WhereX-2) < 21 then ext
  539. else
  540. if a[WhereX-2,WhereY] > 0 then ext
  541. else
  542. begin
  543. if a[WhereX-2,WhereY] < 0 then
  544. begin
  545. b:=b-a[WhereX-2,WhereY];
  546. inc(col.score[1], -a[WhereX-2,WhereY]);
  547. TextColor(now);
  548. end;
  549. GotoXY(WhereX-2,WhereY);
  550. Write('');
  551. Write('═');
  552. GotoXY(WhereX-1,WhereY);
  553. inc(Num);
  554. a[WhereX-1,WhereY] := Num ;
  555. if b > 0 then dec(b);
  556. end;
  557. 4 : if (WhereY - 1) < 3 then ext
  558. else
  559. if a[WhereX-1,WhereY-1] > 0 then ext
  560. else
  561. begin
  562. if a[WhereX-1,WhereY-1] < 0 then
  563. begin
  564. b := b - a[WhereX-1,WhereY-1];
  565. inc(col.score[1], -a[WhereX-1,WhereY-1]);
  566. TextColor(now);
  567. end;
  568. GotoXY(WhereX-1,WhereY-1);
  569. Write('');
  570. GotoXY(WhereX-1,WhereY+1);
  571. Write('║');
  572. GotoXY(WhereX,WhereY-1);
  573. inc(Num);
  574. a[WhereX-1,WhereY] := Num ;
  575. if b > 0 then dec(b);
  576. end;
  577. end;
  578. end;
  579. end;
  580. Stat1(WhereX,WhereY);
  581. if b = 0 then
  582. begin
  583. bg[1] := WhereX;
  584. bg[2] := WhereY;
  585. GotoXY(en[1],en[2]);
  586. Write(' ');
  587. a[WhereX-1,WhereY] := 0;
  588. en[1] := Last(e) mod 100;
  589. en[2] := Last(e) div 100;
  590. GotoXY(bg[1],bg[2]);
  591. inc(e);
  592. end;
  593. ClnBuf;
  594. Delay(1000 + max.sp * 100);
  595. test := true;
  596. for i := 21 to 79 do
  597. for j := 3 to 24 do
  598. if a[i,j] < 0 then test := false;
  599. if test then apple;
  600. until false;
  601. end;
  602. Begin
  603. StartUp;
  604. Game;
  605. end.