squareTwo.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. game.timer.stop();
  406. self.control.animationDelay++;
  407. if (self.control.animationDelay === 50) {
  408. self.ui.message[0].alpha = 0;
  409. self.utils.checkAnswer();
  410. self.control.animationDelay = 0;
  411. self.control.startEndAnimation = true;
  412. }
  413. },
  414. // UPDATE
  415. moveBlocks: function () {
  416. ['top', 'bottom'].forEach((cur) => {
  417. if (self.blocks[cur].animate) {
  418. // Lower selected blocks
  419. for (let i = 0; i < self.blocks[cur].selectedAmount; i++) {
  420. self.blocks[cur].list[i].y += 2;
  421. }
  422. // After fully lowering blocks, set fraction value
  423. if (self.blocks[cur].list[0].y >= self.blocks[cur].auxBlocks[0].y) {
  424. self.blocks[cur].fractions[0].name =
  425. self.blocks[cur].selectedAmount +
  426. '\n' +
  427. self.blocks[cur].list.length;
  428. self.blocks[cur].animate = false;
  429. }
  430. }
  431. });
  432. },
  433. checkAnswer: function () {
  434. for (let block of self.blocks.top.auxBlocks) {
  435. block.alpha = 0;
  436. }
  437. for (let block of self.blocks.bottom.auxBlocks) {
  438. block.alpha = 0;
  439. }
  440. // After delay is over, check result
  441. //if (self.control.animationDelay > 50) {
  442. self.control.isCorrect =
  443. self.blocks.top.selectedAmount / self.blocks.top.list.length ==
  444. self.blocks.bottom.selectedAmount / self.blocks.bottom.list.length;
  445. const x = self.utils.renderOperationUI();
  446. if (self.control.isCorrect) {
  447. if (audioStatus) game.audio.okSound.play();
  448. game.add
  449. .image(x + 50, context.canvas.height / 2, 'answer_correct')
  450. .anchor(0.5, 0.5);
  451. completedLevels++;
  452. if (isDebugMode) console.log('Completed Levels: ' + completedLevels);
  453. } else {
  454. if (audioStatus) game.audio.errorSound.play();
  455. game.add
  456. .image(x, context.canvas.height / 2, 'answer_wrong')
  457. .anchor(0.5, 0.5);
  458. }
  459. self.fetch.postScore();
  460. },
  461. runEndAnimation: function () {
  462. self.control.animationDelay++;
  463. if (self.control.animationDelay === 100) {
  464. self.utils.renderEndUI();
  465. self.control.showEndInfo = true;
  466. if (self.control.isCorrect) canGoToNextMapPosition = true;
  467. else canGoToNextMapPosition = false;
  468. }
  469. },
  470. endLevel: function () {
  471. game.state.start('map');
  472. },
  473. // HANDLERS
  474. /**
  475. * Function called by self.onInputDown() when player clicked a valid rectangle.
  476. *
  477. * @param {object} curBlock clicked rectangle : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  478. */
  479. clickSquareHandler: function (curBlock) {
  480. const curSet = curBlock.position;
  481. if (
  482. !self.blocks[curSet].hasClicked &&
  483. curBlock.index != self.blocks[curSet].list.length - 1
  484. ) {
  485. document.body.style.cursor = 'auto';
  486. // Turn auxiliar blocks invisible
  487. for (let i in self.blocks[curSet].list) {
  488. if (i > curBlock.index) self.blocks[curSet].auxBlocks[i].alpha = 0;
  489. }
  490. // Turn value label invisible
  491. self.blocks[curSet].label.alpha = 0;
  492. if (audioStatus) game.audio.popSound.play();
  493. // Save number of selected blocks
  494. self.blocks[curSet].selectedAmount = curBlock.index + 1;
  495. // Set fraction x position
  496. const newX =
  497. curBlock.finalX +
  498. self.blocks[curSet].selectedAmount *
  499. (self.control.blockWidth / self.blocks[curSet].list.length) +
  500. 40;
  501. self.blocks[curSet].fractions[0].x = newX;
  502. self.blocks[curSet].fractions[1].x = newX;
  503. self.blocks[curSet].fractions[0].name = `${curBlock.index + 1}\n${
  504. self.blocks[curSet].list.length
  505. }`;
  506. self.blocks[curSet].fractions[1].alpha = 1;
  507. self.blocks[curSet].hasClicked = true; // Inform player have clicked in current block set
  508. self.blocks[curSet].animate = true; // Let it initiate animation
  509. }
  510. game.render.all();
  511. },
  512. /**
  513. * Function called by self.onInputOver() when cursor is over a valid rectangle.
  514. *
  515. * @param {object} curBlock rectangle the cursor is over : can be self.blocks.top.list[i] or self.blocks.bottom.list[i]
  516. */
  517. overSquareHandler: function (curBlock) {
  518. const curSet = curBlock.position;
  519. if (!self.blocks[curSet].hasClicked) {
  520. // self.blocks.top.hasClicked || self.blocks.bottom.hasClicked
  521. // If over fraction 'n/n' shows warning message not allowing it
  522. if (curBlock.index == self.blocks[curSet].list.length - 1) {
  523. const otherSet = curSet == 'top' ? 'bottom' : 'top';
  524. self.blocks[curSet].warningText.alpha = 1;
  525. self.blocks[otherSet].warningText.alpha = 0;
  526. self.utils.outSquareHandler(curSet);
  527. } else {
  528. document.body.style.cursor = 'pointer';
  529. self.blocks.top.warningText.alpha = 0;
  530. self.blocks.bottom.warningText.alpha = 0;
  531. // Selected blocks become fully visible
  532. for (let i in self.blocks[curSet].list) {
  533. self.blocks[curSet].list[i].alpha = i <= curBlock.index ? 1 : 0.5;
  534. }
  535. self.blocks[curSet].fractions[0].name = curBlock.index + 1; // Nominator : selected blocks
  536. const newX =
  537. curBlock.finalX +
  538. (curBlock.index + 1) *
  539. (self.control.blockWidth / self.blocks[curSet].list.length) +
  540. 25;
  541. self.blocks[curSet].fractions[0].x = newX;
  542. self.blocks[curSet].fractions[1].x = newX;
  543. self.blocks[curSet].fractions[0].alpha = 1;
  544. }
  545. }
  546. },
  547. /**
  548. * Function called (by self.onInputOver() and self.utils.overSquareHandler()) when cursor is out of a valid rectangle.
  549. *
  550. * @param {object} curSet set of rectangles : can be top (self.blocks.top) or bottom (self.blocks.bottom)
  551. */
  552. outSquareHandler: function (curSet) {
  553. if (!self.blocks[curSet].hasClicked) {
  554. self.blocks[curSet].fractions[0].alpha = 0;
  555. self.blocks[curSet].fractions[1].alpha = 0;
  556. self.blocks[curSet].list.forEach((cur) => {
  557. cur.alpha = 0.5;
  558. });
  559. }
  560. },
  561. },
  562. events: {
  563. /**
  564. * Called by mouse click event
  565. *
  566. * @param {object} mouseEvent contains the mouse click coordinates
  567. */
  568. onInputDown: function (mouseEvent) {
  569. const x = game.math.getMouse(mouseEvent).x;
  570. const y = game.math.getMouse(mouseEvent).y;
  571. // Click block in (a)
  572. self.blocks.top.list.forEach((cur) => {
  573. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  574. });
  575. // Click block in (b)
  576. self.blocks.bottom.list.forEach((cur) => {
  577. if (game.math.isOverIcon(x, y, cur)) self.utils.clickSquareHandler(cur);
  578. });
  579. // Continue button
  580. if (self.control.showEndInfo) {
  581. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  582. if (audioStatus) game.audio.popSound.play();
  583. self.utils.endLevel();
  584. }
  585. }
  586. // Click navigation icons
  587. navigation.onInputDown(x, y);
  588. game.render.all();
  589. },
  590. /**
  591. * Called by mouse move event
  592. *
  593. * @param {object} mouseEvent contains the mouse move coordinates
  594. */
  595. onInputOver: function (mouseEvent) {
  596. const x = game.math.getMouse(mouseEvent).x;
  597. const y = game.math.getMouse(mouseEvent).y;
  598. let flagA = false;
  599. let flagB = false;
  600. // Mouse over (a) : show fraction
  601. self.blocks.top.list.forEach((cur) => {
  602. if (game.math.isOverIcon(x, y, cur)) {
  603. flagA = true;
  604. self.utils.overSquareHandler(cur);
  605. }
  606. });
  607. if (!flagA) self.utils.outSquareHandler('top');
  608. // Mouse over (b) : show fraction
  609. self.blocks.bottom.list.forEach((cur) => {
  610. if (game.math.isOverIcon(x, y, cur)) {
  611. flagB = true;
  612. self.utils.overSquareHandler(cur);
  613. }
  614. });
  615. if (!flagB) self.utils.outSquareHandler('bottom');
  616. if (!flagA && !flagB) document.body.style.cursor = 'auto';
  617. // Continue button
  618. if (self.control.showEndInfo) {
  619. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  620. // If pointer is over icon
  621. document.body.style.cursor = 'pointer';
  622. self.ui.continue.button.scale =
  623. self.ui.continue.button.initialScale * 1.1;
  624. self.ui.continue.text.style = textStyles.btnLg;
  625. } else {
  626. // If pointer is not over icon
  627. document.body.style.cursor = 'auto';
  628. self.ui.continue.button.scale =
  629. self.ui.continue.button.initialScale * 1;
  630. self.ui.continue.text.style = textStyles.btn;
  631. }
  632. }
  633. // Mouse over navigation icons : show name
  634. navigation.onInputOver(x, y);
  635. game.render.all();
  636. },
  637. },
  638. fetch: {
  639. /**
  640. * Saves players data after level ends - to be sent to database. <br>
  641. *
  642. * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
  643. *
  644. * @see /php/save.php
  645. */
  646. postScore: function () {
  647. // Creates string that is going to be sent to db
  648. const data =
  649. '&line_game=' +
  650. gameShape +
  651. '&line_mode=' +
  652. gameMode +
  653. '&line_oper=equal' +
  654. '&line_leve=' +
  655. gameDifficulty +
  656. '&line_posi=' +
  657. curMapPosition +
  658. '&line_resu=' +
  659. self.control.isCorrect +
  660. '&line_time=' +
  661. game.timer.elapsed +
  662. '&line_deta=' +
  663. 'numBlocksA: ' +
  664. self.blocks.top.list.length +
  665. ', valueA: ' +
  666. self.blocks.top.selectedAmount +
  667. ', numBlocksB: ' +
  668. self.blocks.bottom.list.length +
  669. ', valueB: ' +
  670. self.blocks.bottom.selectedAmount;
  671. // FOR MOODLE
  672. sendToDatabase(data);
  673. },
  674. },
  675. };