home *** CD-ROM | disk | FTP | other *** search
- package ENGINE.GAME
- {
- import ENGINE.CORE.OCache;
- import ENGINE.CORE.OGlobal;
- import ENGINE.CORE.OSound;
- import flash.net.*;
- import flash.utils.ByteArray;
-
- public class OGame
- {
-
- public static const catGlobal:String = "Global";
-
- public static const catTmp:String = "Tmp";
-
- protected static const strgMusicVolume:String = "Music Volume";
-
- protected static const strgResX:String = "ResX";
-
- protected static const strgResY:String = "ResY";
-
- protected static const strgСurPlayer:String = "Current Player";
-
- protected static const strgFullScreen:String = "Full Screen";
-
- protected static const strgSoundVolume:String = "Sound Volume";
-
- protected static const strgLocalScores:String = "Local Scores";
-
- public static const catPlayers:String = "Players";
-
-
- protected var iSTableSize:int;
-
- protected var iCache:OCache;
-
- protected var iPlayer:OPlayer;
-
- protected var iRNDFactor:int;
-
- protected var iModes:int;
-
- protected var iScores:OScoresTable;
-
- public function OGame(param1:int = 1, param2:int = 10, param3:int = 10)
- {
- var _loc4_:String = null;
- super();
- this.iModes = param1;
- this.iSTableSize = param2;
- registerClassAlias("OCacheClass",OCache);
- registerClassAlias("OGameParamsClass",OGameParams);
- registerClassAlias("OScoreParamsClass",OScoreParams);
- registerClassAlias("OScoresTableClass",OScoresTable);
- registerClassAlias("OPlayerClass",OPlayer);
- this.LoadCache();
- if(_loc4_ = this.iCache.GetCategoryItem(catGlobal,strgСurPlayer))
- {
- this.iPlayer = this.iCache.GetCategoryItem(catPlayers,_loc4_);
- this.iScores = this.iCache.GetCategoryItem(catGlobal,strgLocalScores);
- this.InitAfterLoadCache();
- }
- else
- {
- this.iScores = new OScoresTable(param1,this.iSTableSize);
- this.DefaultInitLocalScores();
- this.iCache.SetCategoryItem(catGlobal,strgLocalScores,this.iScores);
- this.iCache.SetCategoryItem(catGlobal,strgSoundVolume,1);
- this.iCache.SetCategoryItem(catGlobal,strgMusicVolume,1);
- this.iCache.SetCategoryItem(catGlobal,strgResX,OGlobal.StageRect.width);
- this.iCache.SetCategoryItem(catGlobal,strgResY,OGlobal.StageRect.height);
- this.iCache.SetCategoryItem(catGlobal,strgFullScreen,false);
- }
- OSound.SoundVolume = this.prSoundVolume;
- OSound.MusicVolume = this.prMusicVolume;
- }
-
- public function set prFullScreen(param1:Boolean) : void
- {
- this.iCache.SetCategoryItem(catGlobal,strgFullScreen,param1);
- }
-
- public function set prMode(param1:int) : void
- {
- this.iPlayer.iMode = param1;
- }
-
- public function get prGamesStartCount() : int
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
- }
-
- public function get prLevelScore() : int
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore;
- }
-
- public function set prPassword(param1:String) : void
- {
- this.iPlayer.iPassword = param1;
- }
-
- public function DeletePlayer(param1:String) : String
- {
- var _loc2_:String = null;
- var _loc3_:Array = null;
- _loc2_ = !!this.iPlayer ? this.iPlayer.iName : "";
- this.iCache.DeleteCategoryItem(catPlayers,param1);
- if(param1 == _loc2_)
- {
- _loc3_ = this.iCache.GetCategoryNames(catPlayers);
- if(!_loc3_)
- {
- this.iPlayer = null;
- return null;
- }
- this.iPlayer = this.iCache.GetCategoryItem(catPlayers,_loc3_[0]);
- this.iCache.SetCategoryItem(catGlobal,strgСurPlayer,_loc3_[0]);
- }
- return !!this.iPlayer ? this.iPlayer.iName : null;
- }
-
- public function get prPlayerNames() : Array
- {
- return this.iCache.GetCategoryNames(catPlayers);
- }
-
- public function ClearPersonalScores(param1:int) : void
- {
- this.iPlayer.iScoreTable.Clear(param1);
- }
-
- public function GetPersonalRecord(param1:int) : int
- {
- return this.iPlayer.iScoreTable.GetRecord(param1);
- }
-
- public function InitAfterLoadCache() : void
- {
- }
-
- public function AddScore(param1:int) : void
- {
- this.iPlayer.iGParams[this.iPlayer.iMode].iScore += param1;
- }
-
- public function get prPlayersData() : *
- {
- var _loc1_:OCache = null;
- var _loc2_:ByteArray = null;
- _loc1_ = this.iCache.GetItem(catPlayers);
- _loc2_ = _loc1_.Pack();
- _loc2_.uncompress();
- return _loc2_.readObject();
- }
-
- public function IsPersonalRecord(param1:int, param2:int) : Boolean
- {
- return this.iPlayer.iScoreTable.IsRecord(param1,param2);
- }
-
- public function LoadCache() : void
- {
- var so:SharedObject = null;
- var a:ByteArray = null;
- so = SharedObject.getLocal(OGlobal.AppName);
- if(so.data.iData == undefined)
- {
- this.iCache = new OCache();
- }
- else
- {
- try
- {
- a = so.data.iData;
- a.uncompress();
- this.iCache = a.readObject();
- }
- catch(error:Error)
- {
- this.iCache = new OCache();
- }
- }
- so.close();
- }
-
- public function NewGame() : void
- {
- this.iPlayer.iGParams[this.iPlayer.iMode].iLevel = 0;
- this.iPlayer.iGParams[this.iPlayer.iMode].iScore = 0;
- this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore = 0;
- this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame = null;
- ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
- }
-
- public function get prLevel() : int
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iLevel;
- }
-
- public function get prSoundVolume() : Number
- {
- return this.iCache.GetCategoryItem(catGlobal,strgSoundVolume);
- }
-
- public function get prPlayerName() : String
- {
- return !!this.iPlayer ? this.iPlayer.iName : "";
- }
-
- public function get prScore() : int
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iScore;
- }
-
- public function NextLevel() : Boolean
- {
- ++this.iPlayer.iGParams[this.iPlayer.iMode].iLevel;
- return true;
- }
-
- public function set prPlayersData(param1:*) : void
- {
- this.iCache.SetItem(catPlayers,param1);
- }
-
- public function Read(param1:String, param2:String) : *
- {
- return this.iCache.GetCategoryItem(param1,param2);
- }
-
- public function get prSavedGame() : String
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame;
- }
-
- public function set prResX(param1:int) : void
- {
- this.iCache.SetCategoryItem(catGlobal,strgResX,param1);
- }
-
- public function get prRNDFactor() : int
- {
- return this.iPlayer.iRNDFactor;
- }
-
- public function get prMusicVolume() : Number
- {
- return this.iCache.GetCategoryItem(catGlobal,strgMusicVolume);
- }
-
- public function Write(param1:String, param2:String, param3:*) : void
- {
- this.iCache.SetCategoryItem(param1,param2,param3);
- }
-
- public function Start() : void
- {
- ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
- }
-
- public function get prPassword() : String
- {
- return !!this.iPlayer.iPassword ? this.iPlayer.iPassword : "";
- }
-
- public function get prMode() : int
- {
- return this.iPlayer.iMode;
- }
-
- public function End() : void
- {
- ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesEnd;
- }
-
- public function set prSoundVolume(param1:Number) : void
- {
- OSound.SoundVolume = param1;
- this.iCache.SetCategoryItem(catGlobal,strgSoundVolume,param1);
- }
-
- public function SetLevelScore(param1:int) : void
- {
- this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore = param1;
- }
-
- public function GetLocalScores(param1:int, param2:int) : OScoreParams
- {
- return this.iScores.GetScore(param1,param2);
- }
-
- public function GetPersonalScores(param1:int, param2:int) : OScoreParams
- {
- return this.iPlayer.iScoreTable.GetScore(param1,param2);
- }
-
- public function AddScoreInTable(param1:int) : Boolean
- {
- var _loc2_:Boolean = false;
- _loc2_ = false;
- if(this.iScores.AddScore(this.prPlayerName,param1,this.prMode,this.prLevel))
- {
- this.iCache.SetCategoryItem(OGame.catGlobal,OGame.strgLocalScores,this.iScores);
- _loc2_ = true;
- }
- if(this.iPlayer.iScoreTable.AddScore(this.prPlayerName,param1,this.prMode,this.prLevel,true))
- {
- this.iCache.SetCategoryItem(OGame.catPlayers,this.prPlayerName,this.iPlayer);
- _loc2_ = true;
- }
- return _loc2_;
- }
-
- public function get prResX() : int
- {
- return this.iCache.GetCategoryItem(catGlobal,strgResX);
- }
-
- public function get prResY() : int
- {
- return this.iCache.GetCategoryItem(catGlobal,strgResY);
- }
-
- public function set prPlayerName(param1:String) : void
- {
- var _loc2_:OPlayer = null;
- _loc2_ = this.iCache.GetCategoryItem(catPlayers,param1);
- if(!_loc2_)
- {
- _loc2_ = new OPlayer(param1,"",this.iModes,this.iSTableSize);
- this.iCache.SetCategoryItem(catPlayers,param1,_loc2_);
- }
- this.iPlayer = _loc2_;
- this.iCache.SetCategoryItem(catGlobal,strgСurPlayer,param1);
- }
-
- public function DefaultInitLocalScores() : void
- {
- this.iScores.Clear(0);
- this.iScores.AddScore("Emily",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
- this.iScores.AddScore("Michael",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
- this.iScores.AddScore("Jacob",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
- this.iScores.AddScore("Isabella",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
- this.iScores.AddScore("Madison",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
- this.iScores.SortOn(0);
- }
-
- public function SaveCache() : Boolean
- {
- var _loc1_:SharedObject = null;
- var _loc2_:String = null;
- _loc1_ = SharedObject.getLocal(OGlobal.AppName);
- _loc1_.data.iData = this.iCache.Pack();
- _loc2_ = _loc1_.flush();
- _loc1_.close();
- return _loc2_ == SharedObjectFlushStatus.FLUSHED;
- }
-
- public function set prResY(param1:int) : void
- {
- this.iCache.SetCategoryItem(catGlobal,strgResY,param1);
- }
-
- public function SetSaveGame(param1:String) : void
- {
- this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame = param1;
- }
-
- public function get prGamesEndCount() : int
- {
- return this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesEnd;
- }
-
- public function set prMusicVolume(param1:Number) : void
- {
- OSound.MusicVolume = param1;
- this.iCache.SetCategoryItem(catGlobal,strgMusicVolume,param1);
- }
-
- public function get prFullScreen() : Boolean
- {
- return this.iCache.GetCategoryItem(catGlobal,strgFullScreen);
- }
-
- public function ClearLocalScores(param1:int) : void
- {
- this.iScores.Clear(param1);
- }
- }
- }
-