phaserConfig.js 7.2 KB

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