home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 136 / MOBICLIC136.ISO / pc / DATA / HOTE / libs / xlib1 / xlib1.swf / scripts / __Packages / xb / classes / Liste.as < prev   
Text File  |  2011-07-20  |  8KB  |  263 lines

  1. class xb.classes.Liste
  2. {
  3.    function Liste(p)
  4.    {
  5.       this._p = p;
  6.       this.Init();
  7.    }
  8.    function Init()
  9.    {
  10.       this._liste = [];
  11.       this._position = -1;
  12.       trace(this._p.depart + " " + this._p.fin + " " + this._p.ModeTirage);
  13.       this._mode_tirage = this._p.ModeTirage != undefined ? this._p.ModeTirage : "boucle";
  14.       this.Remplir(this._p);
  15.       if(this._p.melanger == true)
  16.       {
  17.          this.Melanger();
  18.       }
  19.    }
  20.    function Remplir(p)
  21.    {
  22.       this._p = p;
  23.       if((this._p.depart == undefined || this._p.fin == undefined) && this._p.ArraySource == undefined)
  24.       {
  25.          return false;
  26.       }
  27.       this._p.mode = this._p.mode != undefined ? this._p.mode : "linear";
  28.       this._p.nombre = this._p.nombre != undefined ? this._p.nombre - 1 : Math.abs(this._p.fin - this._p.depart);
  29.       this._liste = [];
  30.       if(this._p.ArraySource != undefined)
  31.       {
  32.          var _loc2_ = 0;
  33.          while(_loc2_ < this._p.ArraySource.length)
  34.          {
  35.             this._liste[_loc2_] = this._p.ArraySource[_loc2_];
  36.             _loc2_ = _loc2_ + 1;
  37.          }
  38.       }
  39.       else
  40.       {
  41.          var _loc5_ = (this._p.fin - this._p.depart) / this._p.nombre;
  42.          var _loc4_ = this._p.depart;
  43.          if(this._p.mode == "linear")
  44.          {
  45.             var _loc3_ = 0;
  46.             while(_loc3_ <= this._p.nombre)
  47.             {
  48.                this._liste.push(_loc5_ * _loc3_ + _loc4_);
  49.                _loc3_ = _loc3_ + 1;
  50.             }
  51.          }
  52.          else if(this._p.mode == "exp")
  53.          {
  54.             _loc3_ = 0;
  55.             while(_loc3_ <= this._p.nombre)
  56.             {
  57.                this._liste.push(_loc5_ / this._p.nombre * _loc3_ * _loc3_ + _loc4_);
  58.                _loc3_ = _loc3_ + 1;
  59.             }
  60.          }
  61.       }
  62.       if(this._p.accidents != undefined && this._p.noise_en_dernier != false)
  63.       {
  64.          _loc2_ = 0;
  65.          while(_loc2_ < this._p.accidents.length)
  66.          {
  67.             this._liste[xb.classes.Liste.randomValue(this._p.accidents[_loc2_].depart,this._p.accidents[_loc2_].fin)] = this._p.accidents[_loc2_].valeur;
  68.             _loc2_ = _loc2_ + 1;
  69.          }
  70.       }
  71.       if(this._p.noise != undefined && this._p.noise != false)
  72.       {
  73.          this.Noise();
  74.       }
  75.       if(this._p.accidents != undefined && this._p.noise_en_dernier == false)
  76.       {
  77.          _loc2_ = 0;
  78.          while(_loc2_ < this._p.accidents.length)
  79.          {
  80.             this._liste[xb.classes.Liste.randomValue(this._p.accidents[_loc2_].depart,this._p.accidents[_loc2_].fin)] = this._p.accidents[_loc2_].valeur;
  81.             _loc2_ = _loc2_ + 1;
  82.          }
  83.       }
  84.       return true;
  85.    }
  86.    function Noise()
  87.    {
  88.       if(this._p.noiseAmplitude == undefined)
  89.       {
  90.          this._p.noiseAmplitude = 0.1;
  91.       }
  92.       trace("_p.noiseAmplitude : " + this._p.noiseAmplitude);
  93.       var _loc3_ = undefined;
  94.       var _loc2_ = 0;
  95.       while(_loc2_ < this._liste.length)
  96.       {
  97.          if(typeof this._liste[_loc2_] == "number")
  98.          {
  99.             _loc3_ = this._liste[_loc2_] + xb.classes.Liste.randomValue(-1000,1000) / 1000 * this._p.noiseAmplitude;
  100.             if(_loc3_ < this._p.depart)
  101.             {
  102.                _loc3_ = this._p.depart;
  103.             }
  104.             if(_loc3_ > this._p.fin)
  105.             {
  106.                _loc3_ = this._p.fin;
  107.             }
  108.             this._liste[_loc2_] = _loc3_;
  109.          }
  110.          _loc2_ = _loc2_ + 1;
  111.       }
  112.    }
  113.    function Prochain()
  114.    {
  115.       this._position = this._position + 1;
  116.       if(this._position >= this._liste.length)
  117.       {
  118.          switch(this._mode_tirage)
  119.          {
  120.             case "1fois":
  121.                return "fini";
  122.             case "boucle":
  123.                this._position = 0;
  124.                break;
  125.             case "remelanger":
  126.                this.Melanger();
  127.                this._position = 0;
  128.          }
  129.       }
  130.       return this._liste[this._position];
  131.    }
  132.    function Melanger()
  133.    {
  134.       var _loc2_ = this._liste[this._position];
  135.       this._liste = xb.classes.Liste.randomiseList(this._liste);
  136.       if(this._liste[0] == _loc2_)
  137.       {
  138.          this.Melanger();
  139.       }
  140.       trace("Melanger" + this._liste);
  141.    }
  142.    function SupprimerActuel()
  143.    {
  144.       this._liste.splice(this._position,1);
  145.       this._position = this._position - 1;
  146.    }
  147.    function SupprimerElements(p)
  148.    {
  149.       if(typeof p == "number")
  150.       {
  151.          var _loc2_ = 0;
  152.          while(_loc2_ < p)
  153.          {
  154.             this._liste.splice(xb.classes.Liste.randomValue(0,this._liste.length - 1),1);
  155.             _loc2_ = _loc2_ + 1;
  156.          }
  157.       }
  158.       this._position = 0;
  159.    }
  160.    static function randomiseList(myList)
  161.    {
  162.       var _loc2_ = myList.slice();
  163.       var _loc4_ = [];
  164.       var _loc3_ = undefined;
  165.       var _loc5_ = _loc2_.length;
  166.       var _loc1_ = 0;
  167.       while(_loc1_ < _loc5_)
  168.       {
  169.          _loc3_ = xb.classes.Liste.randomValue(0,_loc2_.length - 1);
  170.          _loc4_.push(_loc2_[_loc3_]);
  171.          _loc2_.splice(_loc3_,1);
  172.          _loc1_ = _loc1_ + 1;
  173.       }
  174.       return _loc4_;
  175.    }
  176.    static function randomValue(min, max)
  177.    {
  178.       var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
  179.       return _loc1_;
  180.    }
  181.    function Info()
  182.    {
  183.       trace("Info : " + this.Info);
  184.       var _loc2_ = 0;
  185.       while(_loc2_ < this._liste.length)
  186.       {
  187.          trace(_loc2_ + " : " + this._liste[_loc2_]);
  188.          _loc2_ = _loc2_ + 1;
  189.       }
  190.    }
  191.    function InfoCourbe()
  192.    {
  193.       var _loc12_ = arguments[0];
  194.       trace("p : " + _loc12_);
  195.       trace("p : " + _loc12_.couleur);
  196.       var _loc13_ = _loc12_.couleur != undefined ? _loc12_.couleur : 16711935;
  197.       var _loc9_ = _root.createEmptyMovieClip("courbe",_root.getNextHighestDepth());
  198.       var _loc11_ = _loc9_.createEmptyMovieClip("axe",5);
  199.       var _loc10_ = _loc9_.createEmptyMovieClip("courbe",10);
  200.       var _loc5_ = undefined;
  201.       var _loc6_ = this._liste;
  202.       var _loc14_ = _loc6_.length;
  203.       var _loc8_ = 10;
  204.       var _loc7_ = 300;
  205.       _loc11_.lineStyle(1,13421772,100);
  206.       _loc11_.moveTo(0,_loc7_);
  207.       _loc11_.lineTo(800,_loc7_);
  208.       _loc11_.lineTo(_loc8_,_loc7_);
  209.       _loc11_.lineTo(_loc8_,600);
  210.       _loc11_.lineTo(_loc8_,0);
  211.       _loc10_._alpha = 70;
  212.       _loc10_.lineStyle(1,_loc13_,100);
  213.       _loc10_.moveTo(_loc8_,_loc7_ - _loc6_[0] / 100);
  214.       var _loc4_ = 1;
  215.       while(_loc4_ < _loc6_.length)
  216.       {
  217.          _loc5_ = _loc9_.createEmptyMovieClip("croix",10 + _loc4_);
  218.          _loc5_.lineStyle(1,0,100);
  219.          _loc5_.moveTo(_loc4_ * 10 + _loc8_,_loc7_ - _loc6_[_loc4_] / 100 - 2);
  220.          _loc5_.lineTo(_loc4_ * 10 + _loc8_,_loc7_ - _loc6_[_loc4_] / 100 + 2);
  221.          _loc10_.lineTo(_loc4_ * 10 + _loc8_,_loc7_ - _loc6_[_loc4_] / 100);
  222.          _loc4_ = _loc4_ + 1;
  223.       }
  224.       _loc9_._x = 0;
  225.       _loc9_._y = 0;
  226.       _loc9_._width = 790;
  227.       _loc9_._height = 600;
  228.    }
  229.    function GetPos(element)
  230.    {
  231.       var _loc2_ = 0;
  232.       while(_loc2_ < this._liste.length)
  233.       {
  234.          if(this._liste[_loc2_] == element)
  235.          {
  236.             return _loc2_;
  237.          }
  238.          _loc2_ = _loc2_ + 1;
  239.       }
  240.       return false;
  241.    }
  242.    function get e()
  243.    {
  244.       return this._liste;
  245.    }
  246.    function set ModeTirage(mode)
  247.    {
  248.       this._mode_tirage = mode;
  249.    }
  250.    function get Taille()
  251.    {
  252.       return this._liste.length;
  253.    }
  254.    function set Position(position)
  255.    {
  256.       this._position = position;
  257.    }
  258.    function get Position()
  259.    {
  260.       return this._position;
  261.    }
  262. }
  263.