Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.96 KB | None | 0 0
  1. frame world;
  2. default x_coord is 0 and % initial values
  3. default y_coord is 0 and
  4. default monster_limit is 6 and
  5. default cellCoord is 9000.
  6.  
  7. frame monster;
  8. default monster_x is null and
  9. default monster_y is null and
  10. default monster_state is alive.
  11.  
  12. instance monster0 is a monster;
  13. monster_type is goblin.
  14.  
  15. instance monster1 is a monster;
  16. monster_type is goblin.
  17.  
  18. instance monster2 is a monster;
  19. monster_type is goblin.
  20.  
  21. instance monster3 is a monster;
  22. monster_type is goblin.
  23.  
  24. instance monster4 is a monster;
  25. monster_type is ogre.
  26.  
  27. instance monster5 is a monster;
  28. monster_type is spider.
  29.  
  30.  
  31.  
  32.  
  33. frame key1;
  34. default key_x is null and
  35. default key_y is null.
  36.  
  37. frame global; % can refer to slots without referring to global
  38. default world_extent is 5 and % 5 x 5 grid. Can change this
  39. default hero_x is 0 and
  40. default hero_y is 0 and
  41. default hero_health is 100 and
  42. default hero_name is 'Dr Graham Winstanley the Magnificent' and
  43. default hero_has_key is 0 and
  44. default number_n is 0 and
  45. default number_m is 0 and
  46. default cellCounter is 9000.
  47.  
  48. action cleanse_world;
  49. cellCounter becomes 9000 and
  50. hero_x becomes 0 and
  51. hero_y becomes 0 and
  52. hero_health becomes 100 and
  53. for every M is an instance of monster do
  54. M`s monster_x becomes null and
  55. M`s monster_y becomes null and
  56. M`s monster_state becomes alive
  57. end for and
  58. number_n becomes 0 and
  59. number_m becomes 0 and
  60. key1`s key_y becomes null and
  61. key1`s key_x becomes null.
  62.  
  63. action cleanse_world2;
  64. cellCounter becomes 9000 and
  65. hero_x becomes 0 and
  66. hero_y becomes 0 and
  67. for every M is an instance of monster do
  68. M`s monster_x becomes null and
  69. M`s monster_y becomes null and
  70. M`s monster_state becomes alive
  71. end for and
  72. hero_has_key becomes 0 and
  73. number_n becomes 0 and
  74. number_m becomes 0.
  75.  
  76. action damage;
  77. hero_health becomes hero_health-20.
  78.  
  79.  
  80. action create_world; % main action
  81. do
  82. for A from 0 to world_extent^2 step world_extent % outer for
  83. do
  84. for X from 0 to world_extent-1
  85. do
  86. create_instance_name(X+A,Y) and % another action to create a name
  87. new_instance(Y,world) and % make the instance
  88. Y`s x_coord becomes X and % update the X coordinate
  89. Y`s y_coord becomes A/world_extent and % update the Y coordinate
  90. Y`s cellCoord becomes cellCounter and
  91. cellCounter becomes cellCounter+1
  92. end for
  93. end for .
  94.  
  95. action create_instance_name(X,Y); % the create name action
  96. do
  97. number_atom(X,Z) and % make the number into an atom (type change)
  98. cat({'cell_',Z},Y,L). % concatenate the 2 atoms to make cell_0 (say)
  99.  
  100.  
  101.  
  102. action create_world2; % main action
  103. do
  104. for A from 0 to world_extent^2 step world_extent % outer for
  105. do
  106. for X from 0 to world_extent-1
  107. do
  108. create_instance_name(X+A,Y) and % another action to create a name
  109. new_instance(Y,world) and % make the instance
  110. Y`s x_coord becomes X and % update the X coordinate
  111. Y`s y_coord becomes A/world_extent and % update the Y coordinate
  112. Y`s cellCoord becomes cellCounter and
  113. cellCounter becomes cellCounter+1
  114. end for
  115. end for .
  116.  
  117. action create_instance_name(X,Y); % the create name action
  118. do
  119. number_atom(X,Z) and % make the number into an atom (type change)
  120. cat({'cell_',Z},Y,L). % concatenate the 2 atoms to make cell_0 (say)
  121.  
  122.  
  123.  
  124. action move_north;
  125. do check that Current_tile is an instance of world
  126. whose x_coord is hero_x and
  127. whose y_coord is hero_y and
  128. check that Tile_north is an instance of world
  129. whose x_coord is Current_tile`s x_coord and
  130. whose y_coord is Current_tile`s y_coord+1 and
  131. hero_x becomes Tile_north`s x_coord and
  132. hero_y becomes Tile_north`s y_coord and
  133. write('hero ') and
  134. write(hero_x) and
  135. write(' , ') and
  136. write(hero_y) and
  137. draw_hero(Tile_north`s cellCoord,Current_tile`s cellCoord) and
  138. nl.
  139.  
  140. action move_south;
  141. do check that Current_tile is an instance of world
  142. whose x_coord is hero_x and
  143. whose y_coord is hero_y and
  144. check that Tile_south is an instance of world
  145. whose x_coord is Current_tile`s x_coord and
  146. whose y_coord is Current_tile`s y_coord-1 and
  147. hero_x becomes Tile_south`s x_coord and
  148. hero_y becomes Tile_south`s y_coord and
  149. write('hero ') and
  150. write(hero_x) and
  151. write(' , ') and
  152. write(hero_y) and
  153. draw_hero(Tile_south`s cellCoord,Current_tile`s cellCoord) and
  154. nl.
  155.  
  156. action move_east;
  157. do check that Current_tile is an instance of world
  158. whose x_coord is hero_x and
  159. whose y_coord is hero_y and
  160. check that Tile_east is an instance of world
  161. whose x_coord is Current_tile`s x_coord+1 and
  162. whose y_coord is Current_tile`s y_coord and
  163. hero_x becomes Tile_east`s x_coord and
  164. hero_y becomes Tile_east`s y_coord and
  165. write('hero ') and
  166. write(hero_x) and
  167. write(' , ') and
  168. write(hero_y) and
  169. draw_hero(Tile_east`s cellCoord,Current_tile`s cellCoord) and
  170. nl.
  171.  
  172. action move_west;
  173. do check that Current_tile is an instance of world
  174. whose x_coord is hero_x and
  175. whose y_coord is hero_y and
  176. check that Tile_west is an instance of world
  177. whose x_coord is Current_tile`s x_coord-1 and
  178. whose y_coord is Current_tile`s y_coord and
  179. hero_x becomes Tile_west`s x_coord and
  180. hero_y becomes Tile_west`s y_coord and
  181. write('hero ') and
  182. write(hero_x) and
  183. write(' , ') and
  184. write(hero_y) and
  185. draw_hero(Tile_west`s cellCoord,Current_tile`s cellCoord) and
  186. nl.
  187.  
  188.  
  189. action printname;
  190. do write(hero_name) and
  191. nl.
  192.  
  193. %make the monsters wander
  194.  
  195. action generate_monsters_locations;
  196. do number_n becomes 0 and
  197. repeat
  198. do generate_locations(world_extent-1, number_n)
  199. and number_n becomes number_n+1
  200.  
  201. until number_n is world`s monster_limit
  202. end repeat.
  203.  
  204. action spawn_monster(X,Y,N);
  205. do number_atom(N,Z) and
  206. cat({'monster',Z},A,_) and
  207. write(A) and
  208. A`s monster_x becomes X and
  209. A`s monster_y becomes Y and
  210. nl and
  211. write(A`s monster_x) and
  212. nl and
  213. write(A`s monster_y) and
  214. nl.
  215.  
  216. %Generate the key location in a random location, but not in 0,0
  217. action generate_key_location;
  218. do generate_key_location(world_extent-1).
  219.  
  220. %Now spawn key1
  221. action spawn_key1(X,Y);
  222. key1`s key_x becomes X and
  223. key1`s key_y becomes Y.
  224.  
  225. %monster movement
  226.  
  227. %needs re-adapting for monster use
  228.  
  229. action move_monsters;
  230. do for every M is an instance of monster
  231. do
  232. if M`s monster_state is alive then do
  233. random_numby(M) else do nl
  234. end if
  235. end for
  236. and
  237. nl.
  238.  
  239.  
  240.  
  241. action wander(A,B);
  242. if A is 0 then do monster_move_north(B) else
  243. if A is 1 then do monster_move_south(B) else
  244. if A is 2 then do monster_move_east(B) else
  245. if A is 3 then do monster_move_west(B) else do nl
  246. end if end if end if end if
  247. and
  248. nl.
  249.  
  250. action monster_move_north(A);
  251. do check that Current_tile is an instance of world
  252. whose x_coord is A`s monster_x and
  253. whose y_coord is A`s monster_y and
  254. check that Tile_north is an instance of world
  255. whose x_coord is Current_tile`s x_coord and
  256. whose y_coord is Current_tile`s y_coord+1 and
  257. A`s monster_x becomes Tile_north`s x_coord and
  258. A`s monster_y becomes Tile_north`s y_coord and
  259. write(A) and
  260. write(' ') and
  261. write(A`s monster_x) and
  262. write(' , ') and
  263. write(A`s monster_y) and
  264. nl.
  265.  
  266. action monster_move_south(A);
  267. do check that Current_tile is an instance of world
  268. whose x_coord is A`s monster_x and
  269. whose y_coord is A`s monster_y and
  270. check that Tile_south is an instance of world
  271. whose x_coord is Current_tile`s x_coord and
  272. whose y_coord is Current_tile`s y_coord-1 and
  273. A`s monster_x becomes Tile_south`s x_coord and
  274. A`s monster_y becomes Tile_south`s y_coord and
  275. write(A) and
  276. write(' ') and
  277. write(A`s monster_x) and
  278. write(' , ') and
  279. write(A`s monster_y) and
  280. nl.
  281.  
  282. action monster_move_east(A);
  283. do check that Current_tile is an instance of world
  284. whose x_coord is A`s monster_x and
  285. whose y_coord is A`s monster_y and
  286. check that Tile_east is an instance of world
  287. whose x_coord is Current_tile`s x_coord+1 and
  288. whose y_coord is Current_tile`s y_coord and
  289. A`s monster_x becomes Tile_east`s x_coord and
  290. A`s monster_y becomes Tile_east`s y_coord and
  291. write(A) and
  292. write(' ') and
  293. write(A`s monster_x) and
  294. write(' , ') and
  295. write(A`s monster_y) and
  296. nl.
  297.  
  298. action monster_move_west(A);
  299. do check that Current_tile is an instance of world
  300. whose x_coord is A`s monster_x and
  301. whose y_coord is A`s monster_y and
  302. check that Tile_west is an instance of world
  303. whose x_coord is Current_tile`s x_coord-1 and
  304. whose y_coord is Current_tile`s y_coord and
  305. A`s monster_x becomes Tile_west`s x_coord and
  306. A`s monster_y becomes Tile_west`s y_coord and
  307. write(A) and
  308. write(' ') and
  309. write(A`s monster_x) and
  310. write(' , ') and
  311. write(A`s monster_y) and
  312. nl.
  313.  
  314. % combat
  315.  
  316. action combat(X);
  317.  
  318. do for every M is an instance of monster
  319.  
  320. do if M`s monster_state is alive and
  321. M`s monster_x is equal to hero_x and
  322. M`s monster_y is equal to hero_y then do
  323.  
  324. if X is 0 then do
  325. update_status('you have found a monster') and
  326. nl
  327. else do
  328. update_status('a monster has found you') and
  329. nl
  330. end if
  331. and
  332.  
  333. M`s monster_state becomes dead and
  334. cat({M,' has died'},C,_) and
  335. update_status(C) and
  336. nl
  337. else do
  338. nl
  339. end if
  340. end for.
  341.  
  342. %check if we are on the door cell and if we have the key
  343. action check_door;
  344. if hero_x is 4 and
  345. hero_y is 4 and
  346. hero_has_key is 1 then do
  347. start2
  348. else if hero_x is 4 and
  349. hero_y is 4 and
  350. hero_has_key is 0 and
  351. key1`s key_x is not null then do
  352. update_status('You need the key to go up to the next level')
  353. else do
  354. nl
  355. end if
  356. end if.
  357. %check if we just found a key
  358. action check_key;
  359. if hero_x is key1`s key_x and
  360. hero_y is key1`s key_y then do
  361. hero_has_key becomes 1 and
  362. update_status('You found a key!') and
  363. key1`s key_x becomes null and
  364. key1`s key_y becomes null
  365. else do
  366. nl
  367. end if.
  368. %dangers in adjacent cells
  369.  
  370. action check_for_dangers;
  371. do check that Current_tile is an instance of world
  372. whose x_coord is hero_x and
  373. whose y_coord is hero_y and
  374.  
  375. if Tile_north is an instance of world
  376. whose x_coord is Current_tile`s x_coord and
  377. whose y_coord is Current_tile`s y_coord+1 then do
  378. nl and
  379. check_for_monster(Tile_north`s x_coord,Tile_north`s y_coord,'north')
  380. else nl
  381. end if and
  382.  
  383. if Tile_south is an instance of world
  384. whose x_coord is Current_tile`s x_coord and
  385. whose y_coord is Current_tile`s y_coord-1 then do
  386. nl and
  387. check_for_monster(Tile_south`s x_coord,Tile_south`s y_coord,'south')
  388. else nl
  389. end if and
  390.  
  391. if Tile_east is an instance of world
  392. whose x_coord is Current_tile`s x_coord+1 and
  393. whose y_coord is Current_tile`s y_coord then do
  394. nl and
  395. check_for_monster(Tile_east`s x_coord,Tile_east`s y_coord,'east')
  396. else nl
  397. end if and
  398.  
  399. if Tile_west is an instance of world
  400. whose x_coord is Current_tile`s x_coord-1 and
  401. whose y_coord is Current_tile`s y_coord then do
  402. nl and
  403. check_for_monster(Tile_west`s x_coord,Tile_west`s y_coord,'west')
  404. else nl
  405. end if.
  406.  
  407. action check_for_monster(X,Y,L);
  408.  
  409. do for every M is an instance of monster
  410.  
  411. do if M`s monster_state is alive and
  412. M`s monster_x is equal to X and
  413. M`s monster_y is equal to Y then do
  414. cat({'You hear footsteps to the ',L},Q,_) and
  415. update_status(Q) and
  416. write(Q) and nl
  417. else do nl
  418. end if
  419. end for.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement