Advertisement
Zung_the_great

[pascal] the hunter (key movement test)

May 18th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.96 KB | None | 0 0
  1. {Oh yeah ! F@!#$#@# text mode !!!!}
  2. program unknow;
  3. uses crt;
  4. const
  5. size1 = 2000;
  6. size2 = 1000;
  7. fout = 'record.dat';
  8. space = #32;
  9.  
  10. type int = integer;
  11. rec = record
  12. m,n : int;
  13. end;
  14.  
  15. arr = array[0..size1, 0..size1] of char;
  16.  
  17. arr_rec = array[0..size2] of rec;
  18.  
  19. var
  20. a : arr;
  21. k : char;
  22. n,xo,yo,d,answer : int;
  23. e : arr_rec;
  24. sec,score,kt,time,dems : int;
  25.  
  26.  
  27. function found(i,j:int; a:arr):boolean;
  28. begin
  29. if a[i,j]= space then found:=true
  30. else found:=false;
  31. end;
  32.  
  33. procedure wall; {so luong buc tuong}
  34. var i,j,o:int;
  35. begin
  36. for i:=0 to 2000 do for j:=0 to 2000 do a[i,j]:=' ';
  37.  
  38. textcolor(green); randomize;
  39. for o:=1 to 290 do
  40. begin
  41. repeat
  42. i:=random(80)+1;
  43. j:=random(24)+1;
  44. until (found(i,j,a));
  45. gotoxy(i,j); write('B');
  46. a[i,j]:='B';
  47. end;
  48. textcolor(8);
  49. end;
  50.  
  51.  
  52. procedure enemy;
  53. var i,j,o:int;
  54. begin
  55. textcolor(white);
  56. randomize;
  57. for o:=1 to 100 do {so luong quan dich}
  58. begin
  59. i:=1; j:=1;
  60. repeat
  61.  
  62. i:=random(79)+1;
  63. j:=random(24)+1;
  64. until ( found(i,j,a))and(j<>1)and(i<>1);
  65.  
  66. gotoxy(i,j); write('I');
  67. a[i,j]:='I';
  68. e[o].m:=i; e[o].n:=j;
  69. d:=40;
  70. end;
  71. textcolor(yellow);
  72. n:=o; d:=n;
  73. end;
  74.  
  75. function clear( j,i:int):boolean;
  76. begin
  77. clear:=false;
  78. if (a[j,i]=' ')or(a[j,i]='x') then clear:=true;
  79.  
  80. end;
  81.  
  82. procedure commove;
  83. var i,x,y,j,l,jo,io,dem:int;
  84. begin
  85. randomize;
  86. if d=0 then exit;
  87. repeat
  88. i:=random(n)+1;
  89. x:=e[i].m; y:=e[i].n;
  90. until (a[x,y]<>'x')and(e[i].n<>0);
  91. x:=e[i].m; y:=e[i].n;
  92. if d>3 then j:=random(4)+1 else j:=random(8)+1;
  93. case j of
  94. 1 : if(y-1<>yo)and(a[x,y-1]<>'B')and(y-1>1)and(a[x,y-1]<>'I') then
  95. begin
  96. textcolor(red);
  97. gotoxy(x,y); write('I'); a[x,y]:=' ';
  98. textcolor(white);
  99. gotoxy(x,y-1); write('I'); a[x,e[i].n-1]:='I';
  100. e[i].m:=x; e[i].n:=e[i].n-1;
  101. end;
  102. 2 : if(y+1<>yo)and(a[x,y+1]<>'B')and(y+1<25)and(a[x,y+1]<>'I') then
  103. begin
  104. textcolor(red);
  105. gotoxy(x,y); write('I'); a[x,y]:=' ';
  106. textcolor(white);
  107. gotoxy(x,y+1); write('I'); a[x,e[i].n+1]:='I';
  108. e[i].m:=x; e[i].n:=e[i].n+1;
  109. end;
  110. 3 : if(x-1<>xo)and(a[x-1,y]<>'B')and(x-1>2)and(a[x-1,y]<>'I') then
  111. begin
  112. textcolor(red);
  113. gotoxy(x,y); write('I'); a[x,y]:=' ';
  114. textcolor(white);
  115. gotoxy(x-1,y); write('I'); a[e[i].m-1,y]:='I';
  116. e[i].m:=e[i].m-1; e[i].n:=y;
  117. end;
  118. 4 : if(x+1<>xo)and(a[x+1,y]<>'B')and(x+1<80)and(a[x+1,y]<>'I') then
  119. begin
  120. textcolor(red);
  121. gotoxy(x,y); write('I'); a[x,y]:=' ';
  122. textcolor(white);
  123. gotoxy(x+1,y); write('I'); a[e[i].m+1,y]:='I';
  124. e[i].m:=e[i].m+1; e[i].n:=y;
  125. end;
  126. end;
  127.  
  128. end;
  129.  
  130. procedure comfire;
  131. var i,x,y,j,l,jo,io,dem:int;
  132. begin
  133. if d=0 then exit;
  134. randomize;
  135. repeat
  136. i:=random(n)+1;
  137. x:=e[i].m; y:=e[i].n;
  138. until (a[x,y]<>'x')and(e[i].n<>0);
  139. x:=e[i].m; y:=e[i].n;
  140. l:=random(4)+1;
  141. case l of
  142. 1 : begin
  143. jo:=x;
  144. for dem:=1 to 5 do
  145. begin
  146. inc(jo);
  147. if (a[jo,y]='B')or(jo>79)or(a[jo,y]='I') then break;
  148. gotoxy(jo,y);
  149. textcolor(black);
  150. write('~'); delay(10);
  151. textcolor(red);
  152. gotoxy(jo,y); write('~');
  153. if (jo=xo)and(y=yo) then kt:=1;
  154. end;
  155. end;
  156.  
  157. 2 : begin
  158. jo:=x;
  159. for dem:=1 to 5 do
  160. begin
  161. inc(jo,-1);
  162. if (a[jo,y]='B')or(jo<1)or(a[jo,y]='I') then break;
  163. gotoxy(jo,y);
  164. textcolor(black);
  165. write('~'); delay(10);
  166. textcolor(red);
  167. gotoxy(jo,y); write('~');
  168. if (jo=xo)and(y=yo) then kt:=1;
  169. end;
  170. end;
  171. 3 : begin
  172. io:=y;
  173. for dem:=1 to 2 do
  174. begin
  175. inc(io,1);
  176. if (a[x,io]='B')or(io>24)or(a[x,io]='I') then break;
  177. gotoxy(x,io);
  178. textcolor(black);
  179. write('~'); delay(10);
  180. textcolor(red);
  181. gotoxy(x,io); write('~');
  182. if (x=xo)and(io=yo) then kt:=1;
  183. end;
  184. end;
  185. 4 : begin
  186. io:=y;
  187. for dem:=1 to 2 do
  188. begin
  189. inc(io,-1);
  190. if (io=1)or(a[x,io]='B')or(a[x,io]='I') then break;
  191. gotoxy(x,io);
  192. textcolor(black);
  193. write('~'); delay(10);
  194. textcolor(red);
  195. gotoxy(x,io); write('~');
  196. if (x=xo)and(io=yo) then kt:=1;
  197. end;
  198. end;
  199. end;
  200. end;
  201.  
  202. procedure delete(j,i:int);
  203. var dem:int;
  204. begin
  205. for dem:=1 to n do if (e[dem].m=j)and(e[dem].n=i)then
  206. begin
  207. e[dem].m:=0;
  208. e[dem].n:=0;
  209. exit;
  210. end;
  211. end;
  212.  
  213. procedure movement(var i,j:int);
  214. var f,io,jo,fir,dem,mo:int;
  215. begin
  216. fir:=0; mo:=0; if (kt=1)or(d=0) then exit;
  217. repeat
  218. fir:=fir+1;
  219. inc(mo);
  220. if (mo=5)and(d>1) then begin commove; mo:=0; end
  221. else if (d=1) then if mo=28 then begin commove; mo:=0; end;
  222. dems:=dems+1;;
  223. delay(10);
  224. if fir=10 then begin comfire; fir:=0; end;
  225. if dems=80 then begin
  226. textcolor(yellow);
  227. inc(time); gotoxy(44,25); write(time);
  228. dems:=0;
  229. end;
  230. until keypressed;
  231. k:=readkey;
  232.  
  233. case k of
  234. 'd' : begin
  235. jo:=j;
  236. for dem:=1 to 15 do
  237. begin
  238. inc(jo);
  239. if (a[jo,i]='B')or(jo=80) then break;
  240. gotoxy(jo,i);
  241. textcolor(black);
  242. write('.'); delay(10);
  243. textcolor(red);
  244. gotoxy(jo,i); write('.');
  245. if a[jo,i]='I' then begin a[jo,i]:='x'; d:=d-1; delete(jo,i); score:=score+3; end;
  246. commove;
  247. end;
  248. end;
  249.  
  250. 'a' : begin
  251. jo:=j;
  252. for dem:=1 to 15 do
  253. begin
  254. inc(jo,-1);
  255. if (a[jo,i]='B')or(jo<1) then break;
  256. gotoxy(jo,i);
  257. textcolor(black);
  258. write('.'); delay(10);
  259. textcolor(red);
  260. gotoxy(jo,i); write('.');
  261. if a[jo,i]='I' then begin a[jo,i]:='x'; d:=d-1; delete(jo,i); score:=score+4;end;
  262. commove;
  263. end;
  264. end;
  265. 's' : begin
  266. io:=i;
  267. for dem:=1 to 10 do
  268. begin
  269. inc(io,1);
  270. if (a[j,io]='B')or(io=25) then break;
  271. gotoxy(j,io);
  272. textcolor(black);
  273. write('.'); delay(10);
  274. textcolor(red);
  275. gotoxy(j,io); write('.');
  276. if a[j,io]='I' then begin a[j,io]:='x'; d:=d-1; delete(j,io); score:=score+2;end;
  277. commove;
  278. end;
  279. end;
  280. 'w' : begin
  281. io:=i;
  282. for dem:=1 to 10 do
  283. begin
  284. inc(io,-1);
  285. if (io=0)or(a[j,io]='B') then break;
  286. gotoxy(j,io);
  287. textcolor(black);
  288. write('.'); delay(10);
  289. textcolor(red);
  290. gotoxy(j,io); write('.');
  291. if a[j,io]='I' then begin a[j,io]:='x'; d:=d-1; delete(j,io); score:=score+1;end;
  292. commove;
  293. end;
  294. end;
  295.  
  296. 'M' : if(j<80)and(clear(j+1,i)) then begin
  297. textcolor(red);
  298. gotoxy(j,i); write('Y');
  299. j:=j+1; textcolor(yellow);
  300. gotoxy(j,i); write('Y');
  301. xo:=j; yo:=i;
  302. sec:=sec-1;
  303. if d>1 then commove;
  304. end;
  305. 'K' : if (j>1)and(clear(j-1,i))then begin
  306.  
  307. textcolor(red);
  308. gotoxy(j,i); write('Y');
  309. textcolor(yellow);
  310. j:=j-1;
  311. gotoxy(j,i); write('Y');
  312. xo:=j; yo:=i;
  313. sec:=sec-1;
  314. if d>1 then commove;
  315. end;
  316. 'H' : if (i>1)and(clear(j,i-1)) then begin
  317. textcolor(red);
  318. gotoxy(j,i); write('Y');
  319. i:=i-1;
  320. textcolor(yellow);
  321. gotoxy(j,i); write('Y');
  322. xo:=j; yo:=i;
  323. sec:=sec-1;
  324. if d>1 then commove;
  325. end;
  326. 'P' : if (i<24)and(clear(j,i+1))then begin
  327. textcolor(red);
  328. gotoxy(j,i); write('Y');
  329. textcolor(yellow);
  330. i:=i+1;
  331. gotoxy(j,i); write('Y');
  332. xo:=j; yo:=i;
  333. sec:=sec-1;
  334. if d>1 then commove;
  335. end;
  336.  
  337. end;
  338. commove;
  339. comfire; dems:=dems+1;
  340. if dems mod 20=0 then
  341. begin
  342. textcolor(yellow);
  343. inc(time); gotoxy(44,25); write(time);
  344. dems:=0;
  345. end;
  346. end;
  347.  
  348.  
  349. procedure play;
  350. var i,j,fake:int; f:text;
  351. begin
  352. wall;
  353. gotoxy(1,1);
  354. for i:=1 to 80 do begin write('*'); a[i,1]:='B'; end;
  355. for i:=1 to 25 do begin
  356. write('*'); a[1,i]:='B'; gotoxy(1,i);
  357. a[80,i]:='B';
  358. end;
  359. gotoxy(80,1);
  360. for i:=1 to 25 do begin
  361. write('*');
  362. gotoxy(80,i);
  363. end;
  364. textcolor(yellow);
  365. sec:=490; gotoxy(1,25); write('MOVE : ');
  366. score:=0; gotoxy(8,25); write(sec);
  367. gotoxy(20,25); write('SCORE : ');
  368. gotoxy(29,25); write(SCORE);
  369. gotoxy(38,25); write('TIME : ');
  370. gotoxy(44,25); write(time);
  371.  
  372. enemy;
  373. gotoxy(2,2);
  374. write('Y');
  375. i:=2; j:=2; xo:=2; yo:=2;
  376. repeat
  377. movement(i,j);
  378. textcolor(yellow);
  379. gotoxy(8,25); write(sec);
  380. gotoxy(29,25); write(SCORE);
  381.  
  382. until (k=#27)or(d=0)or(sec<=0)or(kt=1);
  383. assign(f,fout); reset(f); read(f,fake); close(f);
  384. if score>fake then begin
  385. assign(f,fout); rewrite(f);
  386. write(f,score);
  387. end;
  388.  
  389. end;
  390. procedure head;
  391. begin
  392. writeln('Ok 1st you need to know is this game is f****** simple !');
  393. delay(1000);
  394. writeln('Use arrow keys to move and asdw to shot ');
  395. delay(1000);
  396. writeln('That is .... so f**** play it !');
  397. readln;
  398. clrscr;
  399. textcolor(green);
  400. gotoxy(34,1); write('T'); delay(200);
  401. gotoxy(35,1); write('H'); delay(200);
  402. gotoxy(36,1); write('E'); delay(200);
  403. gotoxy(38,1); write('H'); delay(200);
  404. gotoxy(39,1); write('U'); delay(200);
  405. gotoxy(40,1); write('N'); delay(200);
  406. gotoxy(41,1); write('T'); delay(200);
  407. gotoxy(42,1); write('E'); delay(200);
  408. gotoxy(43,1); write('R'); delay(200);
  409. gotoxy(45,1); write('G');delay(200);
  410. gotoxy(45,1); write('GA');delay(200);
  411. gotoxy(45,1); write('GAM');delay(200);
  412. gotoxy(45,1); write('GAME');delay(200);
  413. gotoxy(1,25); write('press ESC to quit ');
  414. gotoxy(35,2); Delay(600);
  415. repeat
  416. delay(650);
  417. write(' press enter ');
  418. Delay(679);
  419. gotoxy(35,2); clreol;
  420. until keypressed;
  421. textcolor(white);
  422. end;
  423.  
  424. procedure menu ;
  425. var answer :char; x,y,po:int; f:text;
  426. ch :array[1..3] of string;
  427. begin
  428. ch[1]:='PLAY'; ch[2]:='OPTION'; ch[3]:='HIGH SCORE';
  429. textcolor(green);
  430. gotoxy(34,3); write('PLAY'); x:=34; y:=3; po:=1; {position}
  431. textcolor(white);
  432. gotoxy(34,4); write('OPTION dont click i''vent done yet');
  433. gotoxy(34,5); write('HIGH SCORE dont click i''vent done yet');
  434. repeat
  435. answer:=readkey;
  436. case answer of
  437. 'H': if y-1>=3 then begin
  438. gotoxy(x,y); textcolor(white); write(ch[po]);
  439. y:=y-1; po:=po-1;
  440. gotoxy(x,y); textcolor(green); write(ch[po]);
  441. end;
  442. 'P': if y+1<=5then begin
  443. gotoxy(x,y); textcolor(white); write(ch[po]);
  444. y:=y+1; po:=po+1;
  445. gotoxy(x,y); textcolor(green); write(ch[po]);
  446. end;
  447. end;
  448. until answer=' ';
  449. if y=3 then exit else
  450. if y=5 then
  451. begin
  452. assign(f,fout); reset(f);
  453. read(f,score); close(f);
  454. clrscr;
  455. gotoxy(35,5); write('YOUR SCORE : ',score);
  456. answer:=readkey; repeat until answer=' ';
  457. clrscr;
  458. menu;
  459. end;
  460.  
  461.  
  462. end;
  463. var i,j:int; t:char;
  464. begin
  465.  
  466. repeat
  467. textbackground(black); textcolor(yellow); clrscr;
  468. for i:=1 to 25 do for j:=1 to 80 do begin write('Y'); end;
  469. clrscr; head; kt:=0; time:=0; t:=readkey; clrscr;
  470. if t=#27 then halt;
  471. menu; clrscr;
  472. textbackground(red); textcolor(green);
  473. for i:=1 to 25 do for j:=1 to 80 do begin write('B'); end;
  474. clrscr; textcolor(white);
  475. write(' Remember to press ESC while playing if u wanted to quit ! ');
  476. delay(1800);
  477. play; clrscr;
  478.  
  479. textbackground(white);
  480. textcolor(red);
  481. for i:=1 to 25 do for j:=1 to 80 do begin write('I'); end;
  482. clrscr;
  483. textcolor(black);
  484. gotoxy(33,5); write('T'); delay(121);
  485. gotoxy(33,5); write('TH'); delay(121);
  486. gotoxy(33,5); write('THA'); delay(121);
  487. gotoxy(33,5); write('THAN'); delay(121);
  488. gotoxy(33,5); write('THANK'); delay(121);
  489. gotoxy(33,5); write('THANKS'); delay(121);
  490. gotoxy(33,5); write('THANKS F'); delay(121);
  491. gotoxy(33,5); write('THANKS FO'); delay(121);
  492. gotoxy(33,5); write('THANKS FOR '); delay(121);
  493. gotoxy(33,5); write('THANKS FOR P'); delay(121);
  494. gotoxy(33,5); write('THANKS FOR PL'); delay(121);
  495. gotoxy(33,5); write('THANKS FOR PLA'); delay(121);
  496. gotoxy(33,5); write('THANKS FOR PLAY'); delay(121);
  497. gotoxy(33,5); write('THANKS FOR PLAYI'); delay(121);
  498. gotoxy(33,5); write('THANKS FOR PLAYIN'); delay(121);
  499. gotoxy(33,5); write('THANKS FOR PLAYING'); delay(121);
  500. gotoxy(35,6); write('YOUR SCORE : ',score); delay(400);
  501. gotoxy(35,7); write('YOUR TIME : ',time); delay(400);
  502. gotoxy(36,8);
  503. gotoxy(1,25);
  504. write('press ESC to quit ');
  505. gotoxy(36,8);
  506. repeat
  507. delay(650);
  508. write(' press enter ');
  509. Delay(679);
  510. gotoxy(36,8); clreol;
  511. until keypressed;
  512. t:=readkey;
  513. until t=#27;
  514. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement