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

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