Browse Source

-tracking amount of time taken to make a move
-tracking total play time

Bernardo 5 years ago
parent
commit
689ad95a35
2 changed files with 13 additions and 14 deletions
  1. 11 6
      js/iHanoiFunctions.js
  2. 2 8
      js/integration-functions.js

+ 11 - 6
js/iHanoiFunctions.js

@@ -3,13 +3,13 @@ var canvas = document.getElementById('planoDeFundo');
 			var towerA = [], towerB = [], towerC = [];
 			var toMove = null;
 			var idF=" ", idT= " ";
-			var nMovements = 0, nDisks;
-			var moves="";
+			var nMovements = 0, nWrongMoves=0, nDisks;
+			var moves=""; //string to save movements
 			var acertos;
 			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;
@@ -18,6 +18,7 @@ var canvas = document.getElementById('planoDeFundo');
 				var y = 558;
 				var w = 330;
 				moves="";
+				startOfMove=Date.now();
 				for (var i = 0; i < nDisks; i++) {
 					var disk = new Disk(x,y,w,40,colors[i]);
 					towerA.push(disk);
@@ -138,9 +139,12 @@ var canvas = document.getElementById('planoDeFundo');
 
 			function moveDisk (origin, destiny){
 				var originTower = getTower(origin), destinyTower = getTower(destiny), topDiskOrigin, topDiskDestiny;
-				moves+="\n"+origin+" "+destiny;
+				moveTime = Math.floor( (Date.now()- startOfMove) /1000);
+				moves+="\n"+origin+" "+destiny+"  "+moveTime;
+				startOfMove = Date.now();//update start of movement
 				console.clear();
 				console.log(moves);
+				nMovements++;
 				
 				topDiskOrigin = originTower[originTower.length-1];
 				if(destinyTower.length>0){
@@ -150,9 +154,9 @@ var canvas = document.getElementById('planoDeFundo');
 						topDiskOrigin.y += 42*(originTower.length-destinyTower.length-1);
 						originTower.pop();
 						destinyTower.push(topDiskOrigin);
-						nMovements++;
 						drawScene();
 					} else{
+						nWrongMoves++;
 						alert("Movimento Inválido");
 						idF =" ";
 						idT =" ";
@@ -169,6 +173,7 @@ var canvas = document.getElementById('planoDeFundo');
 				acertos=0;
 				if(towerC.length == nDisks && nDisks!=0){
 					acertos=1;
+					totalTime= Date.now() - start;
 					if(nMovements==optimalSolution){
 						alert("You Won in the least amount of movements!!!\nCongratulations!!!");
 					}else{
@@ -202,4 +207,4 @@ var canvas = document.getElementById('planoDeFundo');
 			    ctx.fill();
 			  }        
 			}
-			inicio();
+			inicio(4);

+ 2 - 8
js/integration-functions.js

@@ -24,13 +24,7 @@ function getAnswer() {
     // então trata-se de resolução de atividade
     if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
         // Montar o retorno da resposta do aluno
-        var respostas = Array();
-        for (j = 0; j < desafios.length; j++) {
-            respostas.push(parseInt($("#resposta_" + j).val()));
-        }
-
-        return '[{"respostas": ' + JSON.stringify(respostas) + '}, {"operacao": "' + operacao + '"}, {"parcelas": ' + JSON.stringify(parcelas) + '}, {"desenhos": ' + JSON.stringify(desenhos) + ' }, '
-                    + '{"desafios": ' + JSON.stringify(desafios) + '}]';
+        return moves;
     } else {//se for o professor acessando, mostra a pagina de elaboração
         return JSON.stringify($('form[name="elaborar"]').serializeArray());
     }
@@ -75,9 +69,9 @@ function getiLMContent() {
 // de atividade ou de resolução. E no caso de ser resolução, os dados da atividade
 // precisam ser consultados, pelo método implementado acima, o getiLMContent()
 $(document).ready(function() {
-iLMparameters.iLM_PARAM_SendAnswer='false';
     // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
     // portanto, a "DIV" de resolução é liberada
+    iLMparameters.iLM_PARAM_SendAnswer='false';
     if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
         $('.exercicio').css("display","block");
         getiLMContent();