phaserConfig.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. var towerA = [],
  2. towerB = [],
  3. towerC = [];
  4. var diskQntity = 3,
  5. nMoves, nCurrentMoves = 0,
  6. minimumMoves = Math.pow(2, diskQntity) - 1;
  7. var textsFont = { fontFamily: 'Arial', fontSize: 50, color: '#5cff5c' };
  8. var gameWonMsg, nMoves;
  9. var redoButton, undoButton, restartButton, diskSelectorButton;
  10. var scene, tween;
  11. var wrongMoveSprite;
  12. var outputMsgBox;
  13. var teacherVersion = true;
  14. class sceneGame extends Phaser.Scene {
  15. constructor() {
  16. super({ key: 'sceneGame' });
  17. }
  18. preload() {
  19. scene = this;
  20. this.load.image('sky', 'assets/sky.png');
  21. this.load.image('acoesBox', 'assets/acoes.png');
  22. //this.load.image('base', 'assets/baseText.png');
  23. this.load.image('torre', 'assets/torre.png');
  24. this.load.image('selectionArea', 'assets/selectionArea.png');
  25. //buttons
  26. this.load.image('redo', 'assets/redo2.png');
  27. this.load.image('redoDisabled', 'assets/redoDisabled2.png');
  28. this.load.image('msgBox', 'assets/msgBox.png')
  29. this.load.image('undo', 'assets/undo2.png');
  30. this.load.image('undoDisabled', 'assets/undoDisabled2.png');
  31. this.load.image('restart', 'assets/restart.png');
  32. this.load.image('wrongMove', 'assets/wrongMove.png');
  33. //Only loads disk selection if its the teacher using
  34. try {
  35. if (iLMparameters.iLM_PARAM_SendAnswer != 'true')
  36. teacherVersion = false;
  37. console.log("iAssign version");
  38. } catch (e) {
  39. //this.load.image('diskSelector', 'assets/diskSelector.png');
  40. console.log("web-version");
  41. }
  42. if (teacherVersion == true) this.load.image('diskSelector', 'assets/diskSelector.png');
  43. //load all imgs needed for the exercise
  44. for (var i = 0; i < 6; i++) {
  45. this.load.image('disk' + i, 'assets/disk' + i + '.png')
  46. this.load.image('stroked' + i, 'assets/strokedDisks/stroked' + i + '.png')
  47. }
  48. }
  49. create() {
  50. //misc
  51. this.add.image(0, 0, 'sky').setOrigin(0).setDisplaySize(1320, 600);
  52. this.add.sprite(120, 90, 'acoesBox').setDisplaySize(80, 70);
  53. nMoves = this.add.text(90, 70, 0, textsFont);
  54. this.add.text(135, 530, 'Torre A', {fontFamily: 'Arial', fontSize: 50, color: '#4c0fbd'} );
  55. this.add.text(570, 530, 'Torre B', {fontFamily: 'Arial', fontSize: 50, color: '#4c0fbd'} );
  56. this.add.text(1005, 530, 'Torre C', {fontFamily: 'Arial', fontSize: 50, color: '#4c0fbd'} );
  57. //buttons
  58. redoButton = this.add.sprite(720, 90, 'redoDisabled').setDisplaySize(80, 70); //.setInteractive({useHandCursor: false});
  59. redoButton.on('pointerdown', function(pointer) {
  60. redoMove();
  61. });
  62. undoButton = this.add.sprite(600, 90, 'undoDisabled').setDisplaySize(80, 70); //.setInteractive({useHandCursor: false});
  63. undoButton.on('pointerdown', function(pointer) {
  64. undoMove();
  65. });
  66. restartButton = this.add.sprite(990, 90, 'restart').setDisplaySize(80, 60).setInteractive({ useHandCursor: true });
  67. restartButton.on('pointerdown', function(pointer) {
  68. restart();
  69. });
  70. if (teacherVersion == true){
  71. diskSelectorButton = this.add.sprite(1200, 90, 'diskSelector').setDisplaySize(80, 70).setInteractive({ useHandCursor: true });
  72. diskSelectorButton.on('pointerdown', function(pointer) {
  73. this.scene.start('sceneDiskSelection');
  74. }, this);
  75. }
  76. //loads only if its the teacher seeing or if its not on iAssign
  77. //Towers
  78. this.add.image(219, 320, 'torre').setScale(0.13);
  79. this.add.image(654, 320, 'torre').setScale(0.13);
  80. this.add.image(1089, 320, 'torre').setScale(0.13);
  81. //Disks
  82. var diskX = 220,
  83. diskY = 430;
  84. for (var i = diskQntity - 1; i >= 0; i--) {
  85. towerA[diskQntity - 1 - i] = this.add.sprite(diskX, diskY, 'disk' + i).setScale(0.13); //.setDisplaySize(diskWidth, diskHeight);
  86. diskY -= 28;
  87. }
  88. //towerA Selection Area
  89. var towerASelectionArea = this.add.sprite(220, 375, 'selectionArea').setDisplaySize(400, 320).setInteractive({ useHandCursor: true });
  90. towerASelectionArea.on('pointerdown', function(pointer) {
  91. selectA();
  92. });
  93. towerASelectionArea.alpha = 0.1;
  94. //towerB selectionArea
  95. var towerBSelectionArea = this.add.sprite(655, 375, 'selectionArea').setDisplaySize(400, 320).setInteractive({ useHandCursor: true });
  96. towerBSelectionArea.on('pointerdown', function(pointer) {
  97. selectB();
  98. });
  99. towerBSelectionArea.alpha = 0.1;
  100. var towerCSelectionArea = this.add.sprite(1090, 375, 'selectionArea').setDisplaySize(400, 320).setInteractive({ useHandCursor: true });
  101. towerCSelectionArea.on('pointerdown', function(pointer) {
  102. selectC();
  103. });
  104. towerCSelectionArea.alpha = 0.1;
  105. wrongMoveSprite = this.add.sprite(220, 300, 'wrongMove').setDisplaySize(100, 100).setAlpha(0);
  106. outputMsgBox = this.add.sprite(655, 310, 'msgBox').setDisplaySize(550,180);
  107. outputMsgBox.alpha = 0;
  108. gameWonMsg = this.add.text(450, 255, ' ', { fontFamily: 'Arial', fontSize: 22, color: '#00a600', align: 'center' });
  109. }
  110. update() {}
  111. event() {
  112. console.log('over');
  113. }
  114. }
  115. class sceneDiskSelection extends Phaser.Scene {
  116. constructor() {
  117. super({ key: 'sceneDiskSelection' });
  118. }
  119. preload() {
  120. this.load.image('sixDisks', 'assets/diskSelection/sixDisks.png');
  121. this.load.image('fiveDisks', 'assets/diskSelection/fiveDisks.png');
  122. this.load.image('fourDisks', 'assets/diskSelection/fourDisks.png');
  123. this.load.image('threeDisks', 'assets/diskSelection/threeDisks.png');
  124. this.load.image('twoDisks', 'assets/diskSelection/twoDisks.png');
  125. }
  126. create() {
  127. this.add.image(0, 0, 'sky').setOrigin(0).setDisplaySize(1320, 600);
  128. var sixDisksButton = this.add.sprite(850, 450, 'sixDisks').setDisplaySize(200, 200).setInteractive({ useHandCursor: true });
  129. sixDisksButton.on('pointerdown', function(pointer) {
  130. selectDisks(6, this);
  131. }, this);
  132. var fiveDisksButton = this.add.sprite(450, 450, 'fiveDisks').setDisplaySize(200, 200).setInteractive({ useHandCursor: true });
  133. fiveDisksButton.on('pointerdown', function(pointer) {
  134. selectDisks(5, this);
  135. }, this);
  136. var fourDisksButton = this.add.sprite(1050, 200, 'fourDisks').setDisplaySize(200, 200).setInteractive({ useHandCursor: true });
  137. fourDisksButton.on('pointerdown', function(pointer) {
  138. selectDisks(4, this);
  139. }, this);
  140. var threeDisksButton = this.add.sprite(650, 200, 'threeDisks').setDisplaySize(200, 200).setInteractive({ useHandCursor: true });
  141. threeDisksButton.on('pointerdown', function(pointer) {
  142. selectDisks(3, this);
  143. }, this);
  144. var twoDisksButton = this.add.sprite(250, 200, 'twoDisks').setDisplaySize(200, 200).setInteractive({ useHandCursor: true });
  145. twoDisksButton.on('pointerdown', function(pointer) {
  146. selectDisks(2, this);
  147. }, this);
  148. }
  149. }
  150. var config = {
  151. type: Phaser.AUTO,
  152. scale: {
  153. mode: Phaser.Scale.FIT,
  154. width: 1320,
  155. height: 600
  156. },
  157. scene: [sceneGame, sceneDiskSelection]
  158. // canvas: doocument.querySelector('mainDiv');
  159. };
  160. var game = new Phaser.Game(config);