Team:Tianjin/Community/Education/Game2/js/time.js

// JavaScript Document

// Date: 2014-11-07 // Author: Agnes Xu


i = 0; j = 0; count = 0; MM = 0; SS = 30; // 秒 90s MS = 0; totle = (MM+1)*600; d = 180*(MM+1); MM = "0" + MM; var gameTime = 30; //count down var showTime = function(){

   totle = totle - 1;
   if (totle == 0) {
       clearInterval(s);
       clearInterval(t1);
       clearInterval(t2);
       $(".pie2").css("-o-transform", "rotate(" + d + "deg)");
       $(".pie2").css("-moz-transform", "rotate(" + d + "deg)");
       $(".pie2").css("-webkit-transform", "rotate(" + d + "deg)");
   } else {
       if (totle > 0 && MS > 0) {
           MS = MS - 1;
           if (MS < 10) {
               MS = "0" + MS
           }
           ;
       }
       ;
       if (MS == 0 && SS > 0) {
           MS = 10;
           SS = SS - 1;
           if (SS < 10) {
               SS = "0" + SS
           }
           ;
       }
       ;
       if (SS == 0 && MM > 0) {
           SS = 60;
           MM = MM - 1;
           if (MM < 10) {
               MM = "0" + MM
           }
           ;
       }
       ;
   }
   ;
   $(".time").html(SS + "s");

};

var start1 = function(){ //i = i + 0.6; i = i + 360/((gameTime)*10); //旋转的角度 90s 为 0.4 60s为0.6 count = count + 1; if(count <= (gameTime/2*10)){ // 一半的角度 90s 为 450 $(".pie1").css("-o-transform","rotate(" + i + "deg)"); $(".pie1").css("-moz-transform","rotate(" + i + "deg)"); $(".pie1").css("-webkit-transform","rotate(" + i + "deg)"); }else{ $(".pie2").css("backgroundColor", "#d13c36"); $(".pie2").css("-o-transform","rotate(" + i + "deg)"); $(".pie2").css("-moz-transform","rotate(" + i + "deg)"); $(".pie2").css("-webkit-transform","rotate(" + i + "deg)"); } };

var start2 = function(){

   j = j + 0.6;
   count = count + 1;
   if (count == 300) {
       count = 0;
       clearInterval(t2);
       t1 = setInterval("start1()", 100);
   }

$(".pie2").css("-o-transform","rotate(" + j + "deg)"); $(".pie2").css("-moz-transform","rotate(" + j + "deg)"); $(".pie2").css("-webkit-transform","rotate(" + j + "deg)"); }

var countDown1 = function() {

   //80*80px 时间进度条
   i = 0;
   j = 0;
   count = 0;
   MM = 0;
   SS = gameTime;
   MS = 0;
   totle = (MM + 1) * gameTime * 10;
   d = 180 * (MM + 1);
   MM = "0" + MM;
   showTime();
   s = setInterval("showTime()", 100);
   start1();
   //start2();
   t1 = setInterval("start1()", 100);

}






var td = new Array(),      //保存每个格子的丁昊然
   playing = false,       //游戏是否开始
   score = 0,             //分数
   beat = 0,              //鼠标点击次数
   success = 0,           //命中率
   knock = 0,             //鼠标点中丁昊然次数
   countDown = 30,        //倒计时
   interId = null,        //指定setInterval()的变量
   timeId = null,         //指定setTimeout()的变量

b=0; c=0; function GameOver(){

   timeStop();
   playing = false;
   clearMouse();

success=success.toFixed(3); c=success*100+"%"

   alert("Game Over!\n你打中的丁昊然数为:"+score+"\n命中率为:"+c);
   success = 0;
   score = 0;
   knock = 0;
   beat = 0;
   countDown = 30;

gameTime=30; /* 重置 */ } function timeShow(){

   document.form1.remtime.value = countDown;
   if(countDown == 0){
       GameOver();
       return;
                     }

else{

       countDown = countDown-1;
       timeId = setTimeout("timeShow()",1000);
       }

} function timeStop(){

   clearInterval(interId);//clearInterval()方法返回setInterval()方法的id
   clearTimeout(timeId);//clearTime()方法返回setTimeout()的id

} function show(){

   if(playing)
   {
       var current = Math.floor(Math.random()*36);
       //这里的路径也需要根据自己的实际文件路径来修改
       document.getElementById("td["+current+"]").innerHTML = '<img src="T--Tianjin--Game-bottle.png" width="100" height="100" >';
       //使用setTimeout()实现2秒后隐藏瓶子图片
       setTimeout("document.getElementById('td["+current+"]').innerHTML=",2000);
   }

} function clearMouse(){

   for(var i=0;i<=35;i++)
   {
       document.getElementById("td["+i+"]").innerHTML="";
   }

} function hit(id){

   if(playing==false)
   {
       alert("Start Playing!");
       return;
   }
   else
   {    
        beat +=1;
       if(document.getElementById("td["+id+"]").innerHTML!=" ")
       {
           score += 1;
           knock +=1;

/*playSound(); */

           success = knock/beat;

b=success.toFixed(3);

           document.form1.success.value = b;   /*success*/
           document.form1.score.value = score;
           document.getElementById("td["+id+"]").innerHTML=" ";
       }
       else
       {
           score += 0;
           success = knock/beat;

b=success.toFixed(3); /*success=success.toFixed(3); */

           document.form1.success.value = b;   /*success*/
           document.form1.score.value = score;
       }
   }

} function GameStart(){

   playing = true;
   interId = setInterval("show()",800);

/*success=success.toFixed(3); */

   document.form1.score.value = score;
   document.form1.success.value = success;
   timeShow();

countDown1(); }