munch
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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