home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / bubble_tanks_2.swf / scripts / __Packages / Timer.as < prev    next >
Encoding:
Text File  |  2008-09-02  |  3.1 KB  |  140 lines

  1. class Timer
  2. {
  3.    var intTimer;
  4.    var blnCountUp;
  5.    var intStartTime;
  6.    var intEndTime;
  7.    var blnPaused;
  8.    var intPauseStart;
  9.    var intPauseTime;
  10.    function Timer()
  11.    {
  12.       this.intTimer = 0;
  13.       this.blnCountUp = true;
  14.       this.intStartTime = 0;
  15.       this.intEndTime = 0;
  16.       this.blnPaused = false;
  17.       this.intPauseStart = 0;
  18.       this.intPauseTime = 0;
  19.    }
  20.    function Run()
  21.    {
  22.       if(this.blnPaused == false)
  23.       {
  24.          if(this.blnCountUp == true)
  25.          {
  26.             this.intTimer = getTimer() - this.intStartTime - this.intPauseTime;
  27.          }
  28.          else
  29.          {
  30.             this.intTimer = this.intEndTime - this.intStartTime - (getTimer() - this.intStartTime + this.intPauseTime);
  31.          }
  32.       }
  33.       else
  34.       {
  35.          this.intPauseTime += getTimer() - this.intPauseStart;
  36.          this.intPauseStart = getTimer();
  37.       }
  38.    }
  39.    function Pause()
  40.    {
  41.       if(this.blnPaused == false)
  42.       {
  43.          this.blnPaused = true;
  44.          this.intPauseStart = getTimer();
  45.       }
  46.    }
  47.    function UnPause()
  48.    {
  49.       if(this.blnPaused == true)
  50.       {
  51.          this.intPauseTime += getTimer() - this.intPauseStart;
  52.          this.blnPaused = false;
  53.       }
  54.    }
  55.    function GetTime()
  56.    {
  57.       return this.intTimer;
  58.    }
  59.    function GetTimeString()
  60.    {
  61.       return this.MillisecondsToTimeString(this.intTimer);
  62.    }
  63.    function Start()
  64.    {
  65.       this.SetCountUp();
  66.    }
  67.    function SetCountUp()
  68.    {
  69.       this.blnCountUp = true;
  70.       this.Reset();
  71.    }
  72.    function SetCountDown(durationInMilliseconds)
  73.    {
  74.       this.blnCountUp = false;
  75.       this.intEndTime = getTimer() + durationInMilliseconds;
  76.       this.Reset();
  77.    }
  78.    function Reset()
  79.    {
  80.       this.intStartTime = getTimer();
  81.       this.blnPaused = false;
  82.       this.intPauseStart = 0;
  83.       this.intPauseTime = 0;
  84.       if(this.blnCountUp == true)
  85.       {
  86.          this.intTimer = 0;
  87.       }
  88.       else
  89.       {
  90.          this.intTimer = this.intEndTime - this.intStartTime;
  91.       }
  92.    }
  93.    function MillisecondsToTimeString(intMilliSecs)
  94.    {
  95.       var _loc5_ = intMilliSecs;
  96.       var _loc4_ = Math.floor(_loc5_ / 1000);
  97.       if(_loc4_ >= 60)
  98.       {
  99.          var _loc1_ = _loc5_ / 1000;
  100.          var _loc3_ = _loc1_ / 60;
  101.          if(_loc1_ > 59)
  102.          {
  103.             _loc1_ -= Math.floor(_loc3_) * 60;
  104.          }
  105.          var _loc6_ = undefined;
  106.          var _loc2_ = undefined;
  107.          if(_loc3_ < 10)
  108.          {
  109.             _loc2_ = "0" + Math.floor(_loc3_);
  110.          }
  111.          else
  112.          {
  113.             _loc2_ = "" + Math.floor(_loc3_);
  114.          }
  115.          if(_loc1_ < 10)
  116.          {
  117.             _loc6_ = _loc2_ + ":0" + Math.floor(_loc1_);
  118.          }
  119.          else if(_loc1_ == 0)
  120.          {
  121.             _loc6_ = _loc2_ + ":00";
  122.          }
  123.          else
  124.          {
  125.             _loc6_ = _loc2_ + ":" + Math.floor(_loc1_);
  126.          }
  127.          return _loc6_;
  128.       }
  129.       if(_loc4_ < 10)
  130.       {
  131.          _loc6_ = "00:0" + Math.floor(_loc4_);
  132.       }
  133.       else
  134.       {
  135.          _loc6_ = "00:" + Math.floor(_loc4_);
  136.       }
  137.       return _loc6_;
  138.    }
  139. }
  140.