studentReport.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /************************************************************************************
  2. * This code is used EXCLUSIVELY when iFractions is runnign inside Moodle via iAssign
  3. * as an iLM (interactive learning module) and the global variable moodle=true.
  4. *
  5. * This file holds game states.
  6. ************************************************************************************/
  7. /**
  8. * [STUDENT REPORT STATE] Screen that shows the stats of a previously played game (exclusive to moodle).
  9. *
  10. * FOR MOODLE
  11. *
  12. * @namespace
  13. */
  14. const studentReport = {
  15. /** FOR MOODLE
  16. * Main code
  17. */
  18. create: function () {
  19. const offsetX = context.canvas.width / 4;
  20. const offsetY = 37.5;
  21. const x0 = offsetX / 2;
  22. const y0 = context.canvas.height / 2 - 100;
  23. const titleFont = { ...textStyles.h1_, fill: colors.green };
  24. const infoFont = {
  25. ...textStyles.h4_,
  26. align: 'left',
  27. fill: colors.maroon,
  28. };
  29. renderBackground();
  30. // Title
  31. game.add.text(context.canvas.width / 2, 120, game.lang.results, titleFont);
  32. game.add.image(
  33. x0 - 80,
  34. y0 - 110,
  35. gameList[gameId].assets.menu.gameNameBtn,
  36. 1.4
  37. );
  38. this.utils.renderCurGameMetadata(y0, offsetY, infoFont);
  39. this.utils.renderCurGameStats(x0, offsetX, offsetY, infoFont);
  40. },
  41. utils: {
  42. renderCurGameMetadata: function (defaultY, offsetY, font) {
  43. // Game info
  44. let text =
  45. game.lang[gameShape].charAt(0).toUpperCase() +
  46. game.lang[gameShape].slice(1);
  47. text =
  48. game.lang.game +
  49. ': ' +
  50. text +
  51. (gameName.slice(-3) == 'One' ? ' I' : ' II');
  52. const x0 = 360;
  53. game.add.text(x0, defaultY - offsetY * 2, text, font);
  54. game.add.text(
  55. x0,
  56. defaultY - offsetY,
  57. game.lang.game_mode + ': ' + gameMode.toUpperCase(),
  58. font
  59. );
  60. const operationText =
  61. gameOperation.charAt(0).toUpperCase() + gameOperation.slice(1);
  62. game.add.text(
  63. x0,
  64. defaultY,
  65. game.lang.operation + ': ' + operationText,
  66. font
  67. );
  68. game.add.text(
  69. x0,
  70. defaultY + offsetY,
  71. game.lang.difficulty + ': ' + gameDifficulty,
  72. font
  73. );
  74. },
  75. renderCurGameStats: function (defaultX, offsetX, offsetY, font) {
  76. // Student info
  77. const y0 = context.canvas.height - 300;
  78. let x = defaultX;
  79. for (let i = 0; i < 4; i++, x += offsetX) {
  80. // If level wasnt completed, show broken sign
  81. if (moodleVar.hits[i] === 0 && moodleVar.errors[i] === 0) {
  82. const sign = game.add.image(
  83. x,
  84. context.canvas.height - 150,
  85. 'sign_broken',
  86. 1.2
  87. );
  88. sign.anchor(0.5, 0.5);
  89. continue;
  90. }
  91. // If level was completed shows sign with level number and student report
  92. const sign = game.add.image(
  93. x,
  94. context.canvas.height - 150,
  95. 'sign',
  96. 1.2
  97. );
  98. sign.anchor(0.5, 0.5);
  99. const numberFont = {
  100. ...textStyles.h2_,
  101. font: 'bold ' + textStyles.h2_.font,
  102. fill: colors.white,
  103. };
  104. game.add.text(x, context.canvas.height - 150, '' + (i + 1), numberFont);
  105. game.add.geom.rect(
  106. x - 40 - 50,
  107. y0 - offsetY * 1.75,
  108. 10,
  109. 135 * 1.5,
  110. colors.blue,
  111. 0.1
  112. );
  113. game.add.text(
  114. x - 60,
  115. y0 - offsetY,
  116. game.lang.time + ': ' + game.math.convertTime(moodleVar.time[i]),
  117. font
  118. );
  119. game.add.text(
  120. x - 60,
  121. y0,
  122. game.lang.hits + ': ' + moodleVar.hits[i],
  123. font
  124. );
  125. game.add.text(
  126. x - 60,
  127. y0 + offsetY,
  128. game.lang.errors + ': ' + moodleVar.errors[i],
  129. font
  130. );
  131. }
  132. },
  133. },
  134. };