squareTwo.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /******************************
  2. * This file holds game states.
  3. ******************************/
  4. /** [GAME STATE]
  5. *
  6. * .squareTwo. = gameName
  7. * .../...\...
  8. * ..a.....b.. = gameMode
  9. * ....\./....
  10. * .....|.....
  11. * ..equals... = gameOperation
  12. * .....|.....
  13. * .1,2,3,4,5. = gameDifficulty
  14. *
  15. * Character : kid
  16. * Theme : (not themed)
  17. * Concept : player select equivalent dividends for fractions with different divisors
  18. * Represent fractions as : subdivided rectangles
  19. *
  20. * Game modes can be :
  21. *
  22. * a : equivalence of fractions
  23. * top has more subdivisions
  24. * b : equivalence of fractions
  25. * bottom has more subdivisions
  26. *
  27. * Operations :
  28. *
  29. * equals : Player selects equivalent fractions of both blocks
  30. *
  31. * @namespace
  32. */
  33. const squareTwo = {
  34. ui: undefined,
  35. control: undefined,
  36. blocks: undefined,
  37. /**
  38. * Main code
  39. */
  40. create: function () {
  41. this.ui = {
  42. message: undefined,
  43. continue: {
  44. // modal: undefined,
  45. button: undefined,
  46. text: undefined,
  47. },
  48. };
  49. this.control = {
  50. blockWidth: 600,
  51. blockHeight: 75,
  52. isCorrect: false,
  53. showEndInfo: false,
  54. animationDelay: 0,
  55. startDelay: false,
  56. startEndAnimation: false,
  57. };
  58. this.blocks = {
  59. top: {
  60. list: [], // List of block objects
  61. auxBlocks: [], // List of shadow under selection blocks
  62. fractions: [], // Fractions
  63. selectedAmount: 0,
  64. hasClicked: false, // Check if player clicked blocks from (a)
  65. animate: false, // Animate blocks from (a)
  66. warningText: undefined,
  67. label: undefined,
  68. },
  69. bottom: {
  70. list: [],
  71. auxBlocks: [],
  72. fractions: [],
  73. selectedAmount: 0,
  74. hasClicked: false,
  75. animate: false,
  76. warningText: undefined,
  77. label: undefined,
  78. },
  79. };
  80. renderBackground();
  81. // Calls function that loads navigation icons
  82. // FOR MOODLE
  83. if (moodle) {
  84. navigation.add.right(['audio']);
  85. } else {
  86. navigation.add.left(['back', 'menu'], 'customMenu');
  87. navigation.add.right(['audio']);
  88. }
  89. // Add kid
  90. this.utils.renderCharacters();
  91. this.utils.renderBlockSetup();
  92. this.utils.renderMainUI();
  93. game.timer.start(); // Set a timer for the current level (used in postScore)
  94. game.event.add('click', this.events.onInputDown);
  95. game.event.add('mousemove', this.events.onInputOver);
  96. },
  97. /**
  98. * Game loop
  99. */
  100. update: function () {
  101. // Animate blocks
  102. if (self.blocks.top.animate || self.blocks.bottom.animate) {
  103. self.utils.moveBlocks();
  104. }
  105. // If (a) and (b) are already clicked
  106. if (
  107. !self.control.startDelay &&
  108. !self.control.startEndAnimation &&
  109. self.blocks.top.hasClicked &&
  110. self.blocks.bottom.hasClicked
  111. ) {
  112. self.control.startDelay = true;
  113. }
  114. if (self.control.startDelay && !self.control.startEndAnimation) {
  115. self.utils.startDelayHandler();
  116. }
  117. // Wait a bit and go to map state
  118. if (self.control.startEndAnimation) {
  119. self.utils.runEndAnimation();
  120. }
  121. game.render.all();
  122. },
  123. utils: {
  124. // RENDERS
  125. renderBlockSetup: function () {
  126. // Coordinates for (a) and (b)
  127. let xA, xB, yA, yB;
  128. if (gameMode != 'b') {
  129. // Has more subdivisions on (b)
  130. xA = context.canvas.width / 2 - self.control.blockWidth / 2;
  131. yA = getFrameInfo().y + 100;
  132. xB = xA;
  133. yB = yA + 3 * self.control.blockHeight + 30;
  134. } else {
  135. // Has more subdivisions on (a)
  136. xB = context.canvas.width / 2 - self.control.blockWidth / 2;
  137. yB = getFrameInfo().y + 100;
  138. xA = xB;
  139. yA = yB + 3 * self.control.blockHeight + 30;
  140. }
  141. // Possible points for (a)
  142. const points = [2, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20];
  143. // Random index for 'points'
  144. const randomIndex = game.math.randomInRange(
  145. (gameDifficulty - 1) * 2 + 1,
  146. (gameDifficulty - 1) * 2 + 3
  147. );
  148. // Number of subdivisions of (a) and (b) (blocks)
  149. const totalBlocksA = points[randomIndex];
  150. const totalBlocksB = game.math.randomDivisor(totalBlocksA);
  151. const blockWidthA = self.control.blockWidth / totalBlocksA;
  152. const blockWidthB = self.control.blockWidth / totalBlocksB;
  153. if (isDebugMode) {
  154. console.log(
  155. `Difficulty: ${gameDifficulty}\ncur index: ${randomIndex}, (min index: ${
  156. (gameDifficulty - 1) * 2 + 1
  157. }, max index: ${
  158. (gameDifficulty - 1) * 2 + 3
  159. })\ntotal blocks a: ${totalBlocksA}, total blocks b: ${totalBlocksB}`
  160. );
  161. }
  162. // (a)
  163. self.utils.renderBlocks(
  164. self.blocks.top,
  165. 'top',
  166. totalBlocksA,
  167. blockWidthA,
  168. colors.blueDark,
  169. colors.blueLight,
  170. xA,
  171. yA
  172. );
  173. // (b)
  174. self.utils.renderBlocks(
  175. self.blocks.bottom,
  176. 'bottom',
  177. totalBlocksB,
  178. blockWidthB,
  179. colors.greenDark,
  180. colors.greenLight,
  181. xB,
  182. yB
  183. );
  184. },
  185. renderBlocks: function (
  186. blocks,
  187. blockType,
  188. totalBlocks,
  189. blockWidth,
  190. lineColor,
  191. fillColor,
  192. x0,
  193. y0
  194. ) {
  195. for (let i = 0; i < totalBlocks; i++) {
  196. // Blocks
  197. const curX = x0 + i * blockWidth;
  198. const curBlock = game.add.geom.rect(
  199. curX,
  200. y0,
  201. blockWidth,
  202. self.control.blockHeight,
  203. fillColor,
  204. 0.5,
  205. lineColor,
  206. 4
  207. );
  208. curBlock.position = blockType;
  209. curBlock.index = i;
  210. curBlock.finalX = x0;
  211. blocks.list.push(curBlock);
  212. // Auxiliar blocks (lower alpha)
  213. const alpha = showFractions ? 0.2 : 0;
  214. const curYAux = y0 + self.control.blockHeight + 10;
  215. const curAuxBlock = game.add.geom.rect(
  216. curX,
  217. curYAux,
  218. blockWidth,
  219. self.control.blockHeight,
  220. fillColor,
  221. alpha,
  222. lineColor,
  223. 1
  224. );
  225. blocks.auxBlocks.push(curAuxBlock);
  226. }
  227. // Label - number of blocks (on the right)
  228. let yLabel = y0 + self.control.blockHeight / 2 + 10;
  229. const xLabel = x0 + self.control.blockWidth + 35;
  230. const font = {
  231. ...textStyles.h4_,
  232. font: 'bold ' + textStyles.h4_.font,
  233. fill: lineColor,
  234. };
  235. blocks.label = game.add.text(xLabel, yLabel, blocks.list.length, font);
  236. // 'selected blocks/fraction' label for (a) : at the bottom of (a)
  237. yLabel = y0 + self.control.blockHeight + 40;
  238. blocks.fractions[0] = game.add.text(xLabel, yLabel, '', font);
  239. blocks.fractions[1] = game.add.text(xLabel, yLabel + 10, '___', font);
  240. blocks.fractions[0].alpha = 0;
  241. blocks.fractions[1].alpha = 0;
  242. // Invalid selection text
  243. blocks.warningText = game.add.text(
  244. context.canvas.width / 2,
  245. y0 - 20,
  246. game.lang.s2_error_msg,
  247. { ...font, font: textStyles.h4_.font }
  248. );
  249. blocks.warningText.alpha = 0;
  250. },
  251. renderCharacters: function () {
  252. self.kidAnimation = game.add.sprite(
  253. 100,
  254. context.canvas.height - 128 * 1.5,
  255. 'kid_standing',
  256. 0,
  257. 1.2
  258. );
  259. self.kidAnimation.anchor(0.5, 0.7);
  260. self.kidAnimation.curFrame = 3;
  261. },
  262. renderMainUI: () => {
  263. // Intro text
  264. const treatedMessage = game.lang.squareTwo_intro.split('\\n');
  265. const font = textStyles.h1_;
  266. self.ui.message = [];
  267. self.ui.message.push(
  268. game.add.text(
  269. context.canvas.width / 2,
  270. 170,
  271. treatedMessage[0] + '\n' + treatedMessage[1],
  272. font
  273. )
  274. );
  275. },
  276. renderOperationUI: () => {
  277. const uiList = [
  278. ...self.blocks.top.list,
  279. ...self.blocks.bottom.list,
  280. ...self.blocks.top.fractions,
  281. ...self.blocks.bottom.fractions,
  282. ];
  283. moveList(uiList, -400, 0);
  284. const font = textStyles.fraction;
  285. font.fill = colors.black;
  286. font.align = 'center';
  287. const nominators = [
  288. self.blocks.top.selectedAmount,
  289. self.blocks.bottom.selectedAmount,
  290. ];
  291. const denominators = [
  292. self.blocks.top.list.length,
  293. self.blocks.bottom.list.length,
  294. ];
  295. const renderList = [];
  296. const padding = 100;
  297. const offsetX = 100;
  298. const cardHeight = 400;
  299. const x0 = padding + 400;
  300. const y0 = context.canvas.height / 2;
  301. let nextX = x0;
  302. const cardX = x0 - padding;
  303. const cardY = y0;
  304. // Card
  305. const card = game.add.geom.rect(
  306. cardX,
  307. cardY,
  308. 0,
  309. cardHeight,
  310. colors.blueLight,
  311. 0.5,
  312. colors.blueDark,
  313. 8
  314. );
  315. card.id = 'card';
  316. card.anchor(0, 0.5);
  317. renderList.push(card);
  318. renderList.push(
  319. game.add.text(
  320. nextX,
  321. y0,
  322. nominators[0] + '\n' + denominators[0],
  323. font,
  324. 70
  325. )
  326. );
  327. const topFractionLine = game.add.geom.rect(
  328. nextX,
  329. y0 + 10,
  330. 100,
  331. 4,
  332. colors.black,
  333. 4
  334. );
  335. topFractionLine.anchor(0.5, 0);
  336. renderList.push(topFractionLine);
  337. font.fill = self.control.isCorrect ? colors.green : colors.red;
  338. nextX += offsetX;
  339. renderList.push(
  340. game.add.text(nextX, y0 + 35, self.control.isCorrect ? '=' : '≠', font)
  341. );
  342. font.fill = colors.black;
  343. nextX += offsetX;
  344. renderList.push(
  345. game.add.text(
  346. nextX,
  347. y0,
  348. nominators[1] + '\n' + denominators[1],
  349. font,
  350. 70
  351. )
  352. );
  353. const bottomFractionLine = game.add.geom.rect(
  354. nextX,
  355. y0 + 10,
  356. 100,
  357. 4,
  358. colors.black,
  359. 4
  360. );
  361. bottomFractionLine.anchor(0.5, 0);
  362. renderList.push(bottomFractionLine);
  363. //let resultWidth = ''.length * widthOfChar;
  364. const cardWidth = nextX - x0 + padding * 2;
  365. card.width = cardWidth;
  366. const endSignX =
  367. (context.canvas.width - cardWidth) / 2 + cardWidth + 400 + 50;
  368. // Center Card
  369. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  370. self.fractionOperationUI = renderList;
  371. return endSignX;
  372. },
  373. renderEndUI: () => {
  374. let btnColor = colors.green;
  375. let btnText = game.lang.continue;
  376. if (!self.control.isCorrect) {
  377. btnColor = colors.red;
  378. btnText = game.lang.retry;
  379. }
  380. // continue button
  381. self.ui.continue.button = game.add.geom.rect(
  382. context.canvas.width / 2 + 400,
  383. context.canvas.height / 2 + 280,
  384. 450,
  385. 100,
  386. btnColor
  387. );
  388. self.ui.continue.button.anchor(0.5, 0.5);
  389. self.ui.continue.text = game.add.text(
  390. context.canvas.width / 2 + 400,
  391. context.canvas.height / 2 + 16 + 280,
  392. btnText,
  393. textStyles.btn
  394. );
  395. },
  396. startDelayHandler: () => {
  397. self.control.animationDelay++;
  398. if (self.control.animationDelay === 50) {
  399. self.ui.message[0].alpha = 0;
  400. self.utils.checkAnswer();
  401. self.control.animationDelay = 0;
  402. self.control.startEndAnimation = true;
  403. }
  404. },
  405. // UPDATE
  406. moveBlocks: function () {
  407. ['top', 'bottom'].forEach((cur) => {
  408. if (self.blocks[cur].animate) {
  409. // Lower selected blocks
  410. for (let i = 0; i < self.blocks[cur].selectedAmount; i++) {
  411. self.blocks[cur].list[i].y += 2;
  412. }
  413. // After fully lowering blocks, set fraction value
  414. if (self.blocks[cur].list[0].y >= self.blocks[cur].auxBlocks[0].y) {
  415. self.blocks[cur].fractions[0].name =
  416. self.blocks[cur].selectedAmount +
  417. '\n' +
  418. self.blocks[cur].list.length;
  419. self.blocks[cur].animate = false;
  420. }
  421. }
  422. });
  423. },
  424. checkAnswer: function () {
  425. for (let block of self.blocks.top.auxBlocks) {
  426. block.alpha = 0;
  427. }
  428. for (let block of self.blocks.bottom.auxBlocks) {
  429. block.alpha = 0;
  430. }
  431. // After delay is over, check result
  432. //if (self.control.animationDelay > 50) {
  433. self.control.isCorrect =
  434. self.blocks.top.selectedAmount / self.blocks.top.list.length ==
  435. self.blocks.bottom.selectedAmount / self.blocks.bottom.list.length;
  436. const x = self.utils.renderOperationUI();
  437. if (self.control.isCorrect) {
  438. if (audioStatus) game.audio.okSound.play();
  439. game.add
  440. .image(x + 50, context.canvas.height / 2, 'answer_correct')
  441. .anchor(0.5, 0.5);
  442. completedLevels++;
  443. if (isDebugMode) console.log('Completed Levels: ' + completedLevels);
  444. } else {
  445. if (audioStatus) game.audio.errorSound.play();
  446. game.add
  447. .image(x, context.canvas.height / 2, 'answer_wrong')
  448. .anchor(0.5, 0.5);
  449. }
  450. self.fetch.postScore();
  451. },
  452. runEndAnimation: function () {
  453. self.control.animationDelay++;
  454. if (self.control.animationDelay === 100) {
  455. self.utils.renderEndUI();
  456. self.control.showEndInfo = true;
  457. if (self.control.isCorrect) canGoToNextMapPosition = true;
  458. else canGoToNextMapPosition = false;
  459. }
  460. },
  461. endLevel: function () {
  462. game.state.start('map');
  463. },
  464. // HANDLERS
  465. /**
  466. * Function called by self.onInputDown() when player clicked a valid rectangle.
  467. *
  468. * @param {object} curBlock clicked rectangle : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  469. */
  470. clickSquareHandler: function (curBlock) {
  471. const curSet = curBlock.position;
  472. if (
  473. !self.blocks[curSet].hasClicked &&
  474. curBlock.index != self.blocks[curSet].list.length - 1
  475. ) {
  476. document.body.style.cursor = 'auto';
  477. // Turn auxiliar blocks invisible
  478. for (let i in self.blocks[curSet].list) {
  479. if (i > curBlock.index) self.blocks[curSet].auxBlocks[i].alpha = 0;
  480. }
  481. // Turn value label invisible
  482. self.blocks[curSet].label.alpha = 0;
  483. if (audioStatus) game.audio.popSound.play();
  484. // Save number of selected blocks
  485. self.blocks[curSet].selectedAmount = curBlock.index + 1;
  486. // Set fraction x position
  487. const newX =
  488. curBlock.finalX +
  489. self.blocks[curSet].selectedAmount *
  490. (self.control.blockWidth / self.blocks[curSet].list.length) +
  491. 40;
  492. self.blocks[curSet].fractions[0].x = newX;
  493. self.blocks[curSet].fractions[1].x = newX;
  494. self.blocks[curSet].fractions[0].name = `${curBlock.index + 1}\n${
  495. self.blocks[curSet].list.length
  496. }`;
  497. self.blocks[curSet].fractions[1].alpha = 1;
  498. self.blocks[curSet].hasClicked = true; // Inform player have clicked in current block set
  499. self.blocks[curSet].animate = true; // Let it initiate animation
  500. }
  501. game.render.all();
  502. },
  503. /**
  504. * Function called by self.onInputOver() when cursor is over a valid rectangle.
  505. *
  506. * @param {object} curBlock rectangle the cursor is over : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  507. */
  508. overSquareHandler: function (curBlock) {
  509. const curSet = curBlock.position;
  510. if (!self.blocks[curSet].hasClicked) {
  511. // self.blocks.top.hasClicked || self.blocks.bottom.hasClicked
  512. // If over fraction 'n/n' shows warning message not allowing it
  513. if (curBlock.index == self.blocks[curSet].list.length - 1) {
  514. const otherSet = curSet == 'top' ? 'bottom' : 'top';
  515. self.blocks[curSet].warningText.alpha = 1;
  516. self.blocks[otherSet].warningText.alpha = 0;
  517. self.utils.outSquareHandler(curSet);
  518. } else {
  519. document.body.style.cursor = 'pointer';
  520. self.blocks.top.warningText.alpha = 0;
  521. self.blocks.bottom.warningText.alpha = 0;
  522. // Selected blocks become fully visible
  523. for (let i in self.blocks[curSet].list) {
  524. self.blocks[curSet].list[i].alpha = i <= curBlock.index ? 1 : 0.5;
  525. }
  526. self.blocks[curSet].fractions[0].name = curBlock.index + 1; // Nominator : selected blocks
  527. const newX =
  528. curBlock.finalX +
  529. (curBlock.index + 1) *
  530. (self.control.blockWidth / self.blocks[curSet].list.length) +
  531. 25;
  532. self.blocks[curSet].fractions[0].x = newX;
  533. self.blocks[curSet].fractions[1].x = newX;
  534. self.blocks[curSet].fractions[0].alpha = 1;
  535. }
  536. }
  537. },
  538. /**
  539. * Function called (by self.onInputOver() and self.utils.overSquareHandler()) when cursor is out of a valid rectangle.
  540. *
  541. * @param {object} curSet set of rectangles : can be top (self.blocks.top) or bottom (self.blocks.bottom)
  542. */
  543. outSquareHandler: function (curSet) {
  544. if (!self.blocks[curSet].hasClicked) {
  545. self.blocks[curSet].fractions[0].alpha = 0;
  546. self.blocks[curSet].fractions[1].alpha = 0;
  547. self.blocks[curSet].list.forEach((cur) => {
  548. cur.alpha = 0.5;
  549. });
  550. }
  551. },
  552. },
  553. events: {
  554. /**
  555. * Called by mouse click event
  556. *
  557. * @param {object} mouseEvent contains the mouse click coordinates
  558. */
  559. onInputDown: function (mouseEvent) {
  560. const x = game.math.getMouse(mouseEvent).x;
  561. const y = game.math.getMouse(mouseEvent).y;
  562. // Click block in (a)
  563. self.blocks.top.list.forEach((cur) => {
  564. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  565. });
  566. // Click block in (b)
  567. self.blocks.bottom.list.forEach((cur) => {
  568. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  569. });
  570. // Continue button
  571. if (self.control.showEndInfo) {
  572. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  573. if (audioStatus) game.audio.popSound.play();
  574. self.utils.endLevel();
  575. }
  576. }
  577. // Click navigation icons
  578. navigation.onInputDown(x, y);
  579. game.render.all();
  580. },
  581. /**
  582. * Called by mouse move event
  583. *
  584. * @param {object} mouseEvent contains the mouse move coordinates
  585. */
  586. onInputOver: function (mouseEvent) {
  587. const x = game.math.getMouse(mouseEvent).x;
  588. const y = game.math.getMouse(mouseEvent).y;
  589. let flagA = false;
  590. let flagB = false;
  591. // Mouse over (a) : show fraction
  592. self.blocks.top.list.forEach((cur) => {
  593. if (game.math.isOverIcon(x, y, cur)) {
  594. flagA = true;
  595. self.utils.overSquareHandler(cur);
  596. }
  597. });
  598. if (!flagA) self.utils.outSquareHandler('top');
  599. // Mouse over (b) : show fraction
  600. self.blocks.bottom.list.forEach((cur) => {
  601. if (game.math.isOverIcon(x, y, cur)) {
  602. flagB = true;
  603. self.utils.overSquareHandler(cur);
  604. }
  605. });
  606. if (!flagB) self.utils.outSquareHandler('bottom');
  607. if (!flagA && !flagB) document.body.style.cursor = 'auto';
  608. // Continue button
  609. if (self.control.showEndInfo) {
  610. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  611. // If pointer is over icon
  612. document.body.style.cursor = 'pointer';
  613. self.ui.continue.button.scale =
  614. self.ui.continue.button.initialScale * 1.1;
  615. self.ui.continue.text.style = textStyles.btnLg;
  616. } else {
  617. // If pointer is not over icon
  618. document.body.style.cursor = 'auto';
  619. self.ui.continue.button.scale =
  620. self.ui.continue.button.initialScale * 1;
  621. self.ui.continue.text.style = textStyles.btn;
  622. }
  623. }
  624. // Mouse over navigation icons : show name
  625. navigation.onInputOver(x, y);
  626. game.render.all();
  627. },
  628. },
  629. fetch: {
  630. /**
  631. * Saves players data after level ends - to be sent to database. <br>
  632. *
  633. * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
  634. *
  635. * @see /php/save.php
  636. */
  637. postScore: function () {
  638. // Creates string that is going to be sent to db
  639. const data =
  640. '&line_game=' +
  641. gameShape +
  642. '&line_mode=' +
  643. gameMode +
  644. '&line_oper=Equal' +
  645. '&line_leve=' +
  646. gameDifficulty +
  647. '&line_posi=' +
  648. curMapPosition +
  649. '&line_resu=' +
  650. self.control.isCorrect +
  651. '&line_time=' +
  652. game.timer.elapsed +
  653. '&line_deta=' +
  654. 'numBlocksA: ' +
  655. self.blocks.top.list.length +
  656. ', valueA: ' +
  657. self.blocks.top.selectedAmount +
  658. ', numBlocksB: ' +
  659. self.blocks.bottom.list.length +
  660. ', valueB: ' +
  661. self.blocks.bottom.selectedAmount;
  662. // FOR MOODLE
  663. sendToDatabase(data);
  664. },
  665. },
  666. };