squareTwo.js 21 KB

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