squareOne.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /******************************
  2. * This file holds game states.
  3. ******************************/
  4. /** [GAME STATE]
  5. *
  6. * ..squareOne... = gameName
  7. * ..../...\.....
  8. * ...a.....b.... = gameMode
  9. * .....\./......
  10. * ......|.......
  11. * ...../.\......
  12. * .plus...minus. = gameOperation
  13. * .....\./......
  14. * ......|.......
  15. * ....1,2,3..... = gameDifficulty
  16. *
  17. * Character : tractor
  18. * Theme : farm
  19. * Concept : Player associates 'blocks carried by the tractor' and 'floor spaces to be filled by them'
  20. * Represent fractions as : blocks/rectangles
  21. *
  22. * Game modes can be :
  23. *
  24. * a : Player can select # of 'floor blocks' (hole in the ground)
  25. * Selects size of hole to be made in the ground (to fill with the blocks in front of the truck)
  26. * b : Player can select # of 'stacked blocks' (in front of the truck)
  27. * Selects number of blocks in front of the truck (to fill the hole on the ground)
  28. *
  29. * Operations can be :
  30. *
  31. * plus : addition of fractions
  32. * Represented by : tractor going to the right (floor positions 0..8)
  33. * minus : subtraction of fractions
  34. * Represented by: tractor going to the left (floor positions 8..0)
  35. *
  36. * @namespace
  37. */
  38. const squareOne = {
  39. control: undefined, // level related data
  40. default: undefined, // level related default values
  41. ui: undefined, // graphic elements
  42. animation: undefined, // animation control
  43. tractor: undefined,
  44. stack: undefined, // stack blocks info
  45. floor: undefined, // floor blocks info
  46. /**
  47. * Main code
  48. */
  49. create: function () {
  50. const truckWidth = 201;
  51. const divisor = gameDifficulty == 3 ? 4 : gameDifficulty; // Make sure valid divisors are 1, 2 and 4 (not 3)
  52. let lineColor = undefined;
  53. let fillColor = undefined;
  54. if (gameOperation === 'minus') {
  55. lineColor = colors.red;
  56. fillColor = colors.redLight;
  57. } else {
  58. lineColor = colors.green;
  59. fillColor = colors.greenLight;
  60. }
  61. this.ui = {
  62. arrow: undefined,
  63. help: undefined,
  64. message: undefined,
  65. continue: {
  66. // modal: undefined,
  67. button: undefined,
  68. text: undefined,
  69. },
  70. };
  71. this.control = {
  72. direc: gameOperation == 'minus' ? -1 : 1, // Will be multiplied to values to easily change tractor direction when needed
  73. divisorsList: '', // Hold the divisors for each fraction on stacked blocks (created for postScore())
  74. lineWidth: 3,
  75. hasClicked: false, // Checks if player 'clicked' on a block
  76. checkAnswer: false, // When true allows game to run 'check answer' code in update
  77. isCorrect: false, // Checks player 'answer'
  78. count: 0, // An 'x' position counter used in the tractor animation
  79. };
  80. this.animation = {
  81. animateTractor: false, // When true allows game to run 'tractor animation' code in update (turns animation of the moving tractor ON/OFF)
  82. animateEnding: false, // When true allows game to run 'tractor ending animation' code in update (turns 'ending' animation of the moving tractor ON/OFF)
  83. speed: 2 * this.control.direc, // X distance in which the tractor moves in each iteration of the animation
  84. };
  85. this.default = {
  86. width: 172, // Base block width,
  87. height: 70, // Base block height
  88. x0:
  89. gameOperation == 'minus'
  90. ? context.canvas.width - truckWidth
  91. : truckWidth, // Initial 'x' coordinate for the tractor and stacked blocks
  92. y0: context.canvas.height - game.image['floor_grass'].width * 1.5,
  93. };
  94. this.default.arrowX0 =
  95. self.default.x0 + self.default.width * self.control.direc;
  96. this.default.arrowXEnd =
  97. self.default.arrowX0 + self.default.width * self.control.direc * 8;
  98. renderBackground();
  99. // FOR MOODLE
  100. if (moodle) {
  101. navigation.add.right(['audio']);
  102. } else {
  103. navigation.add.left(['back', 'menu', 'show_answer'], 'customMenu');
  104. navigation.add.right(['audio']);
  105. }
  106. this.stack = {
  107. list: [],
  108. /**
  109. * (a) all blocks (fixed) (random)
  110. * (b) (updates) user selection
  111. */
  112. selectedIndex: undefined,
  113. /**
  114. * (a) UNDEFINED
  115. * (b) subsection of blocks (fixed) (random)
  116. */
  117. correctIndex: undefined,
  118. /**
  119. * (a/b) (updates) cur index (for animation/check control)
  120. *
  121. * initial value: 0
  122. */
  123. curIndex: 0,
  124. /**
  125. * (a/b) (updates) end of current stack block x coord
  126. */
  127. curBlockEndX: undefined,
  128. };
  129. this.floor = {
  130. list: [],
  131. /**
  132. * (a) (updates) user selection
  133. * (b) subsection of floor blocks (fixed) (generated)
  134. */
  135. selectedIndex: undefined,
  136. /**
  137. * (a) correct floor index - equiv to all in STACK
  138. * (b) UNDEFINED
  139. */
  140. correctIndex: undefined,
  141. /**
  142. * (a/b) (updates) cur index (for animation/check control)
  143. *
  144. * initial value: -1
  145. */
  146. curIndex: -1,
  147. /**
  148. * (a) correct floor x coord - equiv to all in STACK
  149. * (b) generated floor x coord - equiv to correct in STACK (fixed) (generated)
  150. */
  151. correctX: undefined,
  152. };
  153. let [restart, correctXA] = this.utils.renderStackedBlocks(
  154. this.control.direc,
  155. lineColor,
  156. fillColor,
  157. this.control.lineWidth,
  158. divisor
  159. );
  160. this.utils.renderFloorBlocks(
  161. this.control.direc,
  162. lineColor,
  163. this.control.lineWidth,
  164. divisor,
  165. correctXA
  166. );
  167. this.utils.renderCharacters();
  168. this.utils.renderMainUI();
  169. this.restart = restart;
  170. if (!this.restart) {
  171. game.timer.start(); // Set a timer for the current level (used in postScore())
  172. game.event.add('click', this.events.onInputDown);
  173. game.event.add('mousemove', this.events.onInputOver);
  174. }
  175. },
  176. /**
  177. * Game loop
  178. */
  179. update: function () {
  180. // Starts tractor animation
  181. if (self.animation.animateTractor) {
  182. self.utils.animateTractorHandler();
  183. }
  184. // Check answer after animation ends
  185. if (self.control.checkAnswer) {
  186. self.utils.checkAnswerHandler();
  187. }
  188. // Starts tractor moving animation
  189. if (self.animation.animateEnding) {
  190. self.utils.animateEndingHandler();
  191. }
  192. game.render.all();
  193. },
  194. utils: {
  195. // RENDER
  196. /**
  197. * Create stacked blocks for the level in create()
  198. */
  199. renderStackedBlocks: (direc, lineColor, fillColor, lineWidth, divisor) => {
  200. let restart = false;
  201. let hasBaseDifficulty = false; // Will be true after next for loop if level has at least one '1/difficulty' fraction (if false, restart)
  202. const max = gameMode == 'b' ? 10 : curMapPosition + 4; // Maximum # of stacked blocks for the level
  203. const total = game.math.randomInRange(curMapPosition + 2, max); // Total # of stacked blocks for the level
  204. const renderLabels = (curDivisor, x, y, i, curBlock) => {
  205. let font, curFractionItems;
  206. const fractionPartsList = [];
  207. if (curDivisor === 1) {
  208. font = textStyles.h2_;
  209. curFractionItems = [
  210. {
  211. x: x,
  212. y: self.default.y0 - i * y - 20,
  213. text: '1',
  214. },
  215. {
  216. x: x - 25,
  217. y: self.default.y0 - i * y - 27,
  218. text: gameOperation === 'minus' ? '-' : '',
  219. },
  220. null,
  221. ];
  222. } else {
  223. font = textStyles.p_;
  224. curFractionItems = [
  225. {
  226. x: x,
  227. y: self.default.y0 - i * y - 40,
  228. text: '1\n' + curDivisor,
  229. },
  230. {
  231. x: x - 25,
  232. y: self.default.y0 - i * y - 27,
  233. text: gameOperation === 'minus' ? '-' : '',
  234. },
  235. {
  236. x0: x,
  237. y: self.default.y0 - i * y - 35,
  238. x1: x + 25,
  239. lineWidth: 2,
  240. color: lineColor,
  241. },
  242. ];
  243. }
  244. font = { ...font, font: 'bold ' + font.font, fill: lineColor };
  245. for (let i = 0; i < 2; i++) {
  246. const item = game.add.text(
  247. curFractionItems[i].x,
  248. curFractionItems[i].y,
  249. curFractionItems[i].text,
  250. font
  251. );
  252. item.lineHeight = 30;
  253. fractionPartsList.push(item);
  254. }
  255. if (curFractionItems[2]) {
  256. const line = game.add.geom.line(
  257. curFractionItems[2].x0,
  258. curFractionItems[2].y,
  259. curFractionItems[2].x1,
  260. curFractionItems[2].y,
  261. curFractionItems[2].lineWidth,
  262. curFractionItems[2].color
  263. );
  264. line.anchor(0.5, 0);
  265. fractionPartsList.push(line);
  266. } else {
  267. fractionPartsList.push(null);
  268. }
  269. curBlock.fraction = {
  270. labels: fractionPartsList,
  271. nominator: direc,
  272. denominator: curDivisor,
  273. };
  274. if (!showFractions) {
  275. curBlock.fraction.labels.forEach((label) => {
  276. if (label) label.alpha = 0;
  277. });
  278. }
  279. };
  280. const shouldRestart = (hasBaseDifficulty, correctXA) => {
  281. if (
  282. !hasBaseDifficulty ||
  283. (gameOperation == 'plus' &&
  284. (correctXA < self.default.x0 + self.default.width ||
  285. correctXA > self.default.x0 + 8 * self.default.width)) ||
  286. (gameOperation == 'minus' &&
  287. (correctXA < self.default.x0 - 8 * self.default.width ||
  288. correctXA > self.default.x0 - self.default.width))
  289. )
  290. return true;
  291. return false;
  292. };
  293. let correctXA = self.default.x0 + self.default.width * direc; // Equivalent x coordinate on the floor
  294. // Render blocks
  295. for (let i = 0; i < total; i++) {
  296. let curDivisor = game.math.randomInRange(1, gameDifficulty); // Set divisor for current fraction
  297. if (curDivisor === gameDifficulty) hasBaseDifficulty = true;
  298. if (curDivisor === 3) curDivisor = 4; // Make sure valid divisors are 1, 2 and 4 (not 3)
  299. const curBlockWidth = self.default.width / curDivisor; // Current width is a fraction of the default
  300. self.control.divisorsList += curDivisor + ','; // Documenting list of divisors (for postScore())
  301. correctXA += curBlockWidth * direc;
  302. const curBlock = game.add.geom.rect(
  303. self.default.x0,
  304. self.default.y0 - i * self.default.height - lineWidth,
  305. curBlockWidth,
  306. self.default.height,
  307. fillColor,
  308. 1,
  309. lineColor,
  310. lineWidth
  311. );
  312. curBlock.anchor(gameOperation === 'minus' ? 1 : 0, 1);
  313. curBlock.blockValue = divisor / curDivisor;
  314. // If game mode is (b), add events to stacked blocks
  315. if (gameMode === 'b') curBlock.blockIndex = i;
  316. // Add to stack blocks list
  317. self.stack.list.push(curBlock);
  318. // If 'show fractions' is turned on, create labels that display the fractions on the side of each block
  319. const x = self.default.x0 + (curBlockWidth + 40) * direc;
  320. const y = self.default.height + 1;
  321. renderLabels(curDivisor, x, y, i, curBlock);
  322. }
  323. // Computer generated correct stack index
  324. if (gameMode === 'a') self.stack.selectedIndex = total - 1;
  325. // Will be used as a counter in update, adding in the width of each stacked block to check if the end matches the floor selected position
  326. // initial value is end of current block
  327. self.stack.curBlockEndX =
  328. self.default.x0 + self.stack.list[0].width * direc;
  329. // Check for errors (level too easy for its difficulty or end position out of bounds)
  330. restart = shouldRestart(hasBaseDifficulty, correctXA);
  331. if (isDebugMode) {
  332. console.log(
  333. `------------------------------
  334. \nGame Map Position: ${curMapPosition}
  335. \n------------------------ setup stack
  336. \nMin blocks (curMapPosition + 2): ${curMapPosition + 2}
  337. ${
  338. gameMode === 'a'
  339. ? `\nMax blocks (A mode) (curMapPosition + 4): ${
  340. curMapPosition + 4
  341. }`
  342. : '\nMax blocks (B mode): 10'
  343. }
  344. \nTotal blocks (random min..max): ${total}
  345. \nPossible divisors (random 1..gameDifficulty / if 3 then 4): 1..${
  346. gameDifficulty == 3 ? 4 : gameDifficulty
  347. }
  348. \n(Checks if has 1/diff or floor x is out of bounds)
  349. `
  350. );
  351. if (restart) console.log('Error during level setup. Retrying...');
  352. else console.log('Successfull level setup!');
  353. }
  354. return [restart, correctXA];
  355. },
  356. /**
  357. * Create floor blocks for the level in create()
  358. */
  359. renderFloorBlocks: (direc, lineColor, lineWidth, divisor, correctXA) => {
  360. let correctXB = 0;
  361. let total = 8 * divisor; // Number of floor blocks
  362. const blockWidth = self.default.width / divisor; // Width of each floor block
  363. const renderLabels = () => {
  364. for (let i = 0; i <= 8; i++) {
  365. const x = self.default.x0 + (i + 1) * self.default.width * direc;
  366. const y = self.default.y0 + self.default.height + 45 - 65;
  367. let numberX = x;
  368. let numberText = i;
  369. let numberCircleSize = 45;
  370. let numberFont = {
  371. ...textStyles.h3_,
  372. fill: lineColor,
  373. font: 'bold ' + textStyles.h3_.font,
  374. };
  375. if (gameOperation === 'minus') {
  376. numberX = i !== 0 ? x - 2 : x;
  377. numberText = -i;
  378. numberCircleSize = 45;
  379. numberFont.font = 'bold ' + textStyles.h4_.font;
  380. }
  381. game.add.geom
  382. .circle(x, y, numberCircleSize, undefined, 0, colors.white, 1)
  383. .anchor(0, 0.25);
  384. game.add.text(numberX, y + 2, numberText, numberFont);
  385. }
  386. };
  387. // If game is type (b), select a random floor x position
  388. if (gameMode === 'b') {
  389. self.stack.correctIndex = game.math.randomInRange(
  390. 0,
  391. self.stack.list.length - 1
  392. ); // Correct stacked index
  393. correctXB = self.default.x0 + self.default.width * direc;
  394. for (let i = 0; i <= self.stack.correctIndex; i++) {
  395. correctXB += self.stack.list[i].width * direc; // Equivalent x position on the floor
  396. }
  397. }
  398. // Render floor blocks
  399. for (let i = 0, shouldUpdateIndex = true; i < total; i++) {
  400. const curX =
  401. self.default.x0 + (self.default.width + i * blockWidth) * direc;
  402. // If game is type (a), iterate until find equivalent floor index
  403. if (gameMode === 'a' && shouldUpdateIndex) {
  404. if (
  405. (gameOperation == 'plus' && curX >= correctXA) ||
  406. (gameOperation == 'minus' && curX <= correctXA)
  407. ) {
  408. self.floor.correctIndex = i - 1; // Set index of correct floor block
  409. shouldUpdateIndex = false;
  410. }
  411. }
  412. // If game is type (b), stop iterating after find equivalent floor block
  413. if (gameMode === 'b') {
  414. if (
  415. (gameOperation == 'plus' && curX >= correctXB) ||
  416. (gameOperation == 'minus' && curX <= correctXB)
  417. ) {
  418. total = i;
  419. break;
  420. }
  421. }
  422. // Render floor block
  423. const curBlock = game.add.geom.rect(
  424. curX,
  425. self.default.y0,
  426. blockWidth,
  427. self.default.height + 10,
  428. colors.blueBgInsideLevel,
  429. 1,
  430. colors.gray,
  431. lineWidth
  432. );
  433. const anchor = gameOperation == 'minus' ? 1 : 0;
  434. curBlock.anchor(anchor, 0);
  435. curBlock.blockValue = 1;
  436. // If game is type (a), add events to floor blocks
  437. if (gameMode === 'a') {
  438. curBlock.fillColor = 'transparent';
  439. curBlock.blockIndex = i;
  440. }
  441. // Add current block to list
  442. self.floor.list.push(curBlock);
  443. }
  444. if (gameMode === 'b') {
  445. self.floor.selectedIndex = total - 1; // Computer generated correct floor index
  446. self.floor.correctX = correctXB;
  447. } else {
  448. self.floor.correctX = correctXA;
  449. }
  450. // Creates labels on the floor to display the numbers
  451. renderLabels();
  452. if (isDebugMode) {
  453. console.log(
  454. `------------------------ setup floor
  455. \nDivisor (gameDifficulty / if 3 then 4): ${divisor}
  456. ${
  457. gameMode === 'a'
  458. ? `\nTotal blocks (A) (divisor * 8): ${divisor} * 8 = ${
  459. divisor * 8
  460. }`
  461. : `\nTotal blocks (B) (((equiv. to stack))): ${self.floor.list.length}`
  462. }
  463. ${
  464. gameMode === 'a'
  465. ? `\nCorrect index (A) (((equival. to stack))): ${self.floor.correctIndex}`
  466. : ''
  467. }
  468. `
  469. );
  470. }
  471. },
  472. renderCharacters: () => {
  473. self.tractor = game.add.sprite(
  474. self.default.x0,
  475. self.default.y0,
  476. 'tractor',
  477. 0,
  478. 1
  479. );
  480. if (gameOperation == 'plus') {
  481. self.tractor.anchor(1, 1);
  482. self.tractor.animation = ['move', [0, 1, 2, 3, 4], 4];
  483. } else {
  484. self.tractor.anchor(0, 1);
  485. self.tractor.animation = ['move', [5, 6, 7, 8, 9], 4];
  486. self.tractor.curFrame = 5;
  487. }
  488. },
  489. renderMainUI: () => {
  490. // Help pointer
  491. self.ui.help = game.add.image(0, 0, 'pointer', 1.7, 0);
  492. if (gameMode === 'b') self.ui.help.anchor(0.25, 0.7);
  493. else self.ui.help.anchor(0.2, 0);
  494. // Selection Arrow
  495. if (gameMode === 'a') {
  496. self.ui.arrow = game.add.image(
  497. self.default.arrowX0,
  498. self.default.y0,
  499. 'arrow_down',
  500. 1.5
  501. );
  502. self.ui.arrow.anchor(0.5, 1);
  503. self.ui.arrow.alpha = 0.5;
  504. }
  505. // Intro text
  506. const correctMessage =
  507. gameMode === 'a'
  508. ? game.lang.squareOne_intro_a
  509. : game.lang.squareOne_intro_b;
  510. const treatedMessage = correctMessage.split('\\n');
  511. const font = textStyles.h1_;
  512. self.ui.message = [];
  513. self.ui.message.push(
  514. game.add.text(
  515. context.canvas.width / 2,
  516. 170,
  517. treatedMessage[0] + '\n' + treatedMessage[1],
  518. font
  519. )
  520. );
  521. },
  522. renderOperationUI_new: () => {
  523. /**
  524. *
  525. * (DOING)
  526. * if game mode A:
  527. * - left: (1) selected floor position (user selection)
  528. * - right: (2) expected floor position equivalent to the stack of blocks (pre-set)
  529. *
  530. * (TODO)
  531. * if game mode B:
  532. * - left: (3) floor position equivalent to the stack of blocks (user selection)
  533. * - right: (4) generated floor position (pre-set)
  534. */
  535. const divisor = gameDifficulty == 3 ? 4 : gameDifficulty;
  536. const renderFloorFractions = (lastIndex, divisor, msg) => {
  537. const operator = gameOperation === 'minus' ? '-' : '+';
  538. const index = lastIndex;
  539. const blocks = index + 1;
  540. const valueReal = blocks / divisor;
  541. const valueFloor = Math.floor(valueReal);
  542. const valueRest = valueReal - valueFloor;
  543. let fracNomin = (fracDenomin = fracLine = '');
  544. // adds sign on the left of the equation
  545. if (gameOperation === 'minus') {
  546. fracNomin += ' ';
  547. fracDenomin += ' ';
  548. fracLine += operator;
  549. }
  550. // 1 _ _
  551. if (valueFloor) {
  552. fracNomin += ' ';
  553. fracDenomin += ' ';
  554. fracLine += valueFloor;
  555. }
  556. // _ + _
  557. if (valueFloor && valueRest) {
  558. fracNomin += ' ';
  559. fracDenomin += ' ';
  560. fracLine += operator;
  561. }
  562. // _ _ 1/5
  563. if (valueRest) {
  564. fracNomin += `${valueRest * divisor}`;
  565. fracDenomin += `${divisor}`;
  566. fracLine += '-';
  567. }
  568. return [fracNomin, fracDenomin, fracLine, valueReal];
  569. };
  570. const renderStackFractions = (lastIndex, msg) => {
  571. const operator = gameOperation === 'minus' ? '-' : '+';
  572. const index = lastIndex;
  573. const blocks = index + 1;
  574. const nominators = [];
  575. const denominators = [];
  576. const values = [];
  577. let valueReal = 0;
  578. let fracNomin = (fracDenomin = fracLine = '');
  579. for (let i = 0; i < blocks; i++) {
  580. const m = self.stack.list[i].fraction.denominator || 1;
  581. const temp = self.stack.list[i].fraction.nominator || 0;
  582. const n = gameOperation === 'minus' ? -temp : +temp;
  583. const nm = n / m;
  584. nominators[i] = n + 0;
  585. denominators[i] = m + 0;
  586. values[i] = nm;
  587. valueReal += nm;
  588. }
  589. for (let i = 0; i < blocks; i++) {
  590. const valueReal = values[i];
  591. const valueFloor = Math.floor(valueReal);
  592. const valueRest = valueReal - valueFloor;
  593. if (i > 0 || gameOperation === 'minus') {
  594. fracNomin += ' ';
  595. fracDenomin += ' ';
  596. fracLine += operator;
  597. }
  598. if (valueFloor && !valueRest) {
  599. fracNomin += ' ';
  600. fracDenomin += ' ';
  601. fracLine += valueFloor;
  602. }
  603. if (valueRest) {
  604. fracNomin += `${nominators[i]}`;
  605. fracDenomin += `${denominators[i]}`;
  606. fracLine += '-';
  607. }
  608. }
  609. return [fracNomin, fracDenomin, fracLine, valueReal];
  610. };
  611. // Initial setup
  612. const font = textStyles.fraction;
  613. font.fill = colors.black;
  614. const padding = 100;
  615. const offsetX = 100;
  616. const widthOfChar = 35;
  617. const x0 = padding;
  618. const y0 = context.canvas.height / 3;
  619. let nextX = x0;
  620. const cardHeight = 400;
  621. const cardX = x0 - padding;
  622. const cardY = y0;
  623. const renderList = [];
  624. // Render Card
  625. const card = game.add.geom.rect(
  626. cardX,
  627. cardY,
  628. 0,
  629. cardHeight,
  630. colors.blueLight,
  631. 0.5,
  632. colors.blueDark,
  633. 8
  634. );
  635. card.id = 'card';
  636. card.anchor(0, 0.5);
  637. renderList.push(card);
  638. // Fraction setup
  639. console.clear();
  640. const [floorNominators, floorDenominators, floorLines, floorValue] =
  641. renderFloorFractions(
  642. self.floor.selectedIndex,
  643. divisor,
  644. 'LEFT SIDE - a fração escolhida no chão é...\n\n'
  645. );
  646. renderFloorFractions(
  647. self.floor.correctIndex,
  648. divisor,
  649. '\n\nRIGHT SIDE 1 - a fração CORRETA no chão é...\n\n'
  650. );
  651. const [stackNominators, stackDenominators, stackLines, stackValue] =
  652. renderStackFractions(
  653. self.stack.selectedIndex,
  654. '\n\nRIGHT SIDE 2 - a fração CORRETA na stack é...\n\n'
  655. );
  656. const renderFloorOperationLine = (x) => {
  657. font.fill = colors.black;
  658. const floorNom = game.add.text(
  659. x + offsetX / 2,
  660. y0,
  661. floorNominators,
  662. font,
  663. 60
  664. );
  665. const floorDenom = game.add.text(
  666. x + offsetX / 2,
  667. y0 + 70,
  668. floorDenominators,
  669. font,
  670. 60
  671. );
  672. const floorLin = game.add.text(
  673. x + offsetX / 2,
  674. y0 + 35,
  675. floorLines,
  676. font,
  677. 60
  678. );
  679. renderList.push(floorNom);
  680. renderList.push(floorDenom);
  681. renderList.push(floorLin);
  682. };
  683. const renderStackOperationLine = (x) => {
  684. font.fill = colors.black;
  685. const stackNom = game.add.text(
  686. x + offsetX / 2,
  687. y0,
  688. stackNominators,
  689. font,
  690. 60
  691. );
  692. const stackDenom = game.add.text(
  693. x + offsetX / 2,
  694. y0 + 70,
  695. stackDenominators,
  696. font,
  697. 60
  698. );
  699. const stackLin = game.add.text(
  700. x + offsetX / 2,
  701. y0 + 35,
  702. stackLines,
  703. font,
  704. 60
  705. );
  706. renderList.push(stackNom);
  707. renderList.push(stackDenom);
  708. renderList.push(stackLin);
  709. };
  710. // Render LEFT part of the operation
  711. if (gameMode === 'a') renderFloorOperationLine(x0);
  712. else renderStackOperationLine(x0);
  713. let curNominators = gameMode === 'a' ? floorNominators : stackNominators;
  714. nextX = x0 + (curNominators.length + 2) * widthOfChar;
  715. // Render middle sign - equal by default
  716. font.fill = colors.green;
  717. let comparisonSign = '=';
  718. // Render middle sign - if not equal
  719. if (floorValue != stackValue) {
  720. font.fill = colors.red;
  721. let leftSideIsLarger = floorValue > stackValue;
  722. if (gameMode === 'b') leftSideIsLarger = !leftSideIsLarger;
  723. if (gameOperation === 'minus') leftSideIsLarger = !leftSideIsLarger;
  724. comparisonSign = leftSideIsLarger ? '>' : '<';
  725. }
  726. renderList.push(game.add.text(nextX, y0 + 35, comparisonSign, font));
  727. // Render RIGHT part of the operation
  728. if (gameMode === 'a') renderStackOperationLine(nextX);
  729. else renderFloorOperationLine(nextX);
  730. curNominators = gameMode === 'a' ? stackNominators : floorNominators;
  731. const resultWidth = (curNominators.length + 2) * widthOfChar;
  732. const cardWidth = nextX - x0 + resultWidth + padding * 2;
  733. card.width = cardWidth;
  734. const endSignX = (context.canvas.width - cardWidth) / 2 + cardWidth;
  735. // Center Card
  736. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  737. self.fractionOperationUI = renderList;
  738. return endSignX;
  739. },
  740. renderOperationUI: () => {
  741. let validBlocks = [];
  742. const lastValidIndex =
  743. gameMode === 'a' ? self.stack.curIndex : self.stack.selectedIndex;
  744. for (let i = 0; i <= lastValidIndex; i++) {
  745. validBlocks.push(self.stack.list[i]);
  746. }
  747. const font = textStyles.fraction;
  748. font.fill = colors.green;
  749. const nominators = [];
  750. const denominators = [];
  751. const renderList = [];
  752. const padding = 100;
  753. const offsetX = 100;
  754. const widthOfChar = 35;
  755. const x0 = padding;
  756. const y0 = context.canvas.height / 3;
  757. let nextX = x0;
  758. const cardHeight = 400;
  759. const cardX = x0 - padding;
  760. const cardY = y0; // + cardHeight / 4;
  761. // Card
  762. const card = game.add.geom.rect(
  763. cardX,
  764. cardY,
  765. 0,
  766. cardHeight,
  767. colors.blueLight,
  768. 0.5,
  769. colors.blueDark,
  770. 8
  771. );
  772. card.id = 'card';
  773. card.anchor(0, 0.5);
  774. renderList.push(card);
  775. // Fraction list
  776. for (let i in validBlocks) {
  777. const curFraction = validBlocks[i].fraction;
  778. const curFractionString = curFraction.labels[0].name;
  779. let curFractionSign = i !== '0' ? '+' : '';
  780. if (curFraction.labels[1].name === '-') {
  781. curFractionSign = '-';
  782. font.fill = colors.red;
  783. }
  784. const fraction = game.add.text(
  785. x0 + i * offsetX + offsetX / 2,
  786. curFractionString === '1' ? y0 + 40 : y0,
  787. curFractionString,
  788. font,
  789. 60
  790. );
  791. fraction.lineHeight = 70;
  792. renderList.push(
  793. game.add.text(x0 + i * offsetX, y0 + 35, curFractionSign, font)
  794. );
  795. renderList.push(fraction);
  796. renderList.push(
  797. game.add.text(
  798. x0 + offsetX / 2 + i * offsetX,
  799. y0,
  800. curFractionString === '1' ? '' : '_',
  801. font
  802. )
  803. );
  804. nominators.push(curFraction.nominator);
  805. denominators.push(curFraction.denominator);
  806. }
  807. // Setup for fraction operation with least common multiple
  808. font.fill = colors.black;
  809. const updatedNominators = [];
  810. const mmc = game.math.mmcArray(denominators);
  811. let resultNominator = 0;
  812. for (let i in nominators) {
  813. const temp = nominators[i] * (mmc / denominators[i]);
  814. updatedNominators.push(temp);
  815. resultNominator += temp;
  816. }
  817. const resultNominatorUnsigned =
  818. resultNominator < 0 ? -resultNominator : resultNominator;
  819. const resultAux = resultNominator / mmc;
  820. const result =
  821. ('' + resultAux).length > 4 ? resultAux.toFixed(2) : resultAux;
  822. // Fraction operation with least common multiple
  823. nextX = x0 + validBlocks.length * offsetX + 20;
  824. // Fraction result
  825. renderList.push(game.add.text(nextX, y0 + 35, '=', font));
  826. font.align = 'center';
  827. nextX += offsetX;
  828. if (result < 0) {
  829. nextX += 60;
  830. renderList.push(game.add.text(nextX - 80, y0 + 35, '-', font));
  831. nextX -= 30;
  832. }
  833. const fractionResult = game.add.text(
  834. nextX,
  835. mmc === 1 || resultNominatorUnsigned === 0 ? y0 + 40 : y0,
  836. mmc === 1 || resultNominatorUnsigned === 0
  837. ? resultNominatorUnsigned
  838. : resultNominatorUnsigned + '\n' + mmc,
  839. font
  840. );
  841. fractionResult.lineHeight = 70;
  842. renderList.push(fractionResult);
  843. const fractionLine = game.add.geom.line(
  844. nextX,
  845. y0 + 15,
  846. nextX + 60,
  847. y0 + 15,
  848. 4,
  849. colors.black,
  850. mmc === 1 || resultNominatorUnsigned === 0 ? 0 : 1
  851. );
  852. fractionLine.anchor(0.5, 0);
  853. renderList.push(fractionLine);
  854. // Fraction result simplified setup
  855. const mdcAux = game.math.mdc(resultNominator, mmc);
  856. const mdc = mdcAux < 0 ? -mdcAux : mdcAux;
  857. if (mdc !== 1 && resultNominatorUnsigned !== 0) {
  858. nextX += offsetX;
  859. renderList.push(game.add.text(nextX, y0 + 35, '=', font));
  860. nextX += offsetX;
  861. renderList.push(
  862. game.add.text(nextX - 50, y0 + 35, result > 0 ? '' : '-', font)
  863. );
  864. renderList.push(
  865. game.add.text(nextX, y0, resultNominatorUnsigned / mdc, font)
  866. );
  867. renderList.push(game.add.text(nextX, y0 + 70, mmc / mdc, font));
  868. const fractionLine = game.add.geom.line(
  869. nextX,
  870. y0 + 15,
  871. nextX + 60,
  872. y0 + 15,
  873. 4,
  874. colors.black
  875. );
  876. fractionLine.anchor(0.5, 0);
  877. renderList.push(fractionLine);
  878. }
  879. // Decimal result
  880. let resultWidth = '_'.length * widthOfChar;
  881. const cardWidth = nextX - x0 + resultWidth + padding * 2;
  882. card.width = cardWidth;
  883. const endSignX = (context.canvas.width - cardWidth) / 2 + cardWidth;
  884. // Center Card
  885. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  886. self.fractionOperationUI = renderList;
  887. return endSignX;
  888. },
  889. renderEndUI: () => {
  890. let btnColor = colors.green;
  891. let btnText = game.lang.continue;
  892. if (!self.control.isCorrect) {
  893. btnColor = colors.red;
  894. btnText = game.lang.retry;
  895. }
  896. // continue button
  897. self.ui.continue.button = game.add.geom.rect(
  898. context.canvas.width / 2,
  899. context.canvas.height / 2 + 100,
  900. 450,
  901. 100,
  902. btnColor
  903. );
  904. self.ui.continue.button.anchor(0.5, 0.5);
  905. self.ui.continue.text = game.add.text(
  906. context.canvas.width / 2,
  907. context.canvas.height / 2 + 16 + 100,
  908. btnText,
  909. textStyles.btn
  910. );
  911. },
  912. // UPDATE HANDLERS
  913. animateTractorHandler: () => {
  914. // Move
  915. self.tractor.x += self.animation.speed;
  916. self.stack.list.forEach((block) => (block.x += self.animation.speed));
  917. // If the current block is 1/n (not 1/1) we need to consider the
  918. // extra space the truck needs to pass after the blocks falls but
  919. // before reaching the next block
  920. const curBlockExtra =
  921. (self.default.width - self.stack.list[self.stack.curIndex].width) *
  922. self.control.direc;
  923. const canLowerBlocks =
  924. (gameOperation == 'plus' &&
  925. self.stack.list[0].x >= self.stack.curBlockEndX + curBlockExtra) ||
  926. (gameOperation == 'minus' &&
  927. self.stack.list[0].x <= self.stack.curBlockEndX + curBlockExtra);
  928. if (canLowerBlocks) {
  929. const endAnimation = self.utils.lowerBlocksHandler();
  930. if (!endAnimation) {
  931. self.animation.animateTractor = false;
  932. self.control.checkAnswer = true;
  933. }
  934. }
  935. },
  936. lowerBlocksHandler: () => {
  937. self.floor.curIndex += self.stack.list[self.stack.curIndex].blockValue;
  938. const tooManyStackBlocks = self.floor.curIndex > self.floor.selectedIndex;
  939. if (tooManyStackBlocks) return false;
  940. // fill floor
  941. for (let i = 0; i <= self.floor.curIndex; i++) {
  942. self.floor.list[i].fillColor = 'transparent';
  943. }
  944. // lower blocks
  945. self.stack.list.forEach((block) => {
  946. block.y += self.default.height;
  947. });
  948. // hide current block
  949. self.stack.list[self.stack.curIndex].alpha = 0;
  950. const isLastFloorBlock = self.floor.curIndex === self.floor.selectedIndex;
  951. const notEnoughStackBlocks =
  952. self.stack.curIndex === self.stack.list.length - 1;
  953. if (isLastFloorBlock || notEnoughStackBlocks) return false;
  954. // update stack blocks
  955. self.stack.curIndex++;
  956. self.stack.curBlockEndX +=
  957. self.stack.list[self.stack.curIndex].width * self.control.direc;
  958. return true;
  959. },
  960. checkAnswerHandler: () => {
  961. game.timer.stop();
  962. game.animation.stop(self.tractor.animation[0]);
  963. if (gameMode === 'a') self.ui.arrow.alpha = 0;
  964. self.control.isCorrect =
  965. gameMode === 'a'
  966. ? self.floor.selectedIndex === self.floor.correctIndex
  967. : self.stack.selectedIndex === self.stack.correctIndex;
  968. const x = self.utils.renderOperationUI_new();
  969. // Give feedback to player and turns on sprite animation
  970. if (self.control.isCorrect) {
  971. completedLevels++; // Increases number os finished levels
  972. if (audioStatus) game.audio.okSound.play();
  973. game.animation.play(self.tractor.animation[0]);
  974. game.add
  975. .image(x + 50, context.canvas.height / 3, 'answer_correct')
  976. .anchor(0.5, 0.5);
  977. if (isDebugMode) console.log('Completed Levels: ' + completedLevels);
  978. } else {
  979. if (audioStatus) game.audio.errorSound.play();
  980. game.add
  981. .image(x, context.canvas.height / 3, 'answer_wrong')
  982. .anchor(0.5, 0.5);
  983. }
  984. self.fetch.postScore();
  985. self.control.checkAnswer = false;
  986. self.animation.animateEnding = true;
  987. },
  988. animateEndingHandler: () => {
  989. // ANIMATE ENDING
  990. self.control.count++;
  991. // If CORRECT ANSWER runs final tractor animation (else tractor desn't move, just wait)
  992. if (self.control.isCorrect) self.tractor.x += self.animation.speed;
  993. if (self.control.count === 100) {
  994. self.utils.renderEndUI();
  995. self.control.showEndInfo = true;
  996. if (self.control.isCorrect) canGoToNextMapPosition = true;
  997. else canGoToNextMapPosition = false;
  998. }
  999. },
  1000. endLevel: () => {
  1001. game.state.start('map');
  1002. },
  1003. // INFORMATION
  1004. /**
  1005. * Display correct answer
  1006. */
  1007. showAnswer: () => {
  1008. if (!self.control.hasClicked) {
  1009. // On gameMode (a)
  1010. if (gameMode === 'a') {
  1011. const aux = self.floor.list[0];
  1012. self.ui.help.x =
  1013. self.floor.correctX - (aux.width / 2) * self.control.direc;
  1014. self.ui.help.y = self.default.y0;
  1015. // On gameMode (b)
  1016. } else {
  1017. const aux = self.stack.list[self.stack.correctIndex];
  1018. self.ui.help.x = aux.x + (aux.width / 2) * self.control.direc;
  1019. self.ui.help.y = aux.y;
  1020. }
  1021. self.ui.help.alpha = 0.7;
  1022. }
  1023. },
  1024. // EVENT HANDLERS
  1025. /**
  1026. * Function called by self.events.onInputDown() when player clicks on a valid rectangle.
  1027. */
  1028. clickHandler: (clickedIndex, curSet) => {
  1029. if (!self.control.hasClicked && !self.animation.animateEnding) {
  1030. document.body.style.cursor = 'auto';
  1031. // Play beep sound
  1032. if (audioStatus) game.audio.popSound.play();
  1033. // Disable show answer nav icon
  1034. navigation.disableIcon(navigation.showAnswerIcon);
  1035. // Hide intro message
  1036. self.ui.message[0].alpha = 0;
  1037. // Hide labels
  1038. if (showFractions) {
  1039. self.stack.list.forEach((block) => {
  1040. block.fraction.labels.forEach((lbl) => {
  1041. if (lbl) lbl.alpha = 0;
  1042. });
  1043. });
  1044. }
  1045. // Hide solution pointer
  1046. if (self.ui.help != undefined) self.ui.help.alpha = 0;
  1047. // Hide unselected blocks
  1048. for (let i = curSet.list.length - 1; i > clickedIndex; i--) {
  1049. curSet.list[i].alpha = 0;
  1050. }
  1051. // Save selected index
  1052. curSet.selectedIndex = clickedIndex;
  1053. if (gameMode === 'a') {
  1054. self.ui.arrow.alpha = 0;
  1055. } else {
  1056. // update list size
  1057. self.stack.list.length = curSet.selectedIndex + 1;
  1058. }
  1059. // Turn tractor animation on
  1060. game.animation.play(self.tractor.animation[0]);
  1061. self.animation.animateTractor = true;
  1062. self.control.hasClicked = true;
  1063. }
  1064. },
  1065. /**
  1066. * Function called by self.events.onInputOver() when cursor is over a valid rectangle
  1067. *
  1068. * @param {object} cur rectangle the cursor is over
  1069. */
  1070. overHandler: (cur) => {
  1071. if (!self.control.hasClicked) {
  1072. document.body.style.cursor = 'pointer';
  1073. if (gameMode === 'a') {
  1074. for (let i in self.floor.list) {
  1075. self.floor.list[i].fillColor =
  1076. i <= cur.blockIndex ? colors.blueBgInsideLevel : 'transparent';
  1077. }
  1078. self.floor.selectedIndex = cur.blockIndex;
  1079. } else {
  1080. for (let i in self.stack.list) {
  1081. const alpha = i <= cur.blockIndex ? 1 : 0.4;
  1082. self.stack.list[i].alpha = alpha;
  1083. if (showFractions) {
  1084. self.stack.list[i].fraction.labels.forEach((lbl) => {
  1085. if (lbl) lbl.alpha = alpha;
  1086. });
  1087. }
  1088. }
  1089. self.stack.selectedIndex = cur.blockIndex;
  1090. }
  1091. }
  1092. },
  1093. /**
  1094. * Function called by self.events.onInputOver() when cursos is out of a valid rectangle
  1095. */
  1096. outHandler: () => {
  1097. if (!self.control.hasClicked) {
  1098. document.body.style.cursor = 'auto';
  1099. if (gameMode === 'a') {
  1100. for (let i in self.floor.list) {
  1101. self.floor.list[i].fillColor = 'transparent';
  1102. }
  1103. self.floor.selectedIndex = undefined;
  1104. } else {
  1105. for (let i in self.stack.list) {
  1106. self.stack.list[i].alpha = 1;
  1107. if (showFractions) {
  1108. self.stack.list[i].fraction.labels.forEach((lbl) => {
  1109. if (lbl) lbl.alpha = 1;
  1110. });
  1111. }
  1112. }
  1113. self.stack.selectedIndex = undefined;
  1114. }
  1115. }
  1116. },
  1117. },
  1118. events: {
  1119. /**
  1120. * Called by mouse click event
  1121. *
  1122. * @param {object} mouseEvent contains the mouse click coordinates
  1123. */
  1124. onInputDown: (mouseEvent) => {
  1125. const x = game.math.getMouse(mouseEvent).x;
  1126. const y = game.math.getMouse(mouseEvent).y;
  1127. // click blocks
  1128. const curSet = gameMode == 'a' ? self.floor : self.stack;
  1129. for (let i in curSet.list) {
  1130. if (game.math.isOverIcon(x, y, curSet.list[i])) {
  1131. self.utils.clickHandler(+i, curSet);
  1132. break;
  1133. }
  1134. }
  1135. // Continue button
  1136. if (self.control.showEndInfo) {
  1137. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  1138. if (audioStatus) game.audio.popSound.play();
  1139. self.utils.endLevel();
  1140. }
  1141. }
  1142. navigation.onInputDown(x, y);
  1143. game.render.all();
  1144. },
  1145. /**
  1146. * Called by mouse move event
  1147. *
  1148. * @param {object} mouseEvent contains the mouse move coordinates
  1149. */
  1150. onInputOver: (mouseEvent) => {
  1151. const x = game.math.getMouse(mouseEvent).x;
  1152. const y = game.math.getMouse(mouseEvent).y;
  1153. let isOverFloor = false;
  1154. let isOverStack = false;
  1155. if (gameMode === 'a') {
  1156. self.floor.list.forEach((cur) => {
  1157. // hover floor blocks
  1158. if (game.math.isOverIcon(x, y, cur)) {
  1159. isOverFloor = true;
  1160. self.utils.overHandler(cur);
  1161. }
  1162. // move arrow
  1163. if (
  1164. !self.control.hasClicked &&
  1165. !self.animation.animateEnding &&
  1166. game.math.isOverIcon(x, self.default.y0, cur)
  1167. ) {
  1168. self.ui.arrow.x = x;
  1169. }
  1170. });
  1171. if (!isOverFloor) self.utils.outHandler('a');
  1172. }
  1173. if (gameMode === 'b') {
  1174. // hover stack blocks
  1175. self.stack.list.forEach((cur) => {
  1176. if (game.math.isOverIcon(x, y, cur)) {
  1177. isOverStack = true;
  1178. self.utils.overHandler(cur);
  1179. }
  1180. });
  1181. if (!isOverStack) self.utils.outHandler('b');
  1182. }
  1183. // Continue button
  1184. if (self.control.showEndInfo) {
  1185. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  1186. // If pointer is over icon
  1187. document.body.style.cursor = 'pointer';
  1188. self.ui.continue.button.scale =
  1189. self.ui.continue.button.initialScale * 1.1;
  1190. self.ui.continue.text.style = textStyles.btnLg;
  1191. } else {
  1192. // If pointer is not over icon
  1193. document.body.style.cursor = 'auto';
  1194. self.ui.continue.button.scale =
  1195. self.ui.continue.button.initialScale * 1;
  1196. self.ui.continue.text.style = textStyles.btn;
  1197. }
  1198. }
  1199. navigation.onInputOver(x, y);
  1200. game.render.all();
  1201. },
  1202. },
  1203. fetch: {
  1204. /**
  1205. * Saves players data after level ends - to be sent to database <br>
  1206. *
  1207. * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
  1208. *
  1209. * @see /php/save.php
  1210. */
  1211. postScore: () => {
  1212. // Creates string that is going to be sent to db
  1213. const data =
  1214. '&line_game=' +
  1215. gameShape +
  1216. '&line_mode=' +
  1217. gameMode +
  1218. '&line_oper=' +
  1219. gameOperation +
  1220. '&line_leve=' +
  1221. gameDifficulty +
  1222. '&line_posi=' +
  1223. curMapPosition +
  1224. '&line_resu=' +
  1225. self.control.isCorrect +
  1226. '&line_time=' +
  1227. game.timer.elapsed +
  1228. '&line_deta=' +
  1229. 'numBlocks:' +
  1230. self.stack.list.length +
  1231. ', valBlocks: ' +
  1232. self.control.divisorsList + // Ends in ','
  1233. ' blockIndex: ' +
  1234. self.stack.selectedIndex +
  1235. ', floorIndex: ' +
  1236. self.floor.selectedIndex;
  1237. // FOR MOODLE
  1238. sendToDatabase(data);
  1239. },
  1240. },
  1241. };