home *** CD-ROM | disk | FTP | other *** search
/ Champak 108 / jogo-disk-108.iso / Games / rush_hour.swf / scripts / __Packages / Board.as next >
Encoding:
Text File  |  2010-05-15  |  6.4 KB  |  227 lines

  1. class Board extends MovieClip
  2. {
  3.    var mode;
  4.    var spacing = 32;
  5.    var cars = new Array();
  6.    var board = new Array();
  7.    var level = 1;
  8.    function Board()
  9.    {
  10.       super();
  11.       this.attachMovie("borderfront","borderfront",1000000);
  12.       this.loadCar("playercar",2,1,1);
  13.    }
  14.    function loadCar(id, xpos, ypos, d)
  15.    {
  16.       var _loc4_ = this.spacing * (xpos + ypos);
  17.       var _loc3_ = this.spacing / 2 * (xpos - ypos);
  18.       var _loc5_ = _loc4_ + (_loc3_ + 80) * 6 * 32;
  19.       var _loc2_ = this.attachMovie(id,"car" + d,_loc5_,{_x:_loc4_,_y:_loc3_,xpos:xpos,ypos:ypos,spacing:this.spacing});
  20.       this.placeCar(_loc2_,xpos,ypos);
  21.       this.cars.push(_loc2_);
  22.    }
  23.    function loadCars(l)
  24.    {
  25.       var _loc2_ = 1;
  26.       while(_loc2_ <= l.length)
  27.       {
  28.          this.loadCar(l[_loc2_ - 1][0],l[_loc2_ - 1][1],l[_loc2_ - 1][2],_loc2_);
  29.          _loc2_ = _loc2_ + 1;
  30.       }
  31.    }
  32.    function unloadCars()
  33.    {
  34.       var _loc2_ = 0;
  35.       while(_loc2_ < this.cars.length)
  36.       {
  37.          this.cars[_loc2_].swapDepths(100000);
  38.          this.cars[_loc2_].removeMovieClip();
  39.          _loc2_ = _loc2_ + 1;
  40.       }
  41.       this.cars = new Array();
  42.    }
  43.    function placeCar(car, xpos, ypos)
  44.    {
  45.       this.board[xpos][ypos] = 1;
  46.       var _loc2_ = 1;
  47.       while(_loc2_ <= car.size[0])
  48.       {
  49.          this.board[xpos + _loc2_][ypos] = 1;
  50.          _loc2_ = _loc2_ + 1;
  51.       }
  52.       _loc2_ = 1;
  53.       while(_loc2_ <= car.size[1])
  54.       {
  55.          this.board[xpos][ypos + _loc2_] = 1;
  56.          _loc2_ = _loc2_ + 1;
  57.       }
  58.    }
  59.    function updateBoard()
  60.    {
  61.       this.loadBoard();
  62.       var _loc2_ = 0;
  63.       while(_loc2_ < this.cars.length)
  64.       {
  65.          this.placeCar(this.cars[_loc2_],this.cars[_loc2_].xpos,this.cars[_loc2_].ypos);
  66.          _loc2_ = _loc2_ + 1;
  67.       }
  68.    }
  69.    function loadBoard()
  70.    {
  71.       this.board = new Array([0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]);
  72.    }
  73.    function possibleMoves(car)
  74.    {
  75.       var _loc4_ = undefined;
  76.       var _loc6_ = undefined;
  77.       var _loc3_ = undefined;
  78.       var _loc5_ = undefined;
  79.       if(car.size[0] > 0)
  80.       {
  81.          _loc4_ = car.xpos;
  82.          _loc6_ = _loc4_ + car.size[0];
  83.          _loc3_ = car.ypos;
  84.          _loc5_ = _loc3_;
  85.          var _loc2_ = _loc4_ - 1;
  86.          while(_loc2_ >= 0)
  87.          {
  88.             if(this.board[_loc2_][_loc3_] != 0)
  89.             {
  90.                break;
  91.             }
  92.             _loc4_ = _loc2_;
  93.             _loc2_ = _loc2_ - 1;
  94.          }
  95.          _loc2_ = _loc6_ + 1;
  96.          while(_loc2_ <= 5)
  97.          {
  98.             if(this.board[_loc2_][_loc3_] != 0)
  99.             {
  100.                break;
  101.             }
  102.             _loc6_ = _loc2_;
  103.             _loc2_ = _loc2_ + 1;
  104.          }
  105.       }
  106.       else if(car.size[1] > 0)
  107.       {
  108.          _loc4_ = car.xpos;
  109.          _loc6_ = _loc4_;
  110.          _loc3_ = car.ypos;
  111.          _loc5_ = _loc3_ + car.size[1];
  112.          _loc2_ = _loc3_ - 1;
  113.          while(_loc2_ >= 0)
  114.          {
  115.             if(this.board[_loc4_][_loc2_] != 0)
  116.             {
  117.                break;
  118.             }
  119.             _loc3_ = _loc2_;
  120.             _loc2_ = _loc2_ - 1;
  121.          }
  122.          _loc2_ = _loc5_ + 1;
  123.          while(_loc2_ <= 5)
  124.          {
  125.             if(this.board[_loc4_][_loc2_] != 0)
  126.             {
  127.                break;
  128.             }
  129.             _loc5_ = _loc2_;
  130.             _loc2_ = _loc2_ + 1;
  131.          }
  132.       }
  133.       return [[_loc4_,_loc3_],[_loc6_,_loc5_]];
  134.    }
  135.    function loadLevel(num)
  136.    {
  137.       this.unloadCars();
  138.       this.loadBoard();
  139.       this.level = num;
  140.       var _loc2_ = new Level().getLevel(this.level);
  141.       this.loadCars(_loc2_);
  142.       var path = this;
  143.       this._parent.bg.but_next.gotoAndStop(2);
  144.       this._parent.bg.but_next._visible = true;
  145.       this._parent.bg.but_reset.gotoAndStop(1);
  146.       this._parent.bg.but_reset.onRelease = function()
  147.       {
  148.          path.loadLevel(path.level);
  149.       };
  150.       delete this._parent.bg.but_start.onRelease;
  151.    }
  152.    function endOfGame()
  153.    {
  154.       var path = this;
  155.       this._parent.bg.but_next.gotoAndStop(1);
  156.       this._parent.bg.but_reset.gotoAndStop(2);
  157.       delete this._parent.bg.but_reset.onRelease;
  158.       this._parent.bg.but_start.onRelease = function()
  159.       {
  160.          this._parent.container["level" + path.level].gotoAndStop(1);
  161.          path.level = path.level + 1;
  162.          this._parent.container["level" + path.level].gotoAndStop(2);
  163.          if(path.level > new Level().getNumberofLevels())
  164.          {
  165.             path.level = 1;
  166.          }
  167.          path.loadLevel(path.level);
  168.       };
  169.    }
  170.    function loadTraining()
  171.    {
  172.       this.mode = "training";
  173.       this._parent.bg.container["level" + this.level].gotoAndStop(2);
  174.       this.loadLevel(this.level);
  175.       var path = this;
  176.       this._parent.bg.but_back.onRelease = function()
  177.       {
  178.          path.unloadCars();
  179.          path.loadCar("playercar",2,1,1);
  180.          this._parent._parent.backToStart();
  181.       };
  182.    }
  183.    function endOfCompetition()
  184.    {
  185.       this.unloadCars();
  186.       var _loc2_ = this._parent.bg.timer.stopTimerAndGetTime();
  187.       this._parent.competitionPopUp(_loc2_);
  188.       this._parent.bg.but_next.gotoAndStop(2);
  189.       delete this._parent.bg.but_reset.onRelease;
  190.       this._parent.bg.but_reset.gotoAndStop(2);
  191.       delete this._parent.bg.but_start.onRelease;
  192.       delete this._parent.bg.but_back.onRelease;
  193.    }
  194.    function loadCompetitionLevel(newlevel)
  195.    {
  196.       this.unloadCars();
  197.       this.loadBoard();
  198.       this.loadCars(newlevel);
  199.       var path = this;
  200.       this._parent.bg.but_next.gotoAndStop(1);
  201.       this._parent.bg.but_reset.gotoAndStop(1);
  202.       this._parent.bg.but_reset.onRelease = function()
  203.       {
  204.          path.loadCompetitionLevel(newlevel);
  205.       };
  206.    }
  207.    function loadCompetition()
  208.    {
  209.       this.mode = "competition";
  210.       var _loc2_ = new Level().getCompetitionLevel();
  211.       this.loadCompetitionLevel(_loc2_);
  212.       this._parent.bg.timer.startTimer();
  213.       var path = this;
  214.       this._parent.bg.but_back.onRelease = function()
  215.       {
  216.          path.unloadCars();
  217.          path.loadCar("playercar",2,1,1);
  218.          this._parent._parent.backToStart();
  219.       };
  220.       this._parent.bg.but_start.onRelease = function()
  221.       {
  222.          path.loadCompetitionLevel(new Level().getCompetitionLevel());
  223.          this._parent.timer.startTimer();
  224.       };
  225.    }
  226. }
  227.