PITON1.PAS 18 KB

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