home *** CD-ROM | disk | FTP | other *** search
- class CTournament
- {
- var tournamentPhase;
- var currentGroupFixture;
- var gameover;
- var secondRoundMatches;
- var quarterFinalMatches;
- var semiFinalMatches;
- var FinalMatches;
- var firstRoundMatches;
- var currentMatch;
- static var _oI;
- function CTournament()
- {
- this.tournamentPhase = -1;
- }
- function newTournament()
- {
- this.tournamentPhase = 1;
- this.currentGroupFixture = 0;
- this.gameover = false;
- this.createFirstRoundMatches();
- this.secondRoundMatches = new Array();
- this.quarterFinalMatches = new Array();
- this.semiFinalMatches = new Array();
- this.FinalMatches = new Array();
- this.gotoNextMatch();
- }
- function endTournament()
- {
- this.gameover = true;
- }
- function createFirstRoundMatches()
- {
- this.firstRoundMatches = new Array();
- this.currentMatch = null;
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- var _loc6_ = CTeamManager.ins().teams[_loc2_ * 4 + 0];
- var _loc5_ = CTeamManager.ins().teams[_loc2_ * 4 + 1];
- var _loc4_ = CTeamManager.ins().teams[_loc2_ * 4 + 2];
- var _loc3_ = CTeamManager.ins().teams[_loc2_ * 4 + 3];
- _loc6_.restartTeam(_loc2_);
- _loc5_.restartTeam(_loc2_);
- _loc4_.restartTeam(_loc2_);
- _loc3_.restartTeam(_loc2_);
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc6_,_loc4_));
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc5_,_loc3_));
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc6_,_loc5_));
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc3_,_loc4_));
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc3_,_loc6_));
- this.firstRoundMatches.push(new CMatch(_loc2_,_loc4_,_loc5_));
- _loc2_ = _loc2_ + 1;
- }
- }
- function createSecondRoundMatches()
- {
- this.secondRoundMatches = new Array();
- this.currentMatch = null;
- var _loc2_ = undefined;
- var _loc6_ = undefined;
- var _loc7_ = undefined;
- var _loc8_ = undefined;
- var _loc9_ = undefined;
- var _loc3_ = 0;
- while(_loc3_ < 8)
- {
- var _loc5_ = this.firstRoundMatches[_loc3_ * 6];
- var _loc4_ = this.firstRoundMatches[_loc3_ * 6 + 1];
- _loc2_ = new Array();
- _loc2_.push(_loc5_.team1);
- _loc2_.push(_loc5_.team2);
- _loc2_.push(_loc4_.team1);
- _loc2_.push(_loc4_.team2);
- _loc2_.sortOn("points",Array.NUMERIC | Array.DESCENDING);
- _loc6_ = _loc2_[0];
- _loc7_ = _loc2_[1];
- _loc5_ = this.firstRoundMatches[(_loc3_ + 1) * 6];
- _loc4_ = this.firstRoundMatches[(_loc3_ + 1) * 6 + 1];
- _loc2_ = new Array();
- _loc2_.push(_loc5_.team1);
- _loc2_.push(_loc5_.team2);
- _loc2_.push(_loc4_.team1);
- _loc2_.push(_loc4_.team2);
- _loc2_.sortOn("points",Array.NUMERIC | Array.DESCENDING);
- _loc8_ = _loc2_[0];
- _loc9_ = _loc2_[1];
- this.secondRoundMatches.push(new CMatch(0,_loc6_,_loc9_));
- this.secondRoundMatches.push(new CMatch(0,_loc8_,_loc7_));
- _loc3_ += 2;
- }
- }
- function createQuarterFinalMatches()
- {
- this.quarterFinalMatches = new Array();
- this.currentMatch = null;
- this.quarterFinalMatches.push(new CMatch(0,this.winnerof(this.secondRoundMatches[0]),this.winnerof(this.secondRoundMatches[2])));
- this.quarterFinalMatches.push(new CMatch(0,this.winnerof(this.secondRoundMatches[1]),this.winnerof(this.secondRoundMatches[3])));
- this.quarterFinalMatches.push(new CMatch(0,this.winnerof(this.secondRoundMatches[4]),this.winnerof(this.secondRoundMatches[6])));
- this.quarterFinalMatches.push(new CMatch(0,this.winnerof(this.secondRoundMatches[5]),this.winnerof(this.secondRoundMatches[7])));
- }
- function createSemiFinalMatches()
- {
- this.semiFinalMatches = new Array();
- this.currentMatch = null;
- this.semiFinalMatches.push(new CMatch(0,this.winnerof(this.quarterFinalMatches[0]),this.winnerof(this.quarterFinalMatches[2])));
- this.semiFinalMatches.push(new CMatch(0,this.winnerof(this.quarterFinalMatches[1]),this.winnerof(this.quarterFinalMatches[3])));
- }
- function createFinalMatches()
- {
- this.FinalMatches = new Array();
- this.currentMatch = null;
- this.FinalMatches.push(new CMatch(0,this.winnerof(this.semiFinalMatches[0]),this.winnerof(this.semiFinalMatches[1])));
- }
- function winnerof(ma)
- {
- if(ma.scoreteam1 > ma.scoreteam2)
- {
- return ma.team1;
- }
- return ma.team2;
- }
- function finishedPhase()
- {
- while(this.tournamentPhase < 8)
- {
- this.nextPhase();
- }
- }
- function nextPhase()
- {
- var _loc2_ = "";
- this.tournamentPhase = this.tournamentPhase + 1;
- this.gotoNextMatch();
- switch(this.tournamentPhase)
- {
- case 4:
- this.createSecondRoundMatches();
- this.currentMatch = this.inCurrentMatches();
- _loc2_ = "";
- if(this.currentMatch == null)
- {
- this.gameover = true;
- }
- else
- {
- _loc2_ = "Congratulation, You have been qualified for playoff round!";
- }
- break;
- case 5:
- this.createQuarterFinalMatches();
- this.currentMatch = this.inCurrentMatches();
- _loc2_ = "";
- if(this.currentMatch == null)
- {
- this.gameover = true;
- }
- else
- {
- _loc2_ = "Congratulation, You\'re going to the quarter final!";
- }
- break;
- case 6:
- this.createSemiFinalMatches();
- this.currentMatch = this.inCurrentMatches();
- _loc2_ = "";
- if(this.currentMatch == null)
- {
- this.gameover = true;
- }
- else
- {
- _loc2_ = "Congratulation, You\'re going to semi final!";
- }
- break;
- case 7:
- this.createFinalMatches();
- this.currentMatch = this.inCurrentMatches();
- _loc2_ = "";
- if(this.currentMatch == null)
- {
- this.gameover = true;
- }
- else
- {
- _loc2_ = "Congratulation, You\'re going to final!";
- }
- break;
- case 8:
- _loc2_ = "";
- this.gameover = true;
- }
- return _loc2_;
- }
- function gotoNextMatch()
- {
- switch(this.tournamentPhase)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- var _loc3_ = false;
- while(!_loc3_ && this.currentGroupFixture < 6)
- {
- var _loc2_ = this.inCurrentMatches();
- if(_loc2_ != null)
- {
- if(!_loc2_.played)
- {
- _loc3_ = true;
- this.currentMatch = _loc2_;
- return undefined;
- }
- this.simulateMatches();
- }
- else
- {
- this.simulateMatches();
- }
- this.currentGroupFixture = this.currentGroupFixture + 1;
- }
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- this.simulateMatches();
- }
- }
- function inCurrentMatches()
- {
- if(this.tournamentPhase < 4)
- {
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- var _loc3_ = this.firstRoundMatches[_loc2_ * 6 + this.currentGroupFixture];
- if(_loc3_.team1 == CTeamManager.ins().currentTeam || _loc3_.team2 == CTeamManager.ins().currentTeam)
- {
- return _loc3_;
- }
- _loc2_ = _loc2_ + 1;
- }
- return null;
- }
- switch(this.tournamentPhase)
- {
- case 4:
- _loc2_ = 0;
- while(_loc2_ < this.secondRoundMatches.length)
- {
- _loc3_ = this.secondRoundMatches[_loc2_];
- if(_loc3_.team1 == CTeamManager.ins().currentTeam || _loc3_.team2 == CTeamManager.ins().currentTeam)
- {
- return _loc3_;
- }
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 5:
- _loc2_ = 0;
- while(_loc2_ < this.quarterFinalMatches.length)
- {
- _loc3_ = this.quarterFinalMatches[_loc2_];
- if(_loc3_.team1 == CTeamManager.ins().currentTeam || _loc3_.team2 == CTeamManager.ins().currentTeam)
- {
- return _loc3_;
- }
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 6:
- _loc2_ = 0;
- while(_loc2_ < this.semiFinalMatches.length)
- {
- _loc3_ = this.semiFinalMatches[_loc2_];
- if(_loc3_.team1 == CTeamManager.ins().currentTeam || _loc3_.team2 == CTeamManager.ins().currentTeam)
- {
- return _loc3_;
- }
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 7:
- _loc2_ = 0;
- while(_loc2_ < this.FinalMatches.length)
- {
- _loc3_ = this.FinalMatches[_loc2_];
- if(_loc3_.team1 == CTeamManager.ins().currentTeam || _loc3_.team2 == CTeamManager.ins().currentTeam)
- {
- return _loc3_;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- return null;
- }
- function simulateMatches()
- {
- if(this.tournamentPhase < 5)
- {
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- var _loc3_ = this.firstRoundMatches[_loc2_ * 6 + this.currentGroupFixture];
- if(_loc3_ != this.currentMatch)
- {
- _loc3_.randomMatch(true);
- }
- _loc3_.calculateResult();
- _loc2_ = _loc2_ + 1;
- }
- }
- else
- {
- switch(this.tournamentPhase)
- {
- case 5:
- _loc2_ = 0;
- while(_loc2_ < this.secondRoundMatches.length)
- {
- _loc3_ = this.secondRoundMatches[_loc2_];
- if(_loc3_ != this.currentMatch)
- {
- _loc3_.randomMatch(false);
- }
- _loc3_.calculateResult();
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 6:
- _loc2_ = 0;
- while(_loc2_ < this.quarterFinalMatches.length)
- {
- _loc3_ = this.quarterFinalMatches[_loc2_];
- if(_loc3_ != this.currentMatch)
- {
- _loc3_.randomMatch(false);
- }
- _loc3_.calculateResult();
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 7:
- _loc2_ = 0;
- while(_loc2_ < this.semiFinalMatches.length)
- {
- _loc3_ = this.semiFinalMatches[_loc2_];
- if(_loc3_ != this.currentMatch)
- {
- _loc3_.randomMatch(false);
- }
- _loc3_.calculateResult();
- _loc2_ = _loc2_ + 1;
- }
- break;
- case 8:
- _loc2_ = 0;
- while(_loc2_ < this.FinalMatches.length)
- {
- _loc3_ = this.FinalMatches[_loc2_];
- if(_loc3_ != this.currentMatch)
- {
- _loc3_.randomMatch(false);
- }
- _loc3_.calculateResult();
- _loc2_ = _loc2_ + 1;
- }
- }
- }
- }
- function getTournamentMatchData(mat)
- {
- var _loc2_ = new Object();
- var _loc3_ = this.getMatchFronCurrentMatchSet(mat);
- _loc2_.team1 = _loc3_.team1.teamname;
- _loc2_.team2 = _loc3_.team2.teamname;
- _loc2_.teamwin = _loc3_.teamwin.teamname;
- return _loc2_;
- }
- function getTournamentGroupData(grp)
- {
- var _loc2_ = new Object();
- var _loc5_ = this.firstRoundMatches[grp * 6];
- var _loc4_ = this.firstRoundMatches[grp * 6 + 1];
- var _loc10_ = this.firstRoundMatches[grp * 6 + 2];
- var _loc9_ = this.firstRoundMatches[grp * 6 + 3];
- var _loc8_ = this.firstRoundMatches[grp * 6 + 4];
- var _loc7_ = this.firstRoundMatches[grp * 6 + 5];
- _loc2_.nat1 = _loc5_.team1.teamname;
- _loc2_.nat3 = _loc5_.team2.teamname;
- _loc2_.nat2 = _loc4_.team1.teamname;
- _loc2_.nat4 = _loc4_.team2.teamname;
- _loc2_.a1 = _loc5_.scoreteam1;
- _loc2_.a2 = _loc5_.scoreteam2;
- _loc2_.b1 = _loc4_.scoreteam1;
- _loc2_.b2 = _loc4_.scoreteam2;
- _loc2_.c1 = _loc10_.scoreteam1;
- _loc2_.c2 = _loc10_.scoreteam2;
- _loc2_.d1 = _loc9_.scoreteam1;
- _loc2_.d2 = _loc9_.scoreteam2;
- _loc2_.e1 = _loc8_.scoreteam1;
- _loc2_.e2 = _loc8_.scoreteam2;
- _loc2_.f1 = _loc7_.scoreteam1;
- _loc2_.f2 = _loc7_.scoreteam2;
- var _loc3_ = new Array();
- _loc3_.push(_loc5_.team1);
- _loc3_.push(_loc5_.team2);
- _loc3_.push(_loc4_.team1);
- _loc3_.push(_loc4_.team2);
- _loc3_.sortOn("points",Array.NUMERIC | Array.DESCENDING);
- _loc2_.win1 = _loc3_[0].teamname;
- _loc2_.win2 = _loc3_[1].teamname;
- _loc2_.win3 = _loc3_[2].teamname;
- _loc2_.win4 = _loc3_[3].teamname;
- _loc2_.w1 = _loc3_[0].won;
- _loc2_.w2 = _loc3_[1].won;
- _loc2_.w3 = _loc3_[2].won;
- _loc2_.w4 = _loc3_[3].won;
- _loc2_.t1 = _loc3_[0].tied;
- _loc2_.t2 = _loc3_[1].tied;
- _loc2_.t3 = _loc3_[2].tied;
- _loc2_.t4 = _loc3_[3].tied;
- _loc2_.l1 = _loc3_[0].lost;
- _loc2_.l2 = _loc3_[1].lost;
- _loc2_.l3 = _loc3_[2].lost;
- _loc2_.l4 = _loc3_[3].lost;
- _loc2_.p1 = _loc3_[0].score;
- _loc2_.p2 = _loc3_[1].score;
- _loc2_.p3 = _loc3_[2].score;
- _loc2_.p4 = _loc3_[3].score;
- return _loc2_;
- }
- function getMatchFronCurrentMatchSet(mat)
- {
- switch(this.tournamentPhase)
- {
- case 4:
- return this.secondRoundMatches[mat];
- case 5:
- return this.quarterFinalMatches[mat];
- case 6:
- return this.semiFinalMatches[mat];
- case 7:
- return this.FinalMatches[mat];
- default:
- }
- }
- function numMatchSet()
- {
- switch(this.tournamentPhase)
- {
- case 4:
- return 16;
- case 5:
- return 8;
- case 6:
- return 4;
- case 7:
- return 2;
- default:
- }
- }
- function getToutnamentStatus()
- {
- switch(this.tournamentPhase)
- {
- case 1:
- return "First Round - fixture 1";
- case 2:
- return "First Round - fixture 2";
- case 3:
- return "First Round - fixture 3";
- case 4:
- return "Playoff - Second Round";
- case 5:
- return "Playoff - Quarter Finals";
- case 6:
- return "Playoff - Semi Finals";
- case 7:
- return "Playoff - Finals";
- case 8:
- return "World Champion";
- default:
- }
- }
- static function _buildInstance()
- {
- CTournament._oI = new CTournament();
- return CTournament._oI;
- }
- static function ins()
- {
- return !(CTournament._oI instanceof CTournament) ? CTournament._buildInstance() : CTournament._oI;
- }
- }
-