Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. {Dungeon, for Turbo/FreePascal, http://rudih.info
  2. This game is a text-based RPG which has:
  3. A random dungeon, hit points, an inventory,
  4. merchants, enemies, money.}
  5.  
  6. program Dungeon;
  7.  
  8. type dunarray = array[1..100] of byte;
  9. var room: dunarray;
  10. column, row, y, scratch, count, GP, HP, enemyhp: integer;
  11. user, enemyname: string[20];
  12. armour, knife: byte; {0=not avail 1=possess}
  13.  
  14.  
  15. procedure normal;
  16. begin
  17. writeln('You are in a dungeon room. HP = ',HP);
  18. writeln('[Q]uit - [I]nventory - [M]ap - Move [N],[S],[E],[W]?');
  19. readln(user);
  20. if (length(user)=1) then user:=upcase(user);
  21. if user='Q' then halt;
  22. if user='I' then
  23. begin
  24. write('Inventory: GP=',GP);
  25. if armour=1 then write(' -Armour');
  26. if knife=1 then write(' -Knife');
  27. writeln;
  28. end;
  29. if user='N' then
  30. begin
  31. scratch:=y-10;
  32. if (row=0) or(room[scratch]=0) or(room[scratch]=2) then
  33. begin
  34. writeln('North is blocked.');
  35. end
  36. else y:=y-10;
  37. end;
  38. if user='S' then
  39. begin
  40. scratch:=y+10;
  41. if (row=9) or(room[scratch]=0) or(room[scratch]=2) then
  42. begin
  43. writeln('South is blocked.');
  44. end
  45. else y:=y+10;
  46. end;
  47. if user='E' then
  48. begin
  49. scratch:=y+1;
  50. if (column=9) or(room[scratch]=0) or(room[scratch]=2) then
  51. begin
  52. writeln('East is blocked.');
  53. end
  54. else y:=y+1;
  55. end;
  56. if user='W' then
  57. begin
  58. scratch:=y-1;
  59. if (column=0) or(room[scratch]=0) or(room[scratch]=2) then
  60. begin
  61. writeln('West is blocked.');
  62. end
  63. else y:=y-1;
  64. end;
  65. end; {normal}
  66.  
  67. procedure shop;
  68. begin
  69. writeln('There is a prisoner here.');
  70. writeln('He asks you if you want to buy something [y/n]:');
  71. readln(user);
  72. if (length(user)=1) then user:=upcase(user);
  73. if user='Y' then
  74. begin
  75. writeln('Which item:');
  76. writeln('[1]armour-5GP [2]knife-10GP [3]potion-3GP');
  77. readln(scratch);
  78. if (length(user)=1) then user:=upcase(user);
  79. if (scratch=1) and (gp>4) then
  80. begin
  81. Writeln('You buy the armour.');
  82. GP:=GP-5;
  83. armour:=1;
  84. end;
  85. if (scratch=2) and (gp>9) then
  86. begin
  87. writeln('You buy the knife.');
  88. GP:=GP-10;
  89. knife:=1;
  90. end;
  91. if (scratch=3) and (gp>2) then
  92. begin
  93. writeln('You buy the potion & drink it (+6HP).');
  94. GP:=GP-3;
  95. HP:=HP+6;
  96. end;
  97. end;
  98. writeln('The prisoner disappears.');
  99. room[y]:=1;
  100. end; {shop}
  101.  
  102. procedure makedun;
  103. begin
  104. {the dungeon is laid out 10x10 so 2 is row 0 column 1
  105. Key:-
  106. 0=walled out 1=ordinary room
  107. 2=walled out 3=room with 3GP
  108. 4=enemy: snake 5=enemy: guard
  109. 6=enemy: skeleton 7=merchant
  110. 8=beginning 9=end}
  111. randomize;
  112. scratch:=0;
  113. for count:=1 to 100 do {randomly generate dungeon}
  114. begin
  115. scratch:=random(8);
  116. room[count]:=scratch;
  117. end;
  118. scratch:=random(100);
  119. room[scratch]:=8;
  120. y:=scratch; {mark beginning}
  121. scratch:=random(100);
  122. room[scratch]:=9; {mark end}
  123. end; {makedun}
  124.  
  125. procedure drawmap;
  126. begin
  127. for count:=1 to 100 do {draw dungeon}
  128. begin
  129. if count=y then write('* ') else write('. ');
  130. if count mod 10=0 then writeln;
  131. end;
  132. end; {drawmap}
  133.  
  134. procedure getcoord; {the coords including 0}
  135. begin
  136. if y<10 then row:=0;
  137. scratch:=0;
  138. while scratch<10 do
  139. begin
  140. if y>=scratch*10 then row:=scratch;
  141. scratch:=scratch+1;
  142. end;
  143. column:=(y mod 10)-1;
  144. if column=-1 then column:=9;
  145. end; {getcoord}
  146.  
  147. procedure combat;
  148. begin
  149. if room[y]=4 then
  150. begin
  151. enemyname:='snake';
  152. enemyhp:=1;
  153. end;
  154. if room[y]=5 then
  155. begin
  156. enemyname:='gaurd';
  157. enemyhp:=2;
  158. end;
  159. if room[y]=6 then
  160. begin
  161. enemyname:='skeleton';
  162. enemyhp:=6;
  163. end;
  164. writeln('You are attacked by a ',enemyname,' with ',enemyhp,' HP.');
  165. randomize;
  166. while enemyhp>0 do
  167. begin
  168. scratch:=random(2);
  169. if scratch=1 then
  170. begin
  171. writeln('You attack the ',enemyname,'.');
  172. scratch:=random(3)+1;
  173. if knife=1 then scratch:=scratch+3;
  174. writeln('The ',enemyname,' loses ',scratch,' HP.');
  175. enemyhp:=enemyhp-scratch;
  176. end
  177. else
  178. begin
  179. writeln('The ',enemyname,' attacks.');
  180. scratch:=random(3)+1;
  181. if (armour=1) and (scratch>1) then scratch:=scratch-2;
  182. writeln('You lose ',scratch,' HP.');
  183. hp:=hp-scratch;
  184. if hp<1 then
  185. begin
  186. writeln('You have been killed. Game over. Enter quits.');
  187. readln(user);
  188. halt;
  189. end;
  190. end;
  191. end;
  192. writeln('You killed the ',enemyname,'.');
  193. writeln('The enemy drops 1 GP - Press enter.');
  194. readln(user);
  195. GP:=GP+1;
  196. room[y]:=1;
  197. end; {combat}
  198.  
  199.  
  200. begin
  201. writeln('---DUNGEON---');
  202. write('[E]asy or [H]ard game> ');
  203. readln(user);
  204. if length(user)=1 then user:=upcase(user);
  205. if user='E' then HP:=16;
  206. if user='H' then HP:=12;
  207. if (user<>'E') and (user<>'H') then halt;
  208. GP:=0;
  209. armour:=0;
  210. knife:=0;
  211. makedun;
  212. drawmap;
  213. while(user<>'Q') do
  214. begin
  215. user:='';
  216. getcoord;
  217. writeln('column=',column,' row=',row);
  218. if (room[y]=1) or (room[y]=8) then normal;
  219. if user='M' then drawmap;
  220. if room[y]=3 then
  221. begin
  222. writeln('You find 2 gold piece on the floor.');
  223. GP:=GP+2;
  224. room[y]:=1;
  225. end;
  226. if (room[y]=4) or (room[y]=5) or (room[y]=6) then combat;
  227. if room[y]=7 then shop;
  228. if room[y]=9 then
  229. begin
  230. writeln('You have found the way out! -THE END- enter quits');
  231. readln(user);
  232. halt;
  233. end;
  234. end;
  235. end. {program}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement