squareTwo.js 21 KB

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