home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / ENGINE / GAME / OGame.as next >
Encoding:
Text File  |  2008-09-12  |  12.4 KB  |  392 lines

  1. package ENGINE.GAME
  2. {
  3.    import ENGINE.CORE.OCache;
  4.    import ENGINE.CORE.OGlobal;
  5.    import ENGINE.CORE.OSound;
  6.    import flash.net.*;
  7.    import flash.utils.ByteArray;
  8.    
  9.    public class OGame
  10.    {
  11.       
  12.       public static const catGlobal:String = "Global";
  13.       
  14.       public static const catTmp:String = "Tmp";
  15.       
  16.       protected static const strgMusicVolume:String = "Music Volume";
  17.       
  18.       protected static const strgResX:String = "ResX";
  19.       
  20.       protected static const strgResY:String = "ResY";
  21.       
  22.       protected static const strg╨íurPlayer:String = "Current Player";
  23.       
  24.       protected static const strgFullScreen:String = "Full Screen";
  25.       
  26.       protected static const strgSoundVolume:String = "Sound Volume";
  27.       
  28.       protected static const strgLocalScores:String = "Local Scores";
  29.       
  30.       public static const catPlayers:String = "Players";
  31.        
  32.       
  33.       protected var iSTableSize:int;
  34.       
  35.       protected var iCache:OCache;
  36.       
  37.       protected var iPlayer:OPlayer;
  38.       
  39.       protected var iRNDFactor:int;
  40.       
  41.       protected var iModes:int;
  42.       
  43.       protected var iScores:OScoresTable;
  44.       
  45.       public function OGame(param1:int = 1, param2:int = 10, param3:int = 10)
  46.       {
  47.          var _loc4_:String = null;
  48.          super();
  49.          this.iModes = param1;
  50.          this.iSTableSize = param2;
  51.          registerClassAlias("OCacheClass",OCache);
  52.          registerClassAlias("OGameParamsClass",OGameParams);
  53.          registerClassAlias("OScoreParamsClass",OScoreParams);
  54.          registerClassAlias("OScoresTableClass",OScoresTable);
  55.          registerClassAlias("OPlayerClass",OPlayer);
  56.          this.LoadCache();
  57.          if(_loc4_ = this.iCache.GetCategoryItem(catGlobal,strg╨íurPlayer))
  58.          {
  59.             this.iPlayer = this.iCache.GetCategoryItem(catPlayers,_loc4_);
  60.             this.iScores = this.iCache.GetCategoryItem(catGlobal,strgLocalScores);
  61.             this.InitAfterLoadCache();
  62.          }
  63.          else
  64.          {
  65.             this.iScores = new OScoresTable(param1,this.iSTableSize);
  66.             this.DefaultInitLocalScores();
  67.             this.iCache.SetCategoryItem(catGlobal,strgLocalScores,this.iScores);
  68.             this.iCache.SetCategoryItem(catGlobal,strgSoundVolume,1);
  69.             this.iCache.SetCategoryItem(catGlobal,strgMusicVolume,1);
  70.             this.iCache.SetCategoryItem(catGlobal,strgResX,OGlobal.StageRect.width);
  71.             this.iCache.SetCategoryItem(catGlobal,strgResY,OGlobal.StageRect.height);
  72.             this.iCache.SetCategoryItem(catGlobal,strgFullScreen,false);
  73.          }
  74.          OSound.SoundVolume = this.prSoundVolume;
  75.          OSound.MusicVolume = this.prMusicVolume;
  76.       }
  77.       
  78.       public function set prFullScreen(param1:Boolean) : void
  79.       {
  80.          this.iCache.SetCategoryItem(catGlobal,strgFullScreen,param1);
  81.       }
  82.       
  83.       public function set prMode(param1:int) : void
  84.       {
  85.          this.iPlayer.iMode = param1;
  86.       }
  87.       
  88.       public function get prGamesStartCount() : int
  89.       {
  90.          return this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
  91.       }
  92.       
  93.       public function get prLevelScore() : int
  94.       {
  95.          return this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore;
  96.       }
  97.       
  98.       public function set prPassword(param1:String) : void
  99.       {
  100.          this.iPlayer.iPassword = param1;
  101.       }
  102.       
  103.       public function DeletePlayer(param1:String) : String
  104.       {
  105.          var _loc2_:String = null;
  106.          var _loc3_:Array = null;
  107.          _loc2_ = !!this.iPlayer ? this.iPlayer.iName : "";
  108.          this.iCache.DeleteCategoryItem(catPlayers,param1);
  109.          if(param1 == _loc2_)
  110.          {
  111.             _loc3_ = this.iCache.GetCategoryNames(catPlayers);
  112.             if(!_loc3_)
  113.             {
  114.                this.iPlayer = null;
  115.                return null;
  116.             }
  117.             this.iPlayer = this.iCache.GetCategoryItem(catPlayers,_loc3_[0]);
  118.             this.iCache.SetCategoryItem(catGlobal,strg╨íurPlayer,_loc3_[0]);
  119.          }
  120.          return !!this.iPlayer ? this.iPlayer.iName : null;
  121.       }
  122.       
  123.       public function get prPlayerNames() : Array
  124.       {
  125.          return this.iCache.GetCategoryNames(catPlayers);
  126.       }
  127.       
  128.       public function ClearPersonalScores(param1:int) : void
  129.       {
  130.          this.iPlayer.iScoreTable.Clear(param1);
  131.       }
  132.       
  133.       public function GetPersonalRecord(param1:int) : int
  134.       {
  135.          return this.iPlayer.iScoreTable.GetRecord(param1);
  136.       }
  137.       
  138.       public function InitAfterLoadCache() : void
  139.       {
  140.       }
  141.       
  142.       public function AddScore(param1:int) : void
  143.       {
  144.          this.iPlayer.iGParams[this.iPlayer.iMode].iScore += param1;
  145.       }
  146.       
  147.       public function get prPlayersData() : *
  148.       {
  149.          var _loc1_:OCache = null;
  150.          var _loc2_:ByteArray = null;
  151.          _loc1_ = this.iCache.GetItem(catPlayers);
  152.          _loc2_ = _loc1_.Pack();
  153.          _loc2_.uncompress();
  154.          return _loc2_.readObject();
  155.       }
  156.       
  157.       public function IsPersonalRecord(param1:int, param2:int) : Boolean
  158.       {
  159.          return this.iPlayer.iScoreTable.IsRecord(param1,param2);
  160.       }
  161.       
  162.       public function LoadCache() : void
  163.       {
  164.          var so:SharedObject = null;
  165.          var a:ByteArray = null;
  166.          so = SharedObject.getLocal(OGlobal.AppName);
  167.          if(so.data.iData == undefined)
  168.          {
  169.             this.iCache = new OCache();
  170.          }
  171.          else
  172.          {
  173.             try
  174.             {
  175.                a = so.data.iData;
  176.                a.uncompress();
  177.                this.iCache = a.readObject();
  178.             }
  179.             catch(error:Error)
  180.             {
  181.                this.iCache = new OCache();
  182.             }
  183.          }
  184.          so.close();
  185.       }
  186.       
  187.       public function NewGame() : void
  188.       {
  189.          this.iPlayer.iGParams[this.iPlayer.iMode].iLevel = 0;
  190.          this.iPlayer.iGParams[this.iPlayer.iMode].iScore = 0;
  191.          this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore = 0;
  192.          this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame = null;
  193.          ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
  194.       }
  195.       
  196.       public function get prLevel() : int
  197.       {
  198.          return this.iPlayer.iGParams[this.iPlayer.iMode].iLevel;
  199.       }
  200.       
  201.       public function get prSoundVolume() : Number
  202.       {
  203.          return this.iCache.GetCategoryItem(catGlobal,strgSoundVolume);
  204.       }
  205.       
  206.       public function get prPlayerName() : String
  207.       {
  208.          return !!this.iPlayer ? this.iPlayer.iName : "";
  209.       }
  210.       
  211.       public function get prScore() : int
  212.       {
  213.          return this.iPlayer.iGParams[this.iPlayer.iMode].iScore;
  214.       }
  215.       
  216.       public function NextLevel() : Boolean
  217.       {
  218.          ++this.iPlayer.iGParams[this.iPlayer.iMode].iLevel;
  219.          return true;
  220.       }
  221.       
  222.       public function set prPlayersData(param1:*) : void
  223.       {
  224.          this.iCache.SetItem(catPlayers,param1);
  225.       }
  226.       
  227.       public function Read(param1:String, param2:String) : *
  228.       {
  229.          return this.iCache.GetCategoryItem(param1,param2);
  230.       }
  231.       
  232.       public function get prSavedGame() : String
  233.       {
  234.          return this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame;
  235.       }
  236.       
  237.       public function set prResX(param1:int) : void
  238.       {
  239.          this.iCache.SetCategoryItem(catGlobal,strgResX,param1);
  240.       }
  241.       
  242.       public function get prRNDFactor() : int
  243.       {
  244.          return this.iPlayer.iRNDFactor;
  245.       }
  246.       
  247.       public function get prMusicVolume() : Number
  248.       {
  249.          return this.iCache.GetCategoryItem(catGlobal,strgMusicVolume);
  250.       }
  251.       
  252.       public function Write(param1:String, param2:String, param3:*) : void
  253.       {
  254.          this.iCache.SetCategoryItem(param1,param2,param3);
  255.       }
  256.       
  257.       public function Start() : void
  258.       {
  259.          ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesStart;
  260.       }
  261.       
  262.       public function get prPassword() : String
  263.       {
  264.          return !!this.iPlayer.iPassword ? this.iPlayer.iPassword : "";
  265.       }
  266.       
  267.       public function get prMode() : int
  268.       {
  269.          return this.iPlayer.iMode;
  270.       }
  271.       
  272.       public function End() : void
  273.       {
  274.          ++this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesEnd;
  275.       }
  276.       
  277.       public function set prSoundVolume(param1:Number) : void
  278.       {
  279.          OSound.SoundVolume = param1;
  280.          this.iCache.SetCategoryItem(catGlobal,strgSoundVolume,param1);
  281.       }
  282.       
  283.       public function SetLevelScore(param1:int) : void
  284.       {
  285.          this.iPlayer.iGParams[this.iPlayer.iMode].iLevelScore = param1;
  286.       }
  287.       
  288.       public function GetLocalScores(param1:int, param2:int) : OScoreParams
  289.       {
  290.          return this.iScores.GetScore(param1,param2);
  291.       }
  292.       
  293.       public function GetPersonalScores(param1:int, param2:int) : OScoreParams
  294.       {
  295.          return this.iPlayer.iScoreTable.GetScore(param1,param2);
  296.       }
  297.       
  298.       public function AddScoreInTable(param1:int) : Boolean
  299.       {
  300.          var _loc2_:Boolean = false;
  301.          _loc2_ = false;
  302.          if(this.iScores.AddScore(this.prPlayerName,param1,this.prMode,this.prLevel))
  303.          {
  304.             this.iCache.SetCategoryItem(OGame.catGlobal,OGame.strgLocalScores,this.iScores);
  305.             _loc2_ = true;
  306.          }
  307.          if(this.iPlayer.iScoreTable.AddScore(this.prPlayerName,param1,this.prMode,this.prLevel,true))
  308.          {
  309.             this.iCache.SetCategoryItem(OGame.catPlayers,this.prPlayerName,this.iPlayer);
  310.             _loc2_ = true;
  311.          }
  312.          return _loc2_;
  313.       }
  314.       
  315.       public function get prResX() : int
  316.       {
  317.          return this.iCache.GetCategoryItem(catGlobal,strgResX);
  318.       }
  319.       
  320.       public function get prResY() : int
  321.       {
  322.          return this.iCache.GetCategoryItem(catGlobal,strgResY);
  323.       }
  324.       
  325.       public function set prPlayerName(param1:String) : void
  326.       {
  327.          var _loc2_:OPlayer = null;
  328.          _loc2_ = this.iCache.GetCategoryItem(catPlayers,param1);
  329.          if(!_loc2_)
  330.          {
  331.             _loc2_ = new OPlayer(param1,"",this.iModes,this.iSTableSize);
  332.             this.iCache.SetCategoryItem(catPlayers,param1,_loc2_);
  333.          }
  334.          this.iPlayer = _loc2_;
  335.          this.iCache.SetCategoryItem(catGlobal,strg╨íurPlayer,param1);
  336.       }
  337.       
  338.       public function DefaultInitLocalScores() : void
  339.       {
  340.          this.iScores.Clear(0);
  341.          this.iScores.AddScore("Emily",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
  342.          this.iScores.AddScore("Michael",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
  343.          this.iScores.AddScore("Jacob",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
  344.          this.iScores.AddScore("Isabella",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
  345.          this.iScores.AddScore("Madison",int(Math.random() * 100 + 50) * 50,0,int(Math.random() * 5 + 3));
  346.          this.iScores.SortOn(0);
  347.       }
  348.       
  349.       public function SaveCache() : Boolean
  350.       {
  351.          var _loc1_:SharedObject = null;
  352.          var _loc2_:String = null;
  353.          _loc1_ = SharedObject.getLocal(OGlobal.AppName);
  354.          _loc1_.data.iData = this.iCache.Pack();
  355.          _loc2_ = _loc1_.flush();
  356.          _loc1_.close();
  357.          return _loc2_ == SharedObjectFlushStatus.FLUSHED;
  358.       }
  359.       
  360.       public function set prResY(param1:int) : void
  361.       {
  362.          this.iCache.SetCategoryItem(catGlobal,strgResY,param1);
  363.       }
  364.       
  365.       public function SetSaveGame(param1:String) : void
  366.       {
  367.          this.iPlayer.iGParams[this.iPlayer.iMode].iSavedGame = param1;
  368.       }
  369.       
  370.       public function get prGamesEndCount() : int
  371.       {
  372.          return this.iPlayer.iGParams[this.iPlayer.iMode].iCGamesEnd;
  373.       }
  374.       
  375.       public function set prMusicVolume(param1:Number) : void
  376.       {
  377.          OSound.MusicVolume = param1;
  378.          this.iCache.SetCategoryItem(catGlobal,strgMusicVolume,param1);
  379.       }
  380.       
  381.       public function get prFullScreen() : Boolean
  382.       {
  383.          return this.iCache.GetCategoryItem(catGlobal,strgFullScreen);
  384.       }
  385.       
  386.       public function ClearLocalScores(param1:int) : void
  387.       {
  388.          this.iScores.Clear(param1);
  389.       }
  390.    }
  391. }
  392.