LINE3.PAS 19 KB

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