|
@@ -1,28 +1,15 @@
|
|
|
-var canvas = document.getElementById('planoDeFundo');
|
|
|
-var context = canvas.getContext('2d');
|
|
|
-var towerA = [], towerB = [], towerC = [];
|
|
|
-var toMove = null;
|
|
|
-var idF=" ", idT= " ";
|
|
|
-var nMovements = 0, nTotalMovements = 0, nWrongMoves = 0, nDisks;
|
|
|
-var moves = [], totalMoves = []; //vector to save movements
|
|
|
-var acertou=0;
|
|
|
-var optimalSolution;
|
|
|
- //NavyBlue Lime Fuchsia yellow Orange LightSteelBlue red
|
|
|
-var colors = ["#000080","#00FF00", "#FF00FF", "yellow", "#FFA500", "#B0C4DE","red"];
|
|
|
-var start = Date.now(), startOfMove, totalTime, moveTime; //timing vars
|
|
|
-
|
|
|
function inicio (QntityDisks){
|
|
|
nDisks=QntityDisks;
|
|
|
optimalSolution= Math.pow(2,QntityDisks)-1;
|
|
|
var x = 0;
|
|
|
- var y = 558;
|
|
|
+ var y = 549.5;
|
|
|
var w = 330;
|
|
|
startOfMove=Date.now();
|
|
|
for (var i = 0; i < QntityDisks; i++) {
|
|
|
var disk = new Disk(x,y,w,40,colors[i]);
|
|
|
towerA.push(disk);
|
|
|
x+=20; //moves to the right
|
|
|
- y-=42; //moves up, +1 to separate disks
|
|
|
+ y-=41; //moves up, +1 to separate disks
|
|
|
w-=40; //reduces disk width
|
|
|
}
|
|
|
drawScene();
|
|
@@ -59,24 +46,24 @@ function reinicio (){
|
|
|
}
|
|
|
function drawTowers (){
|
|
|
context.beginPath();
|
|
|
+ context.fillStyle = pat;
|
|
|
<!-- torre 1 -->
|
|
|
- context.fillStyle = 'black';
|
|
|
- context.fillRect(160, 260, 10, 340);//x, y, largura, altura
|
|
|
-
|
|
|
+ roundRect(context, 160, 260, 20, 340, 5, pat, false);//ctx, x, y, largura, altura, radius, fill, stroke(T/F)
|
|
|
+
|
|
|
<!--Base t1-->
|
|
|
- context.fillRect(0, 600, 330, 15);
|
|
|
+ roundRect(context, 0, 590, 330, 20, 5, pat, false);
|
|
|
|
|
|
<!-- torre 2 -->
|
|
|
- context.fillRect(505, 260 ,10, 340);
|
|
|
+ roundRect(context, 505, 260, 20, 340, 5, pat, false);
|
|
|
|
|
|
<!--Base t2-->
|
|
|
- context.fillRect(345, 600, 330, 15);
|
|
|
+ roundRect(context, 345, 590, 330, 20, 5, pat, false);
|
|
|
|
|
|
<!-- torre 3 -->
|
|
|
- context.fillRect(850, 260, 10, 340);
|
|
|
+ roundRect(context, 850, 260, 20, 340, 5, pat, false);
|
|
|
|
|
|
<!--Base t3-->
|
|
|
- context.fillRect(690, 600, 330, 15);
|
|
|
+ roundRect(context, 690, 590, 330, 20, 5, pat, false);
|
|
|
}
|
|
|
|
|
|
function drawDisks (){
|
|
@@ -140,7 +127,7 @@ function moveDisk (origin, destiny){
|
|
|
}
|
|
|
moves.push(origin+" "+destiny);
|
|
|
|
|
|
- console.log(moves);
|
|
|
+ //console.log(moves);
|
|
|
nMovements++;
|
|
|
finishMove(origin, destiny);
|
|
|
if(towerC.length == nDisks && nDisks!=0){
|
|
@@ -200,7 +187,6 @@ function redo(){
|
|
|
if (nMovements < moves.length){
|
|
|
var res = moves[nMovements].split(" ");
|
|
|
nMovements++;
|
|
|
- console.log(res[0]+ res[1]);
|
|
|
finishMove(parseInt(res[0]), parseInt(res[1]));
|
|
|
}
|
|
|
}
|