home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Juegos / 05-11-10-1.swf / scripts / __Packages / Timer.as < prev    next >
Encoding:
Text File  |  2005-11-18  |  1.6 KB  |  86 lines

  1. class Timer
  2. {
  3.    var FRAMERATE = 36;
  4.    var etat = new String();
  5.    var oldEtat = new String();
  6.    var nom = new String();
  7.    var paused = new Boolean();
  8.    var nbItToDo = new Number();
  9.    var nbItDone = new Number();
  10.    function Timer(l_nom)
  11.    {
  12.       this.nom = l_nom;
  13.       this.etat = "Idle";
  14.       this.oldEtat = "Idle";
  15.       this.nbItToDo = 0;
  16.       this.nbItDone = 0;
  17.       this.paused = false;
  18.    }
  19.    function EnterFrame()
  20.    {
  21.       if(!this.paused)
  22.       {
  23.          this[this.etat]();
  24.       }
  25.    }
  26.    function AddTime(l_nbSec)
  27.    {
  28.       this.nbItToDo += l_nbSec * this.FRAMERATE;
  29.    }
  30.    function GetCurrentTime()
  31.    {
  32.       var _loc2_ = new Number();
  33.       if(this.etat == "Running")
  34.       {
  35.          _loc2_ = Math.round(this.nbItDone / this.FRAMERATE);
  36.       }
  37.       else
  38.       {
  39.          _loc2_ = null;
  40.       }
  41.       return _loc2_;
  42.    }
  43.    function GetName()
  44.    {
  45.       return this.nom;
  46.    }
  47.    function GetState()
  48.    {
  49.       return this.etat;
  50.    }
  51.    function Idle()
  52.    {
  53.    }
  54.    function Pause()
  55.    {
  56.       this.paused = true;
  57.    }
  58.    function Running()
  59.    {
  60.       if(this.nbItDone >= this.nbItToDo)
  61.       {
  62.          this.etat = "Idle";
  63.       }
  64.       else
  65.       {
  66.          this.nbItDone = this.nbItDone + 1;
  67.       }
  68.    }
  69.    function StartTimer(l_nbSeconds)
  70.    {
  71.       this.nbItToDo = l_nbSeconds * this.FRAMERATE;
  72.       this.nbItDone = 0;
  73.       this.etat = "Running";
  74.    }
  75.    function StopTimer()
  76.    {
  77.       this.nbItToDo = 0;
  78.       this.nbItDone = 0;
  79.       this.etat = "Idle";
  80.    }
  81.    function UnPause()
  82.    {
  83.       this.paused = false;
  84.    }
  85. }
  86.