start.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var canvas = document.getElementById('planoDeFundo');
  2. var context = canvas.getContext('2d');
  3. var towerA = [], towerB = [], towerC = [];
  4. var toMove = null;
  5. var idF=" ", idT= " ";
  6. var nMovements = 0, nTotalMovements = 0, nWrongMoves = 0, nDisks = 2;
  7. var moves = [], totalMoves = []; //vector to save movements
  8. var acertou=0;
  9. var start;
  10. var optimalSolution;
  11. //NavyBlue Lime Fuchsia yellow Orange LightSteelBlue red
  12. var colors = ["#000080","#00FF00", "#FF00FF", "yellow", "#FFA500", "#B0C4DE","red"];
  13. var pat = [], sources = ['imgs/baseText.png', 'imgs/disk1.png', 'imgs/disk2.png', 'imgs/disk3.png',
  14. 'imgs/disk4.png', 'imgs/disk5.png', 'imgs/disk6.png'];
  15. loadIMGS(nDisks);
  16. function loadImage(url) {
  17. return new Promise((resolve, reject) => {
  18. let img = new Image();
  19. img.addEventListener('load', e => resolve(img));
  20. img.addEventListener('error', () => {
  21. reject(new Error(`Failed to load image's URL: ${url}`));
  22. });
  23. img.src = url;
  24. });
  25. }
  26. function loadIMGS(n){
  27. var allImgs = sources.map(function(path){
  28. return loadImage(path)
  29. });
  30. Promise.all(allImgs).then(function(imgs){
  31. for (var i = imgs.length - 1; i >= 0; i--) {
  32. pat[i] = context.createPattern(imgs[i], "repeat");
  33. }
  34. }).then(function(){
  35. inicio(n);
  36. });
  37. }