munch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

318 line
6.3 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 startLocation = "Bedroom";
  13. let locations = {};
  14. let locationsSrc = [
  15. {
  16. "name": "Bedroom",
  17. "desc": "A bedroom. It has a bed in it.",
  18. "conn": [
  19. {
  20. "name": "Bathroom",
  21. "dir": EAST,
  22. "desc": "You step into your bathroom."
  23. },
  24. {
  25. "name": "Living Room",
  26. "dir": NORTH,
  27. "desc": "You walk into the living room."
  28. }
  29. ],
  30. "objs": [
  31. Bed
  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. },
  143. {
  144. "name": "Crossroads",
  145. "desc": "Where the roads cross",
  146. "conn": [
  147. {
  148. "name": "North Street",
  149. "dir": NORTH,
  150. "desc": "You walk north"
  151. },
  152. {
  153. "name": "South Street",
  154. "dir": SOUTH,
  155. "desc": "You walk south"
  156. },
  157. {
  158. "name": "Corner Mart",
  159. "dir": SOUTH_EAST,
  160. "desc": "You walk into the convenience store"
  161. }
  162. ]
  163. },
  164. {
  165. "name": "South Street",
  166. "desc": "This street is in the south",
  167. "conn": [
  168. {
  169. "name": "Crossroads",
  170. "dir": NORTH,
  171. "desc": "You walk to the crossroads"
  172. },
  173. {
  174. "name": "Nature Trail",
  175. "dir": SOUTH,
  176. "desc": "You head out into the woods"
  177. }
  178. ]
  179. },
  180. {
  181. "name": "Nature Trail",
  182. "desc": "A winding train cutting through a thick forest",
  183. "conn": [
  184. {
  185. "name": "South Street",
  186. "dir": NORTH,
  187. "desc": "You return to town."
  188. }
  189. ],
  190. "objs": [
  191. NatureTrailExercise,
  192. GetaObj
  193. ]
  194. },
  195. {
  196. "name": "DANGER ZONE",
  197. "desc": "THE DANGER ZONE",
  198. "conn": [
  199. {
  200. "name": "North Street",
  201. "dir": SOUTH,
  202. "desc": "You walk out of the DANGER ZONE"
  203. },
  204. {
  205. "name": "SUPER DANGER ZONE",
  206. "dir": NORTH,
  207. "desc": "Getting eaten is fun!",
  208. }
  209. ],
  210. "hooks": [
  211. function() {
  212. startCombat(new Anthro());
  213. }
  214. ]
  215. },
  216. {
  217. "name": "SUPER DANGER ZONE",
  218. "desc": "Very dangerous",
  219. "conn": [
  220. {
  221. "name": "DANGER ZONE",
  222. "dir": SOUTH,
  223. "desc": "You hurriedly leave the SUPER DANGER ZONE"
  224. }
  225. ],
  226. "hooks": [
  227. function() {
  228. startCombat(new Fen());
  229. }
  230. ]
  231. },
  232. {
  233. "name": "Corner Mart",
  234. "desc": "A convenience store with a variety of snacks and supplies",
  235. "conn": [
  236. {
  237. "name": "Crossroads",
  238. "dir": NORTH_WEST,
  239. "desc": "You leave the store."
  240. }
  241. ]
  242. }
  243. ];
  244. function Location(name="Nowhere",desc="Nada") {
  245. this.name = name;
  246. this.description = desc;
  247. this.exits = [null,null,null,null,null,null,null,null];
  248. this.exitDescs = [null,null,null,null,null,null,null,null];
  249. this.objects = [];
  250. this.hooks = [];
  251. this.conditions = [];
  252. this.visit = function() {
  253. this.hooks.forEach(function (x) {
  254. x();
  255. });
  256. };
  257. }
  258. function opposite(direction) {
  259. return (direction + 4) % 8;
  260. }
  261. function connectLocations(loc1,loc2,dir,desc) {
  262. if (loc1.exits[dir] != null) {
  263. alert(loc1.name + " is already connected to " + loc1.exits[dir].name);
  264. return;
  265. } else {
  266. if (dir >= 0 && dir <= 7) {
  267. loc1.exits[dir] = loc2;
  268. loc1.exitDescs[dir] = desc;
  269. } else {
  270. alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir);
  271. }
  272. }
  273. }
  274. function createWorld() {
  275. for (let i = 0; i < locationsSrc.length; i++) {
  276. let src = locationsSrc[i];
  277. let location = new Location(src.name,src.desc);
  278. locations[src.name] = location;
  279. if (src.objs != undefined) {
  280. src.objs.forEach(function (obj) {
  281. location.objects.push(new obj());
  282. });
  283. }
  284. if (src.hooks != undefined) {
  285. src.hooks.forEach(function (hook) {
  286. location.hooks.push(hook);
  287. });
  288. }
  289. if (src.conditions != undefined) {
  290. src.conditions.forEach(function (cond) {
  291. location.conditions.push(cond);
  292. });
  293. }
  294. }
  295. for (let i = 0; i < locationsSrc.length; i++) {
  296. let src = locationsSrc[i];
  297. let from = locations[src.name];
  298. for (let j = 0; j < src.conn.length; j++) {
  299. let to = locations[src.conn[j].name];
  300. connectLocations(from, to, src.conn[j].dir, src.conn[j].desc);
  301. }
  302. }
  303. return locations[startLocation];
  304. }