LINE31.PAS 20 KB

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