big steppy
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

264 рядки
7.2 KiB

  1. function random_desc(list, odds=1) {
  2. if (Math.random() < odds)
  3. return list[Math.floor(Math.random() * list.length)];
  4. else
  5. return "";
  6. }
  7. function merge_things(list,semicolons=false) {
  8. if (list.length == 0) {
  9. return "";
  10. } else if (list.length == 1) {
  11. return list[0];
  12. } else if (list.length == 2) {
  13. return list[0] + " and " + list[1];
  14. } else {
  15. result = "";
  16. list.slice(0,list.length-1).forEach(function(term) {
  17. result += term + ", ";
  18. })
  19. result += "and " + list[list.length-1]
  20. return result;
  21. }
  22. }
  23. function merge_desc(list) {
  24. result = ""
  25. list.forEach(function(term) {
  26. if (term != "")
  27. result += term + " ";
  28. });
  29. // knock off the last space
  30. if (result.length > 0) {
  31. result = result.substring(0, result.length - 1);
  32. }
  33. return result;
  34. }
  35. // maybe make this something that approximates a
  36. // normal distribution; doing this 15,000,000 times is bad...
  37. function distribution(min, max, samples) {
  38. var result = 0;
  39. for (var i = 0; i < samples; i++) {
  40. result += Math.floor(Math.random() * (max - min + 1) + min);
  41. }
  42. return result;
  43. }
  44. /* default actions */
  45. function defaultStomp(thing) {
  46. return "You crush " + thing.describe() + " underfoot.";
  47. }
  48. function defaultKick(thing) {
  49. return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + ".";
  50. }
  51. function defaultEat(thing) {
  52. return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole.";
  53. }
  54. function DefaultEntity() {
  55. this.stomp = defaultStomp;
  56. this.eat = defaultEat;
  57. this.kick = defaultKick;
  58. return this;
  59. }
  60. function Person(count = 1) {
  61. this.name = "Person";
  62. this.count = count;
  63. this.contents = {};
  64. this.describeOne = function (verbose=true) {
  65. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  66. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  67. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  68. return "a " + merge_desc([sex,body,species]);
  69. }
  70. this.describe = function() {
  71. if (count <= 3) {
  72. list = [];
  73. for (var i = 0; i < count; i++) {
  74. list.push(this.describeOne(this.count <= 2));
  75. }
  76. return merge_things(list);
  77. } else {
  78. return this.count + " people"
  79. }
  80. }
  81. return this;
  82. }
  83. function EmptyCar(count = 1) {
  84. this.name = "Car";
  85. this.count = count;
  86. this.contents = {};
  87. this.describeOne = function() {
  88. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  89. adjective = random_desc(["rusty","brand-new"],0.3);
  90. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  91. return "a parked " + merge_desc([adjective,color,type]);
  92. }
  93. this.describe = function() {
  94. if (this.count <= 3) {
  95. list = [];
  96. for (var i = 0; i < this.count; i++) {
  97. list.push(this.describeOne());
  98. }
  99. return merge_things(list);
  100. } else {
  101. return this.count + " parked cars"
  102. }
  103. }
  104. }
  105. function Car(count = 1) {
  106. this.name = "Car";
  107. this.count = count;
  108. this.contents = {};
  109. var amount = distribution(2,5,count);
  110. this.contents.person = new Person(amount);
  111. this.describeOne = function(verbose=true) {
  112. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  113. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  114. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  115. return "a " + merge_desc([adjective,color,type]);
  116. }
  117. this.describe = function() {
  118. if (this.count <= 3) {
  119. list = [];
  120. for (var i = 0; i < this.count; i++) {
  121. list.push(this.describeOne(this.count < 2));
  122. }
  123. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  124. } else {
  125. return this.count + " cars with " + this.contents.person.describe() + " inside";
  126. }
  127. }
  128. }
  129. function Bus(count = 1) {
  130. this.name = "Bus";
  131. this.count = count;
  132. this.contents = {};
  133. this.resolved = false;
  134. var amount = distribution(10,35,count);
  135. this.contents.person = new Person(amount);
  136. this.describeOne = function(verbose=true) {
  137. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  138. type = random_desc(["bus","double-decker bus","articulating bus"]);
  139. return "a " + merge_desc([adjective,color,type]);
  140. }
  141. this.describe = function() {
  142. if (this.count <= 3) {
  143. list = [];
  144. for (var i = 0; i < this.count; i++) {
  145. list.push(this.describeOne(this.count < 2));
  146. }
  147. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  148. } else {
  149. return this.count + " buses with " + this.contents.person.describe() + " inside";
  150. }
  151. }
  152. }
  153. function Motorcycle(count = 1) {
  154. this.name = "Motorcycle";
  155. this.count = count;
  156. this.contents = {};
  157. var amount = distribution(1,2,count);
  158. this.contents.person = new Person(amount);
  159. }
  160. function Train(count = 1) {
  161. this.name = "Train";
  162. this.count = count;
  163. this.contents = {};
  164. var amount = distribution(20,60,count);
  165. this.contents.person = new Person(amount);
  166. }
  167. function House(count = 1) {
  168. this.name = "House";
  169. this.count = count;
  170. this.contents = {};
  171. var amount = distribution(0,8,count);
  172. this.contents.person = new Person(amount);
  173. amount = distribution(0,2,count);
  174. this.contents.emptycar = new EmptyCar(amount);
  175. this.describeOne = function(verbose=true) {
  176. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  177. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  178. name = random_desc(["house","house","house","house","house","trailer"], 1);
  179. return "a " + merge_desc([size,color,name]);
  180. }
  181. this.describe = function() {
  182. if (this.count <= 3) {
  183. list = [];
  184. for (var i = 0; i < this.count; i++) {
  185. list.push(this.describeOne(this.count < 2));
  186. }
  187. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  188. } else {
  189. return this.count + " homes with " + this.contents.person.describe() + " inside";
  190. }
  191. }
  192. }
  193. function ParkingGarage(count = 1) {
  194. this.name = "Parking Garage";
  195. this.count = count;
  196. this.contents = {};
  197. var amount = distribution(10,200,count);
  198. this.contents.person = new Person(amount);
  199. amount = distribution(30,100,count);
  200. this.contents.emptycar = new EmptyCar(amount);
  201. amount = distribution(5,20,count);
  202. this.contents.car = new Car(amount);
  203. this.describeOne = function(verbose=true) {
  204. return "a parking garage";
  205. }
  206. this.describe = function() {
  207. if (this.count <= 3) {
  208. list = [];
  209. for (var i = 0; i < this.count; i++) {
  210. list.push(this.describeOne(this.count < 2));
  211. }
  212. return merge_things(list) + " with " + merge_things([this.contents.person.describe(),this.contents.emptycar.describe(),this.contents.car.describe()]) + " inside";
  213. } else {
  214. return this.count + " parking garages with " + this.contents.person.describe() + " inside";
  215. }
  216. }
  217. }
  218. function Overpass(count = 1) {
  219. this.name = "Overpass";
  220. this.count = count;
  221. this.contents = {};
  222. var amount = distribution(0,20,count);
  223. this.contents.person = new Person(amount);
  224. amount = distribution(25,100,count);
  225. this.contents.car = new Car(amount);
  226. }