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.

257 lines
6.5 KiB

  1. define(["webL10n","sugar-web/env"], function (webL10n,env) {
  2. var settings = {};
  3. settings.l10n = webL10n;
  4. settings.load = function(callback) {
  5. // Load settings
  6. env.getEnvironment(function(err, environment) {
  7. var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
  8. var language = environment.user ? environment.user.language : defaultLanguage;
  9. settings.language = language;
  10. settings.l10n.language.code = language;
  11. callback();
  12. });
  13. // Stop sound at end of game to sanitize media environment, specifically on Android
  14. document.getElementById("stop-button").addEventListener('click', function (event) {
  15. sound.pause();
  16. });
  17. }
  18. // Get/Set state
  19. settings.getState = function() {
  20. var states = [];
  21. for(var i = 0 ; i < this.levels.length ; i++) {
  22. states.push(this.levels[i].completed);
  23. }
  24. return states;
  25. }
  26. settings.setState = function(states) {
  27. if (states == null || states.length != this.levels.length)
  28. return false;
  29. for (var i = 0 ; i < this.levels.length ; i++) {
  30. this.levels[i].completed = states[i];
  31. }
  32. return true;
  33. }
  34. // Game map
  35. settings.gameMap = function(map) {
  36. var width = constant.boardWidth, height = constant.boardHeight;
  37. if (map == "grass") {
  38. return "---HOH-----H---" + // - = Grass
  39. "----H----------" + // H = Trees
  40. "---------------" + // ^ = Mountain
  41. "---------------" + // O = Lake
  42. "---------------" +
  43. "-----------H---" +
  44. "-----H---------" +
  45. "---------------" +
  46. "---------H-H---";
  47. } else if (map == "trees") {
  48. return "------H--HHHH^-" +
  49. "----H--H----HH-" +
  50. "------H---H----" +
  51. "---------------" +
  52. "---------------" +
  53. "---H-----------" +
  54. "-------HH------" +
  55. "-----H--H---H--" +
  56. "---HHH---HH--H-";
  57. } else if (map == "mountain") {
  58. return "---HHH^^^HHH---" +
  59. "----HHH^^HH--H-" +
  60. "------H-HH-----" +
  61. "---H-----------" +
  62. "-------O-------" +
  63. "-----------H---" +
  64. "-----H-H-------" +
  65. "-----HHH^H-H---" +
  66. "----HHH^^^HHH--";
  67. }
  68. return new Array(width*height).join('-');
  69. }
  70. // Functions to generate tags
  71. settings.typeNumber = function() {
  72. var number = Math.floor(Math.random()*11);
  73. return { tag: ""+number, result: number };
  74. }
  75. settings.generateFunctionAddFromTo = function(start, end) {
  76. var difference = end-start+1;
  77. return function() {
  78. var number1 = start+Math.floor(Math.random()*difference);
  79. var number2 = start+Math.floor(Math.random()*difference);
  80. return { tag: ""+number1+"+"+number2, result: number1+number2 }
  81. }
  82. }
  83. settings.missingNumbers = function() {
  84. var number1 = Math.floor(Math.random()*11);
  85. var number2 = Math.floor(Math.random()*11);
  86. return { tag: ""+number1+"+?="+(number1+number2), result: number2 };
  87. }
  88. settings.generateFunctionSubstractFromTo = function(start, end, negative) {
  89. var difference = end-start+1;
  90. return function() {
  91. var number1 = start+Math.floor(Math.random()*difference);
  92. var number2 = start+Math.floor(Math.random()*difference);
  93. if (!negative && Math.abs(number2) > Math.abs(number1)) {
  94. var tmp = number1;
  95. number1 = number2;
  96. number2 = tmp;
  97. }
  98. return { tag: ""+number1+"-"+number2, result: number1-number2 }
  99. }
  100. }
  101. settings.additionSubtraction = function() {
  102. var number1 = Math.floor(Math.random()*21);
  103. var number2 = Math.floor(Math.random()*11);
  104. var sign = Math.floor(Math.random()*2);
  105. if (sign == 0)
  106. return { tag: ""+number1+"+"+number2, result: number1+number2 };
  107. else {
  108. if (Math.abs(number2) > Math.abs(number1)) {
  109. var tmp = number1;
  110. number1 = number2;
  111. number2 = tmp;
  112. }
  113. return { tag: ""+number1+"-"+number2, result: number1-number2 }
  114. }
  115. }
  116. // Play levels
  117. settings.levels = [
  118. {
  119. id: "Type", // Id of level
  120. name: "Type", // Name of level
  121. map: "mountain", // Name of map, see in util.js
  122. defense: [4, 0, 4, 0, 0], // Defense composition: #HQ, #Soldier, #Tank, #Canon, #Helo
  123. attack: 22, // #Attacking units
  124. stats: [10, 10, 0, 9, 10], // Attack stats composition a random number between 0-9 compared to array number for: HQ, Soldier, Tank, Canon, Helo
  125. generator: settings.typeNumber, // Function to generate the value
  126. completed: false // Use at runtime to see if completed
  127. },
  128. {
  129. id: "ADD3",
  130. name: "ADD3",
  131. map: "trees",
  132. defense: [4, 2, 2, 0, 0],
  133. attack: 20,
  134. stats: [10, 0, 8, 10, 10],
  135. generator: settings.generateFunctionAddFromTo(1, 3),
  136. completed: false
  137. },
  138. {
  139. id: "ADD5",
  140. name: "ADD5",
  141. map: "grass",
  142. defense: [4, 3, 1, 0, 0],
  143. attack: 30,
  144. stats: [10, 0, 8, 10, 9],
  145. generator: settings.generateFunctionAddFromTo(0, 5),
  146. completed: false
  147. },
  148. {
  149. id: "SUM10",
  150. name: "SUM10",
  151. map: "mountain",
  152. defense: [4, 0, 4, 0, 0],
  153. attack: 30,
  154. stats: [10, 10, 0, 8, 9],
  155. generator: settings.generateFunctionAddFromTo(0, 10),
  156. completed: false
  157. },
  158. {
  159. id: "SUM15",
  160. name: "SUM15",
  161. map: "trees",
  162. defense: [4, 2, 2, 0, 0],
  163. attack: 30,
  164. stats: [10, 0, 7, 10, 10],
  165. generator: settings.generateFunctionAddFromTo(0, 15),
  166. completed: false
  167. },
  168. {
  169. id: "SUM20",
  170. name: "SUM20",
  171. map: "grass",
  172. defense: [4, 3, 1, 0, 0],
  173. attack: 40,
  174. stats: [10, 0, 7, 10, 9],
  175. generator: settings.generateFunctionAddFromTo(0, 20),
  176. completed: false
  177. },
  178. {
  179. id: "TDN",
  180. name: "TDN",
  181. map: "mountain",
  182. defense: [4, 4, 4, 0, 0],
  183. attack: 40,
  184. stats: [10, 0, 1, 8, 9],
  185. generator: settings.generateFunctionAddFromTo(10, 20),
  186. completed: false
  187. },
  188. {
  189. id: "Missing",
  190. name: "Missing",
  191. map: "trees",
  192. defense: [4, 2, 2, 0, 0],
  193. attack: 40,
  194. stats: [10, 0, 7, 10, 10],
  195. generator: settings.missingNumbers,
  196. completed: false
  197. },
  198. {
  199. id: "S010",
  200. name: "S010",
  201. map: "grass",
  202. defense: [4, 0, 4, 0, 0],
  203. attack: 40,
  204. stats: [10, 10, 0, 9, 10],
  205. generator: settings.generateFunctionSubstractFromTo(0, 10, false),
  206. completed: false
  207. },
  208. {
  209. id: "S020",
  210. name: "S020",
  211. map: "trees",
  212. defense: [4, 2, 2, 0, 0],
  213. attack: 20,
  214. stats: [10, 0, 8, 10, 10],
  215. generator: settings.generateFunctionSubstractFromTo(0, 20, false),
  216. completed: false
  217. },
  218. {
  219. id: "STW",
  220. name: "STW",
  221. map: "mountain",
  222. defense: [4, 4, 4, 0, 0],
  223. attack: 30,
  224. stats: [10, 0, 1, 8, 9],
  225. generator: settings.generateFunctionSubstractFromTo(10, 30, false),
  226. completed: false
  227. },
  228. {
  229. id: "AAS",
  230. name: "AAS",
  231. map: "trees",
  232. defense: [4, 2, 2, 0, 0],
  233. attack: 40,
  234. stats: [10, 0, 7, 10, 10],
  235. generator: settings.additionSubtraction,
  236. completed: false
  237. }
  238. ];
  239. return settings;
  240. });