crunch
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

335 satır
6.6 KiB

  1. "use strict";
  2. /*jshint browser: true*/
  3. /*jshint devel: true*/
  4. let NORTH = 0;
  5. let NORTH_EAST = 1;
  6. let EAST = 2;
  7. let SOUTH_EAST = 3;
  8. let SOUTH = 4;
  9. let SOUTH_WEST = 5;
  10. let WEST = 6;
  11. let NORTH_WEST = 7;
  12. let locations = {};
  13. let locationsSrc = [
  14. {
  15. "name": "Bedroom",
  16. "desc": "A bedroom. It has a bed in it.",
  17. "conn": [
  18. {
  19. "name": "Bathroom",
  20. "dir": EAST,
  21. "desc": "You step into your bathroom."
  22. },
  23. {
  24. "name": "Living Room",
  25. "dir": NORTH,
  26. "desc": "You walk into the living room."
  27. }
  28. ],
  29. "objs": [
  30. Bed,
  31. Journal
  32. ],
  33. },
  34. {
  35. "name": "Bathroom",
  36. "desc": "Your modest bathroom.",
  37. "conn": [
  38. {
  39. "name": "Bedroom",
  40. "dir": WEST,
  41. "desc": "You walk back into your bedroom."
  42. }
  43. ],
  44. "objs": [
  45. Toilet
  46. ]
  47. },
  48. {
  49. "name": "Living Room",
  50. "desc": "A bare living room",
  51. "conn": [
  52. {
  53. "name": "Lobby",
  54. "dir": NORTH,
  55. "desc": "You leave your apartment and head to the lobby."
  56. },
  57. {
  58. "name": "Bedroom",
  59. "dir": SOUTH,
  60. "desc": "You walk into your bedroom."
  61. }
  62. ],
  63. "objs": [
  64. TV,
  65. Phone
  66. ]
  67. },
  68. {
  69. "name": "North Street",
  70. "desc": "It's a street",
  71. "conn": [
  72. {
  73. "name": "Alley",
  74. "dir": WEST,
  75. "desc": "You wander into the dark alley"
  76. },
  77. {
  78. "name": "Lobby",
  79. "dir": EAST,
  80. "desc": "You step into your apartment's lobby"
  81. },
  82. {
  83. "name": "Crossroads",
  84. "dir": SOUTH,
  85. "desc": "You walk south"
  86. },
  87. {
  88. "name": "DANGER ZONE",
  89. "dir": NORTH,
  90. "desc": "You walk into the DANGER ZONE"
  91. }
  92. ],
  93. "objs": [
  94. Nerd
  95. ]
  96. },
  97. {
  98. "name": "Lobby",
  99. "desc": "The modest lobby of your modest apartment complex",
  100. "conn": [
  101. {
  102. "name": "North Street",
  103. "dir": WEST,
  104. "desc": "You walk out into the street"
  105. },
  106. {
  107. "name": "Living Room",
  108. "dir": SOUTH,
  109. "desc": "You walk back into your apartment"
  110. }
  111. ],
  112. "objs": [
  113. VendingMachine
  114. ]
  115. },
  116. {
  117. "name": "Alley",
  118. "desc": "A suspicious alley",
  119. "conn": [
  120. {
  121. "name": "North Street",
  122. "dir": EAST,
  123. "desc": "You hurry back into the open street."
  124. },
  125. {
  126. "name": "Seedy Bar",
  127. "dir": NORTH,
  128. "desc": "You step into the bar."
  129. }
  130. ]
  131. },
  132. {
  133. "name": "Seedy Bar",
  134. "desc": "God this place is seedy",
  135. "conn": [
  136. {
  137. "name": "Alley",
  138. "dir": SOUTH,
  139. "desc": "You step out of the bar"
  140. }
  141. ],
  142. "objs": [
  143. ]
  144. },
  145. {
  146. "name": "Crossroads",
  147. "desc": "Where the roads cross",
  148. "conn": [
  149. {
  150. "name": "North Street",
  151. "dir": NORTH,
  152. "desc": "You walk north"
  153. },
  154. {
  155. "name": "South Street",
  156. "dir": SOUTH,
  157. "desc": "You walk south"
  158. },
  159. {
  160. "name": "Corner Mart",
  161. "dir": SOUTH_EAST,
  162. "desc": "You walk into the convenience store"
  163. }
  164. ]
  165. },
  166. {
  167. "name": "South Street",
  168. "desc": "This street is in the south",
  169. "conn": [
  170. {
  171. "name": "Crossroads",
  172. "dir": NORTH,
  173. "desc": "You walk to the crossroads"
  174. },
  175. {
  176. "name": "Nature Trail",
  177. "dir": SOUTH,
  178. "desc": "You head out into the woods"
  179. }
  180. ]
  181. },
  182. {
  183. "name": "Nature Trail",
  184. "desc": "A winding train cutting through a thick forest",
  185. "conn": [
  186. {
  187. "name": "South Street",
  188. "dir": NORTH,
  189. "desc": "You return to town."
  190. },
  191. {
  192. "name": "Wilderness",
  193. "dir": SOUTH,
  194. "desc": "You wander into the wilderness...and immediately get lost."
  195. }
  196. ],
  197. "objs": [
  198. NatureTrailExercise,
  199. GetaObj
  200. ]
  201. },
  202. {
  203. "name": "Wilderness",
  204. "desc": "Pretty spooky",
  205. "conn": [
  206. ],
  207. "objs": [
  208. WildernessExplore
  209. ]
  210. },
  211. {
  212. "name": "DANGER ZONE",
  213. "desc": "THE DANGER ZONE",
  214. "conn": [
  215. {
  216. "name": "North Street",
  217. "dir": SOUTH,
  218. "desc": "You walk out of the DANGER ZONE"
  219. },
  220. {
  221. "name": "SUPER DANGER ZONE",
  222. "dir": NORTH,
  223. "desc": "Getting eaten is fun!",
  224. }
  225. ],
  226. "hooks": [
  227. function() {
  228. startCombat(new Anthro());
  229. }
  230. ]
  231. },
  232. {
  233. "name": "SUPER DANGER ZONE",
  234. "desc": "Very dangerous",
  235. "conn": [
  236. {
  237. "name": "DANGER ZONE",
  238. "dir": SOUTH,
  239. "desc": "You hurriedly leave the SUPER DANGER ZONE"
  240. }
  241. ],
  242. "hooks": [
  243. function() {
  244. startCombat(new Fen());
  245. }
  246. ]
  247. },
  248. {
  249. "name": "Corner Mart",
  250. "desc": "A convenience store with a variety of snacks and supplies",
  251. "conn": [
  252. {
  253. "name": "Crossroads",
  254. "dir": NORTH_WEST,
  255. "desc": "You leave the store."
  256. }
  257. ]
  258. }
  259. ];
  260. function Location(name="Nowhere",desc="Nada") {
  261. this.name = name;
  262. this.description = desc;
  263. this.exits = [null,null,null,null,null,null,null,null];
  264. this.exitDescs = [null,null,null,null,null,null,null,null];
  265. this.objects = [];
  266. this.hooks = [];
  267. this.conditions = [];
  268. this.visit = function() {
  269. this.hooks.forEach(function (x) {
  270. x();
  271. });
  272. };
  273. }
  274. function opposite(direction) {
  275. return (direction + 4) % 8;
  276. }
  277. function connectLocations(loc1,loc2,dir,desc) {
  278. if (loc1.exits[dir] != null) {
  279. alert(loc1.name + " is already connected to " + loc1.exits[dir].name);
  280. return;
  281. } else {
  282. if (dir >= 0 && dir <= 7) {
  283. loc1.exits[dir] = loc2;
  284. loc1.exitDescs[dir] = desc;
  285. } else {
  286. alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir);
  287. }
  288. }
  289. }
  290. function createWorld() {
  291. for (let i = 0; i < locationsSrc.length; i++) {
  292. let src = locationsSrc[i];
  293. let location = new Location(src.name,src.desc);
  294. locations[src.name] = location;
  295. if (src.objs != undefined) {
  296. src.objs.forEach(function (obj) {
  297. location.objects.push(new obj());
  298. });
  299. }
  300. if (src.hooks != undefined) {
  301. src.hooks.forEach(function (hook) {
  302. location.hooks.push(hook);
  303. });
  304. }
  305. if (src.conditions != undefined) {
  306. src.conditions.forEach(function (cond) {
  307. location.conditions.push(cond);
  308. });
  309. }
  310. }
  311. for (let i = 0; i < locationsSrc.length; i++) {
  312. let src = locationsSrc[i];
  313. let from = locations[src.name];
  314. for (let j = 0; j < src.conn.length; j++) {
  315. let to = locations[src.conn[j].name];
  316. connectLocations(from, to, src.conn[j].dir, src.conn[j].desc);
  317. }
  318. }
  319. return locations;
  320. }