var cadena=""; var itv=""; var tf; var num; var punt=0; var result, succes; var numOp=0, numCheck=0; var cl; function init_juego(){ itv=setInterval(showOperation, 1500); } function timer(){ cl = $("#respuesta"); if(num>0){ cl.html("time: "+num+" ds"); num--; setTimeout('timer()',1); }else{ cl.html("time: 0 ds"); } } function showOperation(){ numOp++; checkAnswer(); num=150; $("#respuesta").html("1.5"); timer(); if((tf==0)||(succes==false)){ num=0; mostrar_op("GAME OVER"); document.getElementById("boton1").onclick = undefined; document.getElementById("boton2").onclick = undefined; }else{ checkFinal(); tf=0; var a=Math.random()*10; a=Math.round(a)+1; var b=Math.random()*10; b=Math.round(b)+1; var op=chooseOperator(); var res; if(op===" + "){ res=a+b; }else{ res=a-b; } var res2; op1=aleatorial(); if(op1===1){ res2=res+1; }else{ res2=res-2; } var showres; op2=aleatorial(); if(op2===1){ showres=res; result=true; }else{ showres=res2; result=false; } cadena=a + op + b + " = " + showres; mostrar_op(cadena); } } function checkAnswer(){ numCheck++; if(tf==1){ if((result)&&(numOp==numCheck)) { punt++; succes=true; }else{ succes=false; } } if(tf==2){ if((!result) && (numOp==numCheck)) { punt++; succes=true; }else{ succes=false; } } $("#puntuacion").html(punt+" points"); } function checkFinal(){ if((tf==0)||(succes==false)){ clearInterval(itv); itv=undefined; } } function aleatorial(){ var op=Math.random()*2; op=Math.round(op)+1; return op; } function mostrar_op(cadena) { $("#fecha").html(cadena); } function chooseOperator(){ var op=aleatorial(); if(op===1){ return " + "; }else{ return " - "; } } function instrucciones(){ var inst = $("#respuesta"); inst.html("
Di si la operaciĆ³n es cierta o falsa. Si fallas, pierdes; si se acaba el tiempo, pierdes.
"); }