Advertisement
Zung_the_great

Pascal board game-battle sea

Jan 16th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.73 KB | None | 0 0
  1. {battle sea version 2.2.1}
  2. {copy right turbo pascal_free pascal}
  3. {data file sea_coin.txt create your own file name sea_coin.txt in the same folder with your Pascal program's folder }
  4. {run by free Pascal 2.6.4}
  5. {coppy this code !!! i can't post a link}
  6. program sorry_for_party_the_sea;
  7. uses crt,graph;
  8. const
  9. finp = 'sea_coin.txt';
  10. type
  11. int = integer;
  12. arr = array[1..100] of int;
  13. arr2 = array[1..10, 1..10] of string;
  14. var
  15. a,b,a1,a2 : arr2;
  16. live1,live2 : int;
  17. n,m,coin : int;
  18. f : text;
  19. ex,bom,rada : int;
  20. answer,t : int;
  21. procedure menu;
  22. var buy:int;
  23. begin
  24. clrscr;
  25. assign(f,finp); reset(f);
  26. readln(f,coin);
  27. readln(f,ex);
  28. readln(f,bom);
  29. readln(f,rada);
  30. close(f);
  31. writeln('YOUR coin: ',coin,' $');
  32. writeln('YOUR ex ship: ',ex);
  33. writeln('YOUR boom: ',bom);
  34. writeln('YOUR rada: ',rada);
  35. writeln('Hey wanna play ?');
  36. writeln('1 PLAY');
  37. writeln('2 STORE');
  38. writeln('3 INSTRUCTION');
  39. writeln('4 QUIT');
  40. readln(answer);
  41.  
  42. if answer=4 then halt
  43. else if answer=2 then
  44. begin
  45.  
  46. clrscr;
  47. writeln('welcome to battle ship store ! ');
  48. delay(1000);
  49. writeln('here comes the buy list: ');
  50. delay(1000);
  51. writeln('1: an extra ship 25 $');
  52. writeln('2: boomed all the ship 32 $');
  53. writeln('3: rada 39 $');
  54. writeln('if wannna quit so type 0');
  55. writeln('YOUR COIN: ',coin,' $ ');
  56. if coin>25 then
  57. begin
  58. readln(buy);
  59. if buy<>0 then
  60.  
  61. repeat
  62. if (buy=1)and(coin>=25) then begin
  63. coin:=coin-25;
  64. ex :=ex+1;
  65. end
  66. else if(buy=1)and(coin<25) then
  67. begin
  68. writeln('u can''t buy this');
  69. readln;
  70. end;
  71.  
  72. if (buy=2)and(coin>=32) then begin
  73. coin:=coin-32;
  74. bom :=bom+1;
  75. end
  76. else if(buy=2)and(coin<32) then
  77. begin
  78. writeln('u can''t buy this');
  79. readln;
  80. end;
  81.  
  82. if (buy=3)and(coin>=39) then begin
  83. coin:=coin-39;
  84. rada:=rada+1;
  85. end
  86. else if (buy=3)and(coin<39) then
  87. begin
  88. writeln('u can''t buy this');
  89. readln;
  90. end;
  91. writeln;
  92. writeln('YOUR COIN: ',coin,' $ ');
  93. writeln;
  94. write('_ no=0_ buy more ?: '); readln(buy);
  95. if coin <25 then
  96. begin
  97. write('you ''ve out of money !');
  98. readln;
  99. break;
  100. end;
  101.  
  102. until(coin<25)or(buy=0);
  103.  
  104. end
  105. else begin
  106.  
  107. clrscr;
  108. writeln('But');
  109. write('You don''t have enough money man ');
  110. readln;
  111. end;
  112. assign(f,finp); rewrite(f);
  113. writeln(f,coin);
  114. writeln(f,ex);
  115. writeln(f,bom);
  116. writeln(f,rada);
  117. close(f);
  118. menu;
  119. end
  120. else if answer=3 then
  121. begin
  122. clrscr;
  123. writeln('INSTRUCTION: ');
  124. writeln('to create ship you just have to type the coordinates ');
  125. writeln('example: 3 2 ');
  126. writeln;
  127. writeln('to shot the ship you just have to input the coordinates ');
  128. writeln('example: 9 9 ');
  129. writeln;
  130. writeln('you have 2 shot per time and so do the enemy ');
  131. writeln;
  132. writeln('boom can just effect in one line :) ');
  133. writeln;
  134. writeln('please do not type any words or the program will be crashed ');
  135. writeln;
  136. writeln('advoid playing so many time ! (it"s gonna be crashed) ');
  137. writeln;
  138. writeln('type your ship > 0 and <81 ');
  139. writeln;
  140. writeln('while playing you can pick up some item from enemy ');
  141. writeln;
  142. writeln('you will cost 10 $ for each guard ship ');
  143. writeln;
  144. writeln('lost captain means you have nothing but surrender ');
  145. writeln;
  146. write('press enter to next page');
  147. readln;
  148. clrscr;
  149. writeln('CREATE BY ');
  150. writeln('Zung the great ');
  151. writeln('Battle sea version 2.2.4');
  152. writeln('Enjoy the game !');
  153. writeln;
  154. write('press enter to return menu');
  155. readln;
  156. menu;
  157. end;
  158. end;
  159.  
  160.  
  161. procedure tile;
  162. var i:int;
  163. begin
  164. clrscr;
  165. textcolor(3);
  166. write('~~~~Hey hey hey welcome to~~~~');
  167. delay(1000);
  168. clrscr;
  169. write('~~~~The really old game~~~~');
  170. delay(1000);
  171. clrscr;
  172. write('~~~~where u can shot in a really ridiculous board~~~~');
  173. delay(1000);
  174. clrscr;
  175. write('this is :::::::');
  176. delay(1900);
  177. clrscr;
  178. write('S');
  179. delay(600);
  180. clrscr;
  181. write('SE');
  182. delay(600);
  183. clrscr;
  184. write('SEA');
  185. delay(600);
  186. clrscr;
  187. writeln('SEA');
  188. writeln('BATLE!!');
  189. writeln('Press enter');
  190. repeat until keypressed;
  191.  
  192. write('loading ');
  193. for i:=1 to 5 do begin write('. '); delay(600); end;
  194.  
  195. end;
  196. (* ------------------------------------------------------------ *)
  197.  
  198.  
  199. function fin(var a:arr2; i,j:int):boolean;
  200. begin
  201. fin:=false;
  202. if a[i,j]='0' then begin
  203. fin:=true;
  204. a[i,j]:='1';
  205. exit;
  206. end;
  207. end;
  208.  
  209. procedure print(var a:arr2);
  210. var i,j:int;
  211. begin
  212. textcolor(black);
  213. write(' ');
  214. for i:=1 to 9 do write(i,' ');
  215. for i:=1 to 2 do writeln;
  216. for i:=1 to 9 do
  217. begin
  218. write(i,': ');
  219.  
  220. for j:=1 to 9 do if a[i,j]='~' then write(a[i,j],' ')
  221. else if (a[i,j]='#') or (a[i,j]='^') then
  222. begin
  223. textcolor(12);
  224. write(a[i,j],' ');
  225. textcolor(black);
  226. end
  227. else if (a[i,j]='0') then
  228. begin
  229. textcolor(10);
  230. write(a[i,j],' ');
  231. textcolor(black);
  232. end
  233. else if (a[i,j]='x') then
  234. begin
  235. textcolor(yellow);
  236. write(a[i,j],' ');
  237. textcolor(black);
  238. end;
  239. writeln;
  240. end;
  241. end;
  242.  
  243. procedure add;
  244. var i,j,k:int;
  245. begin
  246. clrscr;
  247. textbackground(white);
  248. textcolor(black);
  249.  
  250. write('input your ship ( <= 81 ): '); readln(n);
  251. while (n<1)or(n>81) do
  252. begin
  253. write('hey add again man: ');
  254. readln(n);
  255. end;
  256. while (n>1) and(coin<n*10) do
  257. begin
  258. write('hey add again man, you dont have enough money !');
  259. readln(n);
  260. end;
  261. while (n<1) do
  262. begin
  263. write('hey add again man: ');
  264. readln(n);
  265. end;
  266.  
  267. write('input enemy ship ( <= 81 ): '); readln(m);
  268. while (m<1)or(m>81) do
  269. begin
  270. write('hey add again man: ');
  271. readln(m);
  272. end;
  273. clrscr;
  274. for i:=1 to 9 do
  275. for j:=1 to 9 do begin
  276. a[i,j]:='~';
  277. a2[i,j]:='0';
  278. end;
  279. clrscr;
  280. writeln('let''s add your battle ship');
  281. writeln('x and y');
  282.  
  283. write('add head master: '); readln(i,j);
  284. while (i<1)or(j<1)or(i>9)or(j>9) do
  285. begin
  286. write('add again: '); readln(i,j);
  287. end;
  288. a[i,j]:='^';
  289. a2[i,j]:='1';
  290. print(a);
  291. if n>1 then writeln('hey from now each guard ship costs 10 $ ');
  292. for k:=1 to n-1 do
  293. begin
  294. write('add guard ship ',k,': '); readln(i,j);
  295. while (i<1)or(j<1)or(i>9)or(j>9)or(not fin(a2,i,j)) do
  296. begin
  297. write('add guard ship ',k,' again: '); readln(i,j);
  298. end;
  299. a[i,j]:='#';
  300. clrscr;
  301. print(a);
  302. coin:=coin-10;
  303. writeln('you have ',coin-10,' $');
  304. end;
  305. writeln('so it looks like: ');
  306. write(' ');
  307. for i:=1 to 9 do write(i,' ');
  308. for i:=1 to 2 do writeln;
  309. for i:=1 to 9 do
  310. begin
  311. write(i,': ');
  312.  
  313. for j:=1 to 9 do if a[i,j]='~' then write(a[i,j],' ')
  314. else
  315. begin
  316. textcolor(11);
  317. write(a[i,j],' ');
  318. textcolor(black);
  319. end;
  320. writeln;
  321. end;
  322.  
  323. for i:=1 to 9 do for j:=1 to 9 do
  324. begin
  325. a1[i,j]:='0';
  326. end;
  327.  
  328. writeln('press enter');
  329.  
  330. repeat until keypressed;
  331. write('loading ');
  332. for i:=1 to 5 do begin write('. '); delay(591); end;
  333. end;
  334.  
  335. procedure comadd;
  336. var i,j,l,xoa:int;
  337. begin
  338. textcolor(15);
  339. for i:=1 to 9 do
  340. for j:=1 to 9 do b[i,j]:='~';
  341.  
  342. randomize;
  343. repeat
  344. i:=random(10);
  345. until (i>0);
  346. repeat
  347. j:=random(10);
  348. until(j>0);
  349.  
  350. a1[i,j]:='1';
  351. b[i,j]:='^';
  352. i:=1; j:=1;
  353. for l:=1 to m-1 do
  354. begin
  355. repeat
  356. repeat
  357. i:=random(10);
  358. until(i>0);
  359.  
  360. repeat
  361. j:=random(10);
  362. until(j>0);
  363. until fin(a1,i,j);
  364. b[i,j]:='#';
  365. end;
  366.  
  367. for i:=1 to 9 do for j:=1 to 9 do
  368. begin
  369. a1[i,j]:='0';
  370. end;
  371. end;
  372.  
  373.  
  374. procedure complay(var i,j:int);
  375. var xoa:int ;
  376. begin
  377. randomize;
  378. repeat
  379. repeat
  380. i:=random(10);
  381. until(i>0);
  382. repeat
  383. j:=random(10);
  384. until(j>0);
  385. until fin(a1,i,j);
  386. end;
  387.  
  388. procedure letsplay;
  389. var i,j,d :int;
  390. c :arr2;
  391. count,use:int;
  392. k,m :int;
  393. pickup :int;
  394. f :string;
  395. o :text;
  396. begin
  397.  
  398. for i:=1 to 9 do
  399. for j:=1 to 9 do c[i,j]:='~';
  400. for i:=1 to 9 do for j:=1 to 9 do
  401. begin
  402. a2[i,j]:='0';
  403. end;
  404. {its item time !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  405. d:=0;
  406. if (ex>0)or(bom>0)or(rada>0) then
  407. begin
  408. writeln('HEY !');
  409. writeln;
  410. writeln('USE items extra ? (type 1): ');
  411. writeln('USE items boomed ? (type 2): ');
  412. writeln('USE items rada ? (type 3): ');
  413. writeln('NO=0 ');
  414. writeln;
  415. writeln('YOUR ex ship: ',ex);
  416. writeln('YOUR boom: ',bom);
  417. writeln('YOUR rada: ',rada);
  418. readln(answer);
  419.  
  420. if (answer=1)or(answer=2)or(answer=3) then
  421. repeat
  422.  
  423. if (answer=2)and(bom>0) then
  424. begin
  425. count:=0;
  426. bom:=bom-1;
  427. write('type a line u what to bommed it: '); readln(use);
  428. for j:=1 to 9 do
  429. if (b[use,j]='#')or(b[use,j]='^') then
  430. begin
  431. count:=count+1;
  432. c[use,j]:='x';
  433. a2[use,j]:='1';
  434. live2:=live2-1;
  435. end else
  436. begin
  437. a2[use,j]:='1';
  438. c[use,j]:='0';
  439. end;
  440. if count=0 then writeln('man u hit no ship ! ')
  441. else writeln('good you hit ',count,' ship');
  442. writeln;
  443. writeln('press enter');
  444. repeat until keypressed;
  445. break;
  446. end
  447. else if(answer=2)and(bom=0) then
  448. begin
  449. writeln('na you don''t have any, chose again !: ');
  450. readln(answer);
  451. end;
  452.  
  453. if (answer=1)and(ex>0) then
  454. begin
  455. d:=2;
  456. ex:=ex-1;
  457. break;
  458. end
  459. else if (answer=1)and(ex=0) then
  460. begin
  461. writeln('na you don''t have any, chose again !: ');
  462. readln(answer);
  463. end;
  464. if (answer=3)and(rada>0) then
  465. begin
  466. d:=3;
  467. rada:=rada-1;
  468. writeln('get ready to sea the enemy"sea ');
  469. writeln('you have few second to explore before the enemy find us: ');
  470. writeln('the map will be in white color');
  471. delay(3100);
  472. textbackground(white);
  473. for i:=1 to 9 do
  474. begin
  475. for j:=1 to 9 do write(b[i,j],' ');
  476. writeln;
  477. end;
  478. delay(469);
  479. clrscr;
  480. write('so fast right ? :)');
  481. repeat until keypressed;
  482. break;
  483. end
  484. else if (answer=3)and(rada=0) then
  485. begin
  486. writeln('na you don''t have any, chose again !: ');
  487. readln(answer);
  488. end;
  489.  
  490. until answer=0
  491.  
  492. else write('na u don''t have any item ');
  493. end;
  494. {playing time !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  495. textbackground(yellow);
  496. repeat
  497. for count:=1 to 2 do
  498. begin
  499. clrscr;
  500. writeln('THE ENEMY''S SEA');
  501. print(c);
  502. writeln('your turn :');
  503. write('input your fire !! : '); readln(i,j);
  504. if (i=99) and (j=99) then
  505. begin
  506. clrscr;
  507. write('input cheat '); readln(f);
  508.  
  509. if (f='edge eyes') then
  510. begin
  511. print(b);
  512. delay(3000);
  513. clrscr;
  514. end;
  515. if (f='fire balls') then
  516. for k:=1 to 9 do
  517. for m:=1 to 9 do if b[k,m]='#' then
  518. begin
  519. c[k,m]:='x';
  520. a2[k,m]:='1';
  521. end;
  522. if (f='shield protected') then
  523. for k:=1 to 9 do
  524. for m:=1 to 9 do if a[k,m]='^' then a1[k,m]:='1';
  525. if (f='surrender') then
  526. begin
  527. live1:=0;
  528. writeln('ok that was your choice ! ');
  529. writeln('you heard it men, fall back');
  530. writeln('press enter');
  531. readln;
  532. exit;
  533. end;
  534. if (f='coinnage') then
  535. begin
  536. coin:=coin+99;
  537. writeln('your coin: ',coin);
  538. writeln('press enter');
  539. readln;
  540. end;
  541. if (f='black death') then
  542. begin
  543. live2:=0;
  544. writeln('the enemy has fallen in flame ! ');
  545. writeln('you win the battle but not so glory !');
  546. writeln('press enter');
  547. readln;
  548. exit;
  549. end;
  550.  
  551. i:=10;
  552. j:=10;
  553. clrscr;
  554. writeln('THE ENEMY''S SEA');
  555. print(c);
  556. writeln('your turn :');
  557. end;
  558.  
  559.  
  560. while (i>9)or(j>9)or(i<1)or(j<1)or(not fin(a2,i,j)) do
  561. begin
  562. write('input your fire again !! : '); readln(i,j);
  563. end;
  564.  
  565. if (b[i,j]='#') then
  566. begin
  567. clrscr;
  568. writeln('we''ve hit it');
  569. writeln('they still have ',live2-1,' ship (hang on guy !)');
  570. live2:=live2-1;
  571. c[i,j]:='x';
  572. randomize;
  573. pickup:=random(330);
  574. if pickup=1 then
  575. begin
  576. writeln('hey you have picked up from that ship an extra item !');
  577. ex:=ex+1;
  578. end else if pickup=21 then
  579. begin
  580. writeln('hey you have picked up from that ship an boom item !');
  581. bom:=bom+1;
  582. end else if pickup=144 then
  583. begin
  584. writeln('hey you have picked up from that ship an rada item !');
  585. rada:=rada+1;
  586. end else if pickup=300 then
  587. begin
  588. writeln('lucky for you, an bonus coin : + 20 $');
  589. coin:=coin+20;
  590. end;
  591. readln;
  592. assign(o,finp); rewrite(o);
  593. writeln(o,coin);
  594. writeln(o,ex);
  595. writeln(o,bom);
  596. writeln(o,rada);
  597. close(o);
  598.  
  599.  
  600. end else
  601. if (b[i,j]='^') then
  602. begin
  603. clrscr;
  604. live2:=0;
  605. writeln('we hit the leader ship !');
  606. delay(2000);
  607. writeln('victory is our ');
  608. writeln('press enter');
  609. readln;
  610. exit;
  611. end
  612. else c[i,j]:='0';
  613. end;
  614. clrscr;
  615. writeln('opponent''s turn :');
  616.  
  617. for count:=1 to 2 do
  618. begin
  619. complay(i,j);
  620. if (a[i,j]='#') then
  621. begin
  622. writeln('they hit it');
  623. writeln('we have ',live1-1,' ship');
  624. live1:=live1-1;
  625. a[i,j]:='x';
  626. readln;
  627. end
  628. else
  629. if (a[i,j]='^') then
  630. begin
  631. live1:=0;
  632. writeln('Nooo ! Our leader has fallen');
  633. delay(2000);
  634. writeln('the captain rest in peace !');
  635. delay(2000);
  636. writeln('fall back men we lose !');
  637. delay(2000);
  638. print(a);
  639. repeat until keypressed;
  640. for i:=1 to 9 do for j:=1 to 9 do
  641. begin
  642. a[i,j]:='~';
  643. a2[i,j]:='0';
  644. a1[i,j]:='0';
  645. end;
  646. exit;
  647. end
  648. else a[i,j]:='0';
  649. writeln('_they fired at ',i,' ',j,'_');
  650. end;
  651. writeln;
  652. writeln('OUR SEA: ');
  653. print(a);
  654.  
  655. repeat until keypressed;
  656. until (live1=0)or(live2=0);
  657.  
  658.  
  659. if (d=2)and(live1=0) then
  660. begin
  661. write('wait you can add extra ship : '); readln(i,j);
  662. while (i<1)or(j<1)or(i>9)or(j>9)or(not fin(a2,i,j)) do
  663. begin
  664. write('add again: '); readln(i,j);
  665. end;
  666. a[i,j]:='#';
  667. a2[i,j]:='0';
  668. print(a);
  669. live1:=1;
  670. letsplay;
  671. end;
  672. end;
  673.  
  674. procedure theend;
  675. begin
  676. if live1=0 then
  677. begin
  678. writeln(' the battle was so rude !');
  679. delay(1000);
  680. writeln(' but that"s ok ');
  681. delay(1000);
  682. writeln(' try hard next time ! ');
  683. delay(1000);
  684. write('press enter');
  685. repeat until keypressed;
  686. end
  687. else if live2=0 then
  688. begin
  689. writeln(' good job captain !');
  690. delay(1000);
  691. writeln(' wish you luck everytime !');
  692. delay(1000);
  693. write('press enter');
  694. clrscr;
  695. writeln('you now have : ',coin+m,' coin ! ');
  696. repeat until keypressed;
  697. end;
  698. assign(f,finp); rewrite(f);
  699. writeln(f,coin+m);
  700. writeln(f,ex);
  701. writeln(f,bom);
  702. writeln(f,rada);
  703. close(f);
  704. end;
  705.  
  706.  
  707. begin
  708. clrscr;
  709. textbackground(white);
  710. tile;
  711. textcolor(black);
  712.  
  713. repeat
  714.  
  715. textbackground(white);
  716. menu;
  717. add;
  718. clrscr;
  719. live1:=n;
  720. live2:=m;
  721. writeln;
  722. comadd;
  723. clrscr;
  724. textbackground(yellow);
  725. letsplay;
  726. clrscr;
  727. theend;
  728.  
  729. until answer=4;
  730. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement