squareTwo.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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.geom.line(
  240. xLabel,
  241. yLabel + 10,
  242. xLabel + 50,
  243. yLabel + 10,
  244. 2,
  245. lineColor
  246. );
  247. blocks.fractions[1].anchor(0.5, 0);
  248. blocks.fractions[0].alpha = 0;
  249. blocks.fractions[1].alpha = 0;
  250. // Invalid selection text
  251. blocks.warningText = game.add.text(
  252. context.canvas.width / 2,
  253. y0 - 20,
  254. game.lang.s2_error_msg,
  255. { ...font, font: textStyles.h4_.font }
  256. );
  257. blocks.warningText.alpha = 0;
  258. },
  259. renderCharacters: function () {
  260. self.kidAnimation = game.add.sprite(
  261. 100,
  262. context.canvas.height - 128 * 1.5,
  263. 'kid_standing',
  264. 0,
  265. 1.2
  266. );
  267. self.kidAnimation.anchor(0.5, 0.7);
  268. self.kidAnimation.curFrame = 3;
  269. },
  270. renderMainUI: () => {
  271. // Intro text
  272. const treatedMessage = game.lang.squareTwo_intro.split('\\n');
  273. const font = textStyles.h1_;
  274. self.ui.message = [];
  275. self.ui.message.push(
  276. game.add.text(
  277. context.canvas.width / 2,
  278. 170,
  279. treatedMessage[0] + '\n' + treatedMessage[1],
  280. font
  281. )
  282. );
  283. },
  284. renderOperationUI: () => {
  285. const uiList = [
  286. ...self.blocks.top.list,
  287. ...self.blocks.bottom.list,
  288. ...self.blocks.top.fractions,
  289. ...self.blocks.bottom.fractions,
  290. ];
  291. moveList(uiList, -400, 0);
  292. const font = textStyles.fraction;
  293. font.fill = colors.black;
  294. font.align = 'center';
  295. const nominators = [
  296. self.blocks.top.selectedAmount,
  297. self.blocks.bottom.selectedAmount,
  298. ];
  299. const denominators = [
  300. self.blocks.top.list.length,
  301. self.blocks.bottom.list.length,
  302. ];
  303. const renderList = [];
  304. const padding = 100;
  305. const offsetX = 100;
  306. const cardHeight = 400;
  307. const x0 = padding + 400;
  308. const y0 = context.canvas.height / 2;
  309. let nextX = x0;
  310. const cardX = x0 - padding;
  311. const cardY = y0;
  312. // Card
  313. const card = game.add.geom.rect(
  314. cardX,
  315. cardY,
  316. 0,
  317. cardHeight,
  318. colors.blueLight,
  319. 0.5,
  320. colors.blueDark,
  321. 8
  322. );
  323. card.id = 'card';
  324. card.anchor(0, 0.5);
  325. renderList.push(card);
  326. renderList.push(
  327. game.add.text(
  328. nextX,
  329. y0,
  330. nominators[0] + '\n' + denominators[0],
  331. font,
  332. 70
  333. )
  334. );
  335. const topFractionLine = game.add.geom.rect(
  336. nextX,
  337. y0 + 10,
  338. 100,
  339. 4,
  340. colors.black,
  341. 4
  342. );
  343. topFractionLine.anchor(0.5, 0);
  344. renderList.push(topFractionLine);
  345. font.fill = self.control.isCorrect ? colors.green : colors.red;
  346. nextX += offsetX;
  347. renderList.push(
  348. game.add.text(nextX, y0 + 35, self.control.isCorrect ? '=' : '≠', font)
  349. );
  350. font.fill = colors.black;
  351. nextX += offsetX;
  352. renderList.push(
  353. game.add.text(
  354. nextX,
  355. y0,
  356. nominators[1] + '\n' + denominators[1],
  357. font,
  358. 70
  359. )
  360. );
  361. const bottomFractionLine = game.add.geom.rect(
  362. nextX,
  363. y0 + 10,
  364. 100,
  365. 4,
  366. colors.black,
  367. 4
  368. );
  369. bottomFractionLine.anchor(0.5, 0);
  370. renderList.push(bottomFractionLine);
  371. //let resultWidth = ''.length * widthOfChar;
  372. const cardWidth = nextX - x0 + padding * 2;
  373. card.width = cardWidth;
  374. const endSignX =
  375. (context.canvas.width - cardWidth) / 2 + cardWidth + 400 + 50;
  376. // Center Card
  377. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  378. self.fractionOperationUI = renderList;
  379. return endSignX;
  380. },
  381. renderEndUI: () => {
  382. let btnColor = colors.green;
  383. let btnText = game.lang.continue;
  384. if (!self.control.isCorrect) {
  385. btnColor = colors.red;
  386. btnText = game.lang.retry;
  387. }
  388. // continue button
  389. self.ui.continue.button = game.add.geom.rect(
  390. context.canvas.width / 2 + 400,
  391. context.canvas.height / 2 + 280,
  392. 450,
  393. 100,
  394. btnColor
  395. );
  396. self.ui.continue.button.anchor(0.5, 0.5);
  397. self.ui.continue.text = game.add.text(
  398. context.canvas.width / 2 + 400,
  399. context.canvas.height / 2 + 16 + 280,
  400. btnText,
  401. textStyles.btn
  402. );
  403. },
  404. startDelayHandler: () => {
  405. self.control.animationDelay++;
  406. if (self.control.animationDelay === 50) {
  407. self.ui.message[0].alpha = 0;
  408. self.utils.checkAnswer();
  409. self.control.animationDelay = 0;
  410. self.control.startEndAnimation = true;
  411. }
  412. },
  413. // UPDATE
  414. moveBlocks: function () {
  415. ['top', 'bottom'].forEach((cur) => {
  416. if (self.blocks[cur].animate) {
  417. // Lower selected blocks
  418. for (let i = 0; i < self.blocks[cur].selectedAmount; i++) {
  419. self.blocks[cur].list[i].y += 2;
  420. }
  421. // After fully lowering blocks, set fraction value
  422. if (self.blocks[cur].list[0].y >= self.blocks[cur].auxBlocks[0].y) {
  423. self.blocks[cur].fractions[0].name =
  424. self.blocks[cur].selectedAmount +
  425. '\n' +
  426. self.blocks[cur].list.length;
  427. self.blocks[cur].animate = false;
  428. }
  429. }
  430. });
  431. },
  432. checkAnswer: function () {
  433. for (let block of self.blocks.top.auxBlocks) {
  434. block.alpha = 0;
  435. }
  436. for (let block of self.blocks.bottom.auxBlocks) {
  437. block.alpha = 0;
  438. }
  439. // After delay is over, check result
  440. //if (self.control.animationDelay > 50) {
  441. self.control.isCorrect =
  442. self.blocks.top.selectedAmount / self.blocks.top.list.length ==
  443. self.blocks.bottom.selectedAmount / self.blocks.bottom.list.length;
  444. const x = self.utils.renderOperationUI();
  445. if (self.control.isCorrect) {
  446. if (audioStatus) game.audio.okSound.play();
  447. game.add
  448. .image(x + 50, context.canvas.height / 2, 'answer_correct')
  449. .anchor(0.5, 0.5);
  450. completedLevels++;
  451. if (isDebugMode) console.log('Completed Levels: ' + completedLevels);
  452. } else {
  453. if (audioStatus) game.audio.errorSound.play();
  454. game.add
  455. .image(x, context.canvas.height / 2, 'answer_wrong')
  456. .anchor(0.5, 0.5);
  457. }
  458. self.fetch.postScore();
  459. },
  460. runEndAnimation: function () {
  461. self.control.animationDelay++;
  462. if (self.control.animationDelay === 100) {
  463. self.utils.renderEndUI();
  464. self.control.showEndInfo = true;
  465. if (self.control.isCorrect) canGoToNextMapPosition = true;
  466. else canGoToNextMapPosition = false;
  467. }
  468. },
  469. endLevel: function () {
  470. game.state.start('map');
  471. },
  472. // HANDLERS
  473. /**
  474. * Function called by self.onInputDown() when player clicked a valid rectangle.
  475. *
  476. * @param {object} curBlock clicked rectangle : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  477. */
  478. clickSquareHandler: function (curBlock) {
  479. const curSet = curBlock.position;
  480. if (
  481. !self.blocks[curSet].hasClicked &&
  482. curBlock.index != self.blocks[curSet].list.length - 1
  483. ) {
  484. document.body.style.cursor = 'auto';
  485. // Turn auxiliar blocks invisible
  486. for (let i in self.blocks[curSet].list) {
  487. if (i > curBlock.index) self.blocks[curSet].auxBlocks[i].alpha = 0;
  488. }
  489. // Turn value label invisible
  490. self.blocks[curSet].label.alpha = 0;
  491. if (audioStatus) game.audio.popSound.play();
  492. // Save number of selected blocks
  493. self.blocks[curSet].selectedAmount = curBlock.index + 1;
  494. // Set fraction x position
  495. const newX =
  496. curBlock.finalX +
  497. self.blocks[curSet].selectedAmount *
  498. (self.control.blockWidth / self.blocks[curSet].list.length) +
  499. 40;
  500. self.blocks[curSet].fractions[0].x = newX;
  501. self.blocks[curSet].fractions[1].x = newX;
  502. self.blocks[curSet].fractions[0].name = `${curBlock.index + 1}\n${
  503. self.blocks[curSet].list.length
  504. }`;
  505. self.blocks[curSet].fractions[1].alpha = 1;
  506. self.blocks[curSet].hasClicked = true; // Inform player have clicked in current block set
  507. self.blocks[curSet].animate = true; // Let it initiate animation
  508. }
  509. game.render.all();
  510. },
  511. /**
  512. * Function called by self.onInputOver() when cursor is over a valid rectangle.
  513. *
  514. * @param {object} curBlock rectangle the cursor is over : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  515. */
  516. overSquareHandler: function (curBlock) {
  517. const curSet = curBlock.position;
  518. if (!self.blocks[curSet].hasClicked) {
  519. // self.blocks.top.hasClicked || self.blocks.bottom.hasClicked
  520. // If over fraction 'n/n' shows warning message not allowing it
  521. if (curBlock.index == self.blocks[curSet].list.length - 1) {
  522. const otherSet = curSet == 'top' ? 'bottom' : 'top';
  523. self.blocks[curSet].warningText.alpha = 1;
  524. self.blocks[otherSet].warningText.alpha = 0;
  525. self.utils.outSquareHandler(curSet);
  526. } else {
  527. document.body.style.cursor = 'pointer';
  528. self.blocks.top.warningText.alpha = 0;
  529. self.blocks.bottom.warningText.alpha = 0;
  530. // Selected blocks become fully visible
  531. for (let i in self.blocks[curSet].list) {
  532. self.blocks[curSet].list[i].alpha = i <= curBlock.index ? 1 : 0.5;
  533. }
  534. self.blocks[curSet].fractions[0].name = curBlock.index + 1; // Nominator : selected blocks
  535. const newX =
  536. curBlock.finalX +
  537. (curBlock.index + 1) *
  538. (self.control.blockWidth / self.blocks[curSet].list.length) +
  539. 25;
  540. self.blocks[curSet].fractions[0].x = newX;
  541. self.blocks[curSet].fractions[1].x = newX;
  542. self.blocks[curSet].fractions[0].alpha = 1;
  543. }
  544. }
  545. },
  546. /**
  547. * Function called (by self.onInputOver() and self.utils.overSquareHandler()) when cursor is out of a valid rectangle.
  548. *
  549. * @param {object} curSet set of rectangles : can be top (self.blocks.top) or bottom (self.blocks.bottom)
  550. */
  551. outSquareHandler: function (curSet) {
  552. if (!self.blocks[curSet].hasClicked) {
  553. self.blocks[curSet].fractions[0].alpha = 0;
  554. self.blocks[curSet].fractions[1].alpha = 0;
  555. self.blocks[curSet].list.forEach((cur) => {
  556. cur.alpha = 0.5;
  557. });
  558. }
  559. },
  560. },
  561. events: {
  562. /**
  563. * Called by mouse click event
  564. *
  565. * @param {object} mouseEvent contains the mouse click coordinates
  566. */
  567. onInputDown: function (mouseEvent) {
  568. const x = game.math.getMouse(mouseEvent).x;
  569. const y = game.math.getMouse(mouseEvent).y;
  570. // Click block in (a)
  571. self.blocks.top.list.forEach((cur) => {
  572. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  573. });
  574. // Click block in (b)
  575. self.blocks.bottom.list.forEach((cur) => {
  576. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  577. });
  578. // Continue button
  579. if (self.control.showEndInfo) {
  580. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  581. if (audioStatus) game.audio.popSound.play();
  582. self.utils.endLevel();
  583. }
  584. }
  585. // Click navigation icons
  586. navigation.onInputDown(x, y);
  587. game.render.all();
  588. },
  589. /**
  590. * Called by mouse move event
  591. *
  592. * @param {object} mouseEvent contains the mouse move coordinates
  593. */
  594. onInputOver: function (mouseEvent) {
  595. const x = game.math.getMouse(mouseEvent).x;
  596. const y = game.math.getMouse(mouseEvent).y;
  597. let flagA = false;
  598. let flagB = false;
  599. // Mouse over (a) : show fraction
  600. self.blocks.top.list.forEach((cur) => {
  601. if (game.math.isOverIcon(x, y, cur)) {
  602. flagA = true;
  603. self.utils.overSquareHandler(cur);
  604. }
  605. });
  606. if (!flagA) self.utils.outSquareHandler('top');
  607. // Mouse over (b) : show fraction
  608. self.blocks.bottom.list.forEach((cur) => {
  609. if (game.math.isOverIcon(x, y, cur)) {
  610. flagB = true;
  611. self.utils.overSquareHandler(cur);
  612. }
  613. });
  614. if (!flagB) self.utils.outSquareHandler('bottom');
  615. if (!flagA && !flagB) document.body.style.cursor = 'auto';
  616. // Continue button
  617. if (self.control.showEndInfo) {
  618. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  619. // If pointer is over icon
  620. document.body.style.cursor = 'pointer';
  621. self.ui.continue.button.scale =
  622. self.ui.continue.button.initialScale * 1.1;
  623. self.ui.continue.text.style = textStyles.btnLg;
  624. } else {
  625. // If pointer is not over icon
  626. document.body.style.cursor = 'auto';
  627. self.ui.continue.button.scale =
  628. self.ui.continue.button.initialScale * 1;
  629. self.ui.continue.text.style = textStyles.btn;
  630. }
  631. }
  632. // Mouse over navigation icons : show name
  633. navigation.onInputOver(x, y);
  634. game.render.all();
  635. },
  636. },
  637. fetch: {
  638. /**
  639. * Saves players data after level ends - to be sent to database. <br>
  640. *
  641. * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
  642. *
  643. * @see /php/save.php
  644. */
  645. postScore: function () {
  646. // Creates string that is going to be sent to db
  647. const data =
  648. '&line_game=' +
  649. gameShape +
  650. '&line_mode=' +
  651. gameMode +
  652. '&line_oper=Equal' +
  653. '&line_leve=' +
  654. gameDifficulty +
  655. '&line_posi=' +
  656. curMapPosition +
  657. '&line_resu=' +
  658. self.control.isCorrect +
  659. '&line_time=' +
  660. game.timer.elapsed +
  661. '&line_deta=' +
  662. 'numBlocksA: ' +
  663. self.blocks.top.list.length +
  664. ', valueA: ' +
  665. self.blocks.top.selectedAmount +
  666. ', numBlocksB: ' +
  667. self.blocks.bottom.list.length +
  668. ', valueB: ' +
  669. self.blocks.bottom.selectedAmount;
  670. // FOR MOODLE
  671. sendToDatabase(data);
  672. },
  673. },
  674. };