home *** CD-ROM | disk | FTP | other *** search
- class Board extends MovieClip
- {
- var mode;
- var spacing = 32;
- var cars = new Array();
- var board = new Array();
- var level = 1;
- function Board()
- {
- super();
- this.attachMovie("borderfront","borderfront",1000000);
- this.loadCar("playercar",2,1,1);
- }
- function loadCar(id, xpos, ypos, d)
- {
- var _loc4_ = this.spacing * (xpos + ypos);
- var _loc3_ = this.spacing / 2 * (xpos - ypos);
- var _loc5_ = _loc4_ + (_loc3_ + 80) * 6 * 32;
- var _loc2_ = this.attachMovie(id,"car" + d,_loc5_,{_x:_loc4_,_y:_loc3_,xpos:xpos,ypos:ypos,spacing:this.spacing});
- this.placeCar(_loc2_,xpos,ypos);
- this.cars.push(_loc2_);
- }
- function loadCars(l)
- {
- var _loc2_ = 1;
- while(_loc2_ <= l.length)
- {
- this.loadCar(l[_loc2_ - 1][0],l[_loc2_ - 1][1],l[_loc2_ - 1][2],_loc2_);
- _loc2_ = _loc2_ + 1;
- }
- }
- function unloadCars()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.cars.length)
- {
- this.cars[_loc2_].swapDepths(100000);
- this.cars[_loc2_].removeMovieClip();
- _loc2_ = _loc2_ + 1;
- }
- this.cars = new Array();
- }
- function placeCar(car, xpos, ypos)
- {
- this.board[xpos][ypos] = 1;
- var _loc2_ = 1;
- while(_loc2_ <= car.size[0])
- {
- this.board[xpos + _loc2_][ypos] = 1;
- _loc2_ = _loc2_ + 1;
- }
- _loc2_ = 1;
- while(_loc2_ <= car.size[1])
- {
- this.board[xpos][ypos + _loc2_] = 1;
- _loc2_ = _loc2_ + 1;
- }
- }
- function updateBoard()
- {
- this.loadBoard();
- var _loc2_ = 0;
- while(_loc2_ < this.cars.length)
- {
- this.placeCar(this.cars[_loc2_],this.cars[_loc2_].xpos,this.cars[_loc2_].ypos);
- _loc2_ = _loc2_ + 1;
- }
- }
- function loadBoard()
- {
- 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]);
- }
- function possibleMoves(car)
- {
- var _loc4_ = undefined;
- var _loc6_ = undefined;
- var _loc3_ = undefined;
- var _loc5_ = undefined;
- if(car.size[0] > 0)
- {
- _loc4_ = car.xpos;
- _loc6_ = _loc4_ + car.size[0];
- _loc3_ = car.ypos;
- _loc5_ = _loc3_;
- var _loc2_ = _loc4_ - 1;
- while(_loc2_ >= 0)
- {
- if(this.board[_loc2_][_loc3_] != 0)
- {
- break;
- }
- _loc4_ = _loc2_;
- _loc2_ = _loc2_ - 1;
- }
- _loc2_ = _loc6_ + 1;
- while(_loc2_ <= 5)
- {
- if(this.board[_loc2_][_loc3_] != 0)
- {
- break;
- }
- _loc6_ = _loc2_;
- _loc2_ = _loc2_ + 1;
- }
- }
- else if(car.size[1] > 0)
- {
- _loc4_ = car.xpos;
- _loc6_ = _loc4_;
- _loc3_ = car.ypos;
- _loc5_ = _loc3_ + car.size[1];
- _loc2_ = _loc3_ - 1;
- while(_loc2_ >= 0)
- {
- if(this.board[_loc4_][_loc2_] != 0)
- {
- break;
- }
- _loc3_ = _loc2_;
- _loc2_ = _loc2_ - 1;
- }
- _loc2_ = _loc5_ + 1;
- while(_loc2_ <= 5)
- {
- if(this.board[_loc4_][_loc2_] != 0)
- {
- break;
- }
- _loc5_ = _loc2_;
- _loc2_ = _loc2_ + 1;
- }
- }
- return [[_loc4_,_loc3_],[_loc6_,_loc5_]];
- }
- function loadLevel(num)
- {
- this.unloadCars();
- this.loadBoard();
- this.level = num;
- var _loc2_ = new Level().getLevel(this.level);
- this.loadCars(_loc2_);
- var path = this;
- this._parent.bg.but_next.gotoAndStop(2);
- this._parent.bg.but_next._visible = true;
- this._parent.bg.but_reset.gotoAndStop(1);
- this._parent.bg.but_reset.onRelease = function()
- {
- path.loadLevel(path.level);
- };
- delete this._parent.bg.but_start.onRelease;
- }
- function endOfGame()
- {
- var path = this;
- this._parent.bg.but_next.gotoAndStop(1);
- this._parent.bg.but_reset.gotoAndStop(2);
- delete this._parent.bg.but_reset.onRelease;
- this._parent.bg.but_start.onRelease = function()
- {
- this._parent.container["level" + path.level].gotoAndStop(1);
- path.level = path.level + 1;
- this._parent.container["level" + path.level].gotoAndStop(2);
- if(path.level > new Level().getNumberofLevels())
- {
- path.level = 1;
- }
- path.loadLevel(path.level);
- };
- }
- function loadTraining()
- {
- this.mode = "training";
- this._parent.bg.container["level" + this.level].gotoAndStop(2);
- this.loadLevel(this.level);
- var path = this;
- this._parent.bg.but_back.onRelease = function()
- {
- path.unloadCars();
- path.loadCar("playercar",2,1,1);
- this._parent._parent.backToStart();
- };
- }
- function endOfCompetition()
- {
- this.unloadCars();
- var _loc2_ = this._parent.bg.timer.stopTimerAndGetTime();
- this._parent.competitionPopUp(_loc2_);
- this._parent.bg.but_next.gotoAndStop(2);
- delete this._parent.bg.but_reset.onRelease;
- this._parent.bg.but_reset.gotoAndStop(2);
- delete this._parent.bg.but_start.onRelease;
- delete this._parent.bg.but_back.onRelease;
- }
- function loadCompetitionLevel(newlevel)
- {
- this.unloadCars();
- this.loadBoard();
- this.loadCars(newlevel);
- var path = this;
- this._parent.bg.but_next.gotoAndStop(1);
- this._parent.bg.but_reset.gotoAndStop(1);
- this._parent.bg.but_reset.onRelease = function()
- {
- path.loadCompetitionLevel(newlevel);
- };
- }
- function loadCompetition()
- {
- this.mode = "competition";
- var _loc2_ = new Level().getCompetitionLevel();
- this.loadCompetitionLevel(_loc2_);
- this._parent.bg.timer.startTimer();
- var path = this;
- this._parent.bg.but_back.onRelease = function()
- {
- path.unloadCars();
- path.loadCar("playercar",2,1,1);
- this._parent._parent.backToStart();
- };
- this._parent.bg.but_start.onRelease = function()
- {
- path.loadCompetitionLevel(new Level().getCompetitionLevel());
- this._parent.timer.startTimer();
- };
- }
- }
-