home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / RES / WINDOWS / OWGame.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  10.0 KB  |  336 lines

  1. package RES.WINDOWS
  2. {
  3.    import ENGINE.CORE.OGlobal;
  4.    import ENGINE.CORE.OSound;
  5.    import ENGINE.DISPLAY.OBitmap;
  6.    import ENGINE.DISPLAY.ODisplay;
  7.    import ENGINE.GAME.OGame;
  8.    import ENGINE.INTERFACE.OButton;
  9.    import ENGINE.INTERFACE.OCounter;
  10.    import ENGINE.INTERFACE.ODialog;
  11.    import ENGINE.INTERFACE.OIObject;
  12.    import ENGINE.INTERFACE.OWindow;
  13.    import RES.OBJECTS.OBang;
  14.    import RES.OBJECTS.OBubble;
  15.    import RES.OBJECTS.OField;
  16.    import flash.events.Event;
  17.    import flash.utils.getTimer;
  18.    
  19.    public class OWGame extends OWindow
  20.    {
  21.       
  22.       public static const stInitGraphics:int = 0;
  23.       
  24.       public static const stNormal:int = 4;
  25.       
  26.       public static const stLevelComplete:int = 6;
  27.       
  28.       public static const stBGameOver:int = 7;
  29.       
  30.       public static const stLevelInfo:int = 2;
  31.       
  32.       public static const stLevelInit:int = 3;
  33.       
  34.       public static const stGameOver:int = 8;
  35.       
  36.       public static const stBLevelComplete:int = 5;
  37.       
  38.       public static const stLoadLevel:int = 1;
  39.        
  40.       
  41.       public var iLevelC:OCounter;
  42.       
  43.       private var iNewGame:Boolean;
  44.       
  45.       private var iDAlpha:Number = 0.025;
  46.       
  47.       private var iField:OField;
  48.       
  49.       private var iBang:OBang;
  50.       
  51.       private var iTimer:int;
  52.       
  53.       public var iMenu:OButton;
  54.       
  55.       public var iScore:OCounter;
  56.       
  57.       public var iLevel:OIObject;
  58.       
  59.       private var iInfo:OIObject;
  60.       
  61.       private var iBangInd:int;
  62.       
  63.       public function OWGame(param1:OBang, param2:int, param3:Boolean)
  64.       {
  65.          iDAlpha = 0.025;
  66.          this.iBang = param1;
  67.          this.iBangInd = param2;
  68.          this.iNewGame = param3;
  69.          super(ClusterzL.OWGame,ODialog.iDefAnimators);
  70.       }
  71.       
  72.       private function InitMaker() : Array
  73.       {
  74.          var _loc1_:Array = null;
  75.          var _loc2_:int = 0;
  76.          var _loc3_:int = 0;
  77.          var _loc4_:int = 0;
  78.          _loc1_ = new Array();
  79.          _loc4_ = 0;
  80.          _loc2_ = 4;
  81.          while(_loc2_ <= 15)
  82.          {
  83.             _loc3_ = 0;
  84.             while(_loc3_ < 6)
  85.             {
  86.                _loc1_.push([OBubble.MakeBubble,_loc2_ * 0.97,_loc2_ / 91 * 3,_loc3_,"Bubble",_loc4_,true]);
  87.                _loc4_++;
  88.                _loc3_++;
  89.             }
  90.             _loc2_++;
  91.          }
  92.          _loc4_ = 0;
  93.          _loc2_ = 4;
  94.          while(_loc2_ <= 15)
  95.          {
  96.             _loc3_ = 0;
  97.             while(_loc3_ < 6)
  98.             {
  99.                _loc1_.push([OBubble.MakeShadow,_loc2_,_loc2_ / 91 * 3,_loc3_,"Shadow",_loc4_,true]);
  100.                _loc4_++;
  101.                _loc3_++;
  102.             }
  103.             _loc2_++;
  104.          }
  105.          return _loc1_;
  106.       }
  107.       
  108.       override public function Init() : void
  109.       {
  110.          var _loc1_:OBitmap = null;
  111.          var _loc2_:int = 0;
  112.          super.Init();
  113.          _loc1_ = ODisplay.OBitmapRoundBorder([null,485 + 30,544,40,8,"GEL","120,0.5,0.5,150,0.2,1.0","border",1,OGlobal.ScaleFloor(10),OGlobal.ScaleFloor(10)]);
  114.          this.addChild(_loc1_);
  115.          _loc2_ = getTimer();
  116.          this.iField = new OField(15,20,20,this.iScore,this.iBang,_loc2_,null);
  117.          this.addChild(this.iField);
  118.          this.addChild(this.iBang);
  119.          this.State = stInitGraphics;
  120.       }
  121.       
  122.       private function VisibleElements(param1:Boolean) : void
  123.       {
  124.          if(param1)
  125.          {
  126.             if(!this.iLevel.prVisible)
  127.             {
  128.                this.iLevel.prVisible = true;
  129.             }
  130.             if(!this.iLevelC.prVisible)
  131.             {
  132.                this.iLevelC.prVisible = true;
  133.             }
  134.             if(!this.iScore.prVisible)
  135.             {
  136.                this.iScore.prVisible = true;
  137.             }
  138.          }
  139.          else
  140.          {
  141.             this.iLevel.prVisible = false;
  142.             this.iLevelC.prVisible = false;
  143.             this.iScore.prVisible = false;
  144.          }
  145.       }
  146.       
  147.       override public function OnPress(param1:Event, param2:*) : void
  148.       {
  149.          if(param2 == this.iMenu)
  150.          {
  151.             this.parent.addChildAt(this.iBang,this.iBangInd);
  152.             this.prVisible = false;
  153.             return;
  154.          }
  155.       }
  156.       
  157.       public function SplashInfoMessage() : Boolean
  158.       {
  159.          var _loc1_:Boolean = false;
  160.          _loc1_ = false;
  161.          if(this.iInfo.prAnimation)
  162.          {
  163.             return false;
  164.          }
  165.          this.iInfo.alpha += this.iDAlpha;
  166.          if(this.iDAlpha > 0 && this.iInfo.alpha >= 1)
  167.          {
  168.             this.iInfo.alpha = 1;
  169.             this.iDAlpha *= -1;
  170.          }
  171.          if(this.iDAlpha < 0 && this.iInfo.alpha <= 0)
  172.          {
  173.             this.iInfo.alpha = 0;
  174.             this.iDAlpha *= -1;
  175.             _loc1_ = true;
  176.          }
  177.          return _loc1_;
  178.       }
  179.       
  180.       override public function Free() : void
  181.       {
  182.          this.iLevel = null;
  183.          this.iLevelC = null;
  184.          this.iScore = null;
  185.          this.iMenu = null;
  186.          this.iField = null;
  187.          super.Free();
  188.       }
  189.       
  190.       private function AddInfo(param1:OIObject, param2:Boolean = true) : void
  191.       {
  192.          if(this.iInfo)
  193.          {
  194.             this.removeChild(this.iInfo);
  195.             this.iInfo.Free();
  196.             this.iInfo = null;
  197.          }
  198.          if(param1)
  199.          {
  200.             this.iInfo = param1;
  201.             this.iInfo.Pos(0,0);
  202.             this.iInfo.Pos(10 + (520 - this.iInfo.prWidth) / 2,300 - this.iInfo.prHeight / 2);
  203.             if(param2)
  204.             {
  205.                this.iInfo.SetVisible(false);
  206.                this.iInfo.prVisible = true;
  207.             }
  208.             this.addChild(this.iInfo);
  209.          }
  210.       }
  211.       
  212.       override public function OnEnterFrame(param1:Event) : void
  213.       {
  214.          var _loc2_:int = 0;
  215.          var _loc3_:int = 0;
  216.          super.OnEnterFrame(param1);
  217.          switch(this.iState)
  218.          {
  219.             case stInitGraphics:
  220.                if(!this.prAnimation)
  221.                {
  222.                   this.State = stLoadLevel;
  223.                }
  224.                break;
  225.             case stLoadLevel:
  226.                _loc2_ = getTimer() - this.iTimer;
  227.                if(_loc2_ > 70)
  228.                {
  229.                   this.State = stLevelInfo;
  230.                }
  231.                break;
  232.             case stLevelInfo:
  233.                _loc2_ = getTimer();
  234.                if(_loc2_ - this.iTimer > 2000)
  235.                {
  236.                   if(this.iInfo.prVisible)
  237.                   {
  238.                      this.iInfo.prVisible = false;
  239.                   }
  240.                   else if(!this.iInfo.prAnimation)
  241.                   {
  242.                      this.AddInfo(null);
  243.                      this.State = stLevelInit;
  244.                   }
  245.                }
  246.                break;
  247.             case stLevelInit:
  248.                if(this.iField.State == OField.stNormal)
  249.                {
  250.                   this.VisibleElements(true);
  251.                   this.State = stNormal;
  252.                }
  253.                break;
  254.             case stNormal:
  255.                _loc3_ = 0;
  256.                switch(this.iField.State)
  257.                {
  258.                   case OField.stLevelCompShow:
  259.                      break;
  260.                   case OField.stLevelComplete:
  261.                      this.State = stBLevelComplete;
  262.                      this.VisibleElements(false);
  263.                      break;
  264.                   case OField.stGameOver:
  265.                      this.State = stBGameOver;
  266.                      this.VisibleElements(false);
  267.                }
  268.                break;
  269.             case stBLevelComplete:
  270.                this.State = stLevelComplete;
  271.                break;
  272.             case stLevelComplete:
  273.                if(!this.iInfo.prVisible && !this.iInfo.prAnimation)
  274.                {
  275.                   this.AddInfo(null);
  276.                   this.State = stLoadLevel;
  277.                }
  278.                break;
  279.             case stBGameOver:
  280.                this.State = stGameOver;
  281.                break;
  282.             case stGameOver:
  283.                if(!this.iInfo.prVisible && !this.iInfo.prAnimation)
  284.                {
  285.                   this.AddInfo(null);
  286.                   this.State = stLoadLevel;
  287.                }
  288.          }
  289.       }
  290.       
  291.       override public function set State(param1:int) : void
  292.       {
  293.          this.iState = param1;
  294.          switch(this.iState)
  295.          {
  296.             case stInitGraphics:
  297.                this.VisibleElements(false);
  298.                break;
  299.             case stLoadLevel:
  300.                this.iTimer = getTimer();
  301.                ClusterzL.iMP.ClearOpponentTurn(true);
  302.                ClusterzL.iMP.Turn(["rdl",ClusterzL.iGAME.prLevel,this.iField.prGameIndex,ClusterzL.iGAME.prPlayerName]);
  303.                break;
  304.             case stLevelInfo:
  305.                OSound.PlaySoundInd(1);
  306.                this.iLevelC.prValue = ClusterzL.iGAME.prLevel + 1;
  307.                ClusterzL.OWGameNewLevel[3] = ClusterzL.strLevel + " - " + (ClusterzL.iGAME.prLevel + 1).toString();
  308.                this.AddInfo(ClusterzS.ColorText(ClusterzL.OWGameNewLevel),true);
  309.                this.iTimer = getTimer();
  310.                break;
  311.             case stLevelInit:
  312.                this.iField.NewLevel(ClusterzL.iGAME.prLevel);
  313.                break;
  314.             case stBLevelComplete:
  315.                this.State = stLevelComplete;
  316.                break;
  317.             case stLevelComplete:
  318.                ClusterzL.iGAME.Write(OGame.catTmp,"Score",this.iScore.prValue);
  319.                ClusterzL.iGAME.NextLevel();
  320.                this.iInfo = new OWResults(false);
  321.                this.iInfo.Pos(0,0);
  322.                this.addChild(iInfo);
  323.                break;
  324.             case stBGameOver:
  325.                this.State = stGameOver;
  326.                break;
  327.             case stGameOver:
  328.                ClusterzL.iGAME.Write(OGame.catTmp,"Score",0);
  329.                this.iInfo = new OWResults(true);
  330.                this.iInfo.Pos(0,0);
  331.                this.addChild(iInfo);
  332.          }
  333.       }
  334.    }
  335. }
  336.