not really known
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.

146 lines
3.9 KiB

  1. // Cards lists
  2. FoodChain.cards = [
  3. "alligator", "animal", "bat", "bee", "bird", "camel", "cat", "chicken", "chimp",
  4. "clam", "corn", "cow", "crab", "crocodile", "crow", "dog", "duck", "fish", "flies",
  5. "fox", "frog", "giraffe", "goat", "grass", "hay", "hen", "lamb", "mice", "mole",
  6. "mosquito", "mule", "owl", "ox", "pig", "rat", "shark", "shrimp", "skunk", "snail",
  7. "snake", "spider", "spike", "squid", "squirrel", "starfish", "swan", "tick", "wheat"
  8. ];
  9. // Feed strategy list and members
  10. FoodChain.feedStrategy = [
  11. { name: "herbivore", members: ["swan", "bee", "cow", "giraffe", "squirrel", "goat", "ox", "lamb", "mule", "camel", "chimp"] },
  12. { name: "carnivore", members: ["mosquito", "mole", "spike", "tick", "squid", "crab", "owl", "snake", "dog", "alligator", "bat", "crocodile", "frog", "shark", "spider", "starfish", "crocodile"] },
  13. { name: "omnivore", members: ["duck", "flies", "pig", "mice", "rat", "skunk", "chicken", "hen", "fox"] }
  14. ];
  15. // Chains computation
  16. FoodChain.validChains = [
  17. ["snake", "mice", "corn"],
  18. ["cat", "mice", "corn"],
  19. ["fox", "bird", "spider", "mosquito"],
  20. ["fox", "bird", "spider", "flies"],
  21. ["fox", "duck", "frog", "flies"],
  22. ["snake", "frog", "mosquito"],
  23. ["snake", "frog", "flies"],
  24. ["fox", "duck", "frog", "snail", "grass"],
  25. ["spike", "spider", "mosquito"],
  26. ["spike", "spider", "flies"],
  27. ["shark", "fish", "shrimp"],
  28. ["owl", "bat", "mosquito"],
  29. ["owl", "bat", "flies"],
  30. ["cat", "bat", "mosquito"],
  31. ["cat", "bat", "flies"],
  32. ["fox", "hen", "corn"],
  33. ["fox", "chicken", "corn"],
  34. ["cow", "grass"],
  35. ["starfish", "clam"],
  36. ["frog", "snail", "grass"],
  37. ["skunk", "rat", "snail", "grass"],
  38. ["skunk", "mice", "snail", "grass"],
  39. ["spike", "snail", "grass"],
  40. ["crow", "snail", "grass"],
  41. ["duck", "snail", "grass"],
  42. ["starfish", "crab"]
  43. ];
  44. // Create a random foodchain for the specified size (game build)
  45. FoodChain.randomChain = function(size) {
  46. // Check size
  47. if (size == undefined) {
  48. size = 3;
  49. }
  50. // Look for chains for this size
  51. var chains = [];
  52. for(var i in FoodChain.validChains) {
  53. // Too small
  54. var c = FoodChain.validChains[i];
  55. if (c.length < size)
  56. continue;
  57. // Just the right size
  58. if (c.length == size) {
  59. chains.push(c);
  60. continue;
  61. }
  62. // Too long, compute randomly a subchain
  63. var index = Math.floor(Math.random()*(c.length-size));
  64. var newchain = [];
  65. for (var j = index; j < index+size ; j++) {
  66. newchain.push(c[j]);
  67. }
  68. chains.push(newchain);
  69. }
  70. // Randomly choose a chain
  71. return chains[Math.floor(Math.random()*chains.length)];
  72. };
  73. // Mix a chain
  74. FoodChain.mix = function(chain) {
  75. // Check size
  76. if (chain.length < 2) {
  77. return chain;
  78. }
  79. // Mix cards
  80. var mixedchain = [];
  81. var tomix = enyo.cloneArray(chain);
  82. while (tomix.length != 1) {
  83. // Take a card
  84. var i = Math.floor(Math.random()*tomix.length);
  85. mixedchain.push(tomix[i]);
  86. tomix[i] = null;
  87. // Remix
  88. var newmix = [];
  89. for (var j = 0 ; j < tomix.length ; j++) {
  90. if (tomix[j] != null)
  91. newmix.push(tomix[j]);
  92. }
  93. tomix = newmix;
  94. }
  95. mixedchain.push(tomix[0]);
  96. return mixedchain;
  97. };
  98. // Create a random feed card for the specified size and count (game learn)
  99. FoodChain.randomFeedList = function(size, count) {
  100. // Check size
  101. if (size == undefined) {
  102. size = 2;
  103. }
  104. // Look for chains for this size
  105. var list = [];
  106. for(var i = 0 ; i < count ; i++) {
  107. // Choose randomly a feed strategy
  108. var strategy = Math.floor(Math.random()*size);
  109. // Choose randomly a card not already picked
  110. var index = -1;
  111. var cardname;
  112. while (index == -1) {
  113. // Pick a card
  114. index = Math.floor(Math.random()*FoodChain.feedStrategy[strategy].members.length);
  115. // Check if not already here
  116. cardname = FoodChain.feedStrategy[strategy].members[index];
  117. for (var j = 0 ; index != -1 && j < list.length ; j++) {
  118. if (list[j].cardname == cardname) {
  119. index = -1;
  120. }
  121. }
  122. }
  123. // Add card
  124. list.push({cardname: cardname, strategy: strategy});
  125. }
  126. // Return list
  127. return list;
  128. };