home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / DSS145 / DSS145_10 / DSS145_10.swf / scripts / dss145_10 / AttenteJeu.as next >
Text File  |  2012-07-18  |  17KB  |  484 lines

  1. package dss145_10
  2. {
  3.    import com.milanpresse.engineaddons.facades.EngineExt;
  4.    import com.milanpresse.engineaddons.initdisplayobject.ExtendedClip;
  5.    import com.milanpresse.engineaddons.labelstypes.AttenteLabel;
  6.    import com.milanpresse.tools.*;
  7.    import flash.display.DisplayObjectContainer;
  8.    import flash.display.MovieClip;
  9.    import flash.events.Event;
  10.    import flash.events.MouseEvent;
  11.    import flash.geom.Point;
  12.    import flash.geom.Rectangle;
  13.    
  14.    public class AttenteJeu extends AttenteLabel
  15.    {
  16.        
  17.       
  18.       public var config:AttenteJeuConfig;
  19.       
  20.       public var CONTAINER:DisplayObjectContainer;
  21.       
  22.       public var mainAlgo:CapsuleAlgo;
  23.       
  24.       public var BT_REJOUER:ExtendedClip;
  25.       
  26.       public var BT_AIDE:ExtendedClip;
  27.       
  28.       public var CLIP_AIDE:ExtendedClip;
  29.       
  30.       public var GERYON:ExtendedClip;
  31.       
  32.       public var HERAKLES:ExtendedClip;
  33.       
  34.       public var BT_FLECHE_DO:ExtendedClip;
  35.       
  36.       public var BT_FLECHE_UP:ExtendedClip;
  37.       
  38.       public var JAUGE:ExtendedClip;
  39.       
  40.       public var BLOC_QUESTIONS:ExtendedClip;
  41.       
  42.       public var BLOC_QUESTIONS_DRAG:ExtendedClip;
  43.       
  44.       public var CURSEUR:Cursor;
  45.       
  46.       private var _questionsJeuManager:Questions;
  47.       
  48.       private var _questionOriginalList:Vector.<Question>;
  49.       
  50.       private var jaugeValue:Number = 0;
  51.       
  52.       private var GeryonTouche:Boolean = false;
  53.       
  54.       private var _temp_point:Point;
  55.       
  56.       private var _zoneLimit:Rectangle;
  57.       
  58.       public function AttenteJeu(param1:EngineExt, param2:Function = null)
  59.       {
  60.          this.config = new AttenteJeuConfig();
  61.          this._questionOriginalList = new Vector.<Question>();
  62.          this._temp_point = new Point();
  63.          this._zoneLimit = new Rectangle(0,0,800,600);
  64.          super(param1,param2);
  65.       }
  66.       
  67.       public function init() : void
  68.       {
  69.          this.CONTAINER = this.config.CONTAINER;
  70.          this.CLIP_AIDE_Init();
  71.          this.BT_REJOUER_Init();
  72.          this.BT_AIDE_Init();
  73.          this.GERYON_Init();
  74.          this.HERAKLES_Init();
  75.          this.BT_FLECHE_DO_Init();
  76.          this.BT_FLECHE_UP_Init();
  77.          this.JAUGE_Init();
  78.          this.jaugeChange(0);
  79.          this.createQuestionsListe();
  80.          this._questionsJeuManager.melanger();
  81.          this._questionsJeuManager.next();
  82.          this.BLOC_QUESTION_Init();
  83.       }
  84.       
  85.       private function CLIP_AIDE_Init() : void
  86.       {
  87.          var clip:ExtendedClip = this.CLIP_AIDE = new ExtendedClip(this.config.CLIP_AIDE as MovieClip,_e);
  88.          clip.onPress = function():void
  89.          {
  90.             CLIP_AIDE.visible = false;
  91.             _e.commentStop();
  92.          };
  93.          clip.enabled = false;
  94.          clip.visible = false;
  95.          clip.init();
  96.       }
  97.       
  98.       private function BT_REJOUER_Init() : void
  99.       {
  100.          var clip:ExtendedClip = this.BT_REJOUER = new ExtendedClip(this.config.BT_REJOUER as MovieClip,_e);
  101.          clip.onPressState = {"label":"E1"};
  102.          clip.onRollOverState = {
  103.             "label":"E2",
  104.             "noiseCode":"B_REJ"
  105.          };
  106.          clip.onRollOutState = {"label":"E1"};
  107.          clip.onPress = function():void
  108.          {
  109.             rejouer();
  110.          };
  111.          clip.enabled = false;
  112.          clip.visible = false;
  113.          clip.init();
  114.       }
  115.       
  116.       private function BT_AIDE_Init() : void
  117.       {
  118.          var clip:ExtendedClip = this.BT_AIDE = new ExtendedClip(this.config.BT_AIDE as MovieClip,_e);
  119.          clip.onPressState = {"label":"E1"};
  120.          clip.onRollOverState = {
  121.             "label":"E2",
  122.             "noiseCode":"B_AIDE"
  123.          };
  124.          clip.onRollOutState = {"label":"E1"};
  125.          clip.onPress = function():void
  126.          {
  127.             CLIP_AIDE.visible = true;
  128.             CLIP_AIDE.enabled = true;
  129.             _e.commentPlay({
  130.                "code":"AIDE",
  131.                "zapBlock":"NOZAP_NOBLOCK"
  132.             });
  133.          };
  134.          clip.enabled = true;
  135.          clip.init();
  136.       }
  137.       
  138.       private function BT_FLECHE_DO_Init() : void
  139.       {
  140.          var clip:ExtendedClip = this.BT_FLECHE_DO = new ExtendedClip(this.config.BT_FLECHE_DO as MovieClip,_e);
  141.          clip.onPressState = {"label":"E1"};
  142.          clip.onRollOverState = {
  143.             "label":"E2",
  144.             "noiseCode":"B_FLECHE"
  145.          };
  146.          clip.onRollOutState = {"label":"E1"};
  147.          clip.onPress = function():void
  148.          {
  149.             _questionsJeuManager.next();
  150.             BLOC_QUESTION_Refresh();
  151.          };
  152.          clip.enabled = true;
  153.          clip.init();
  154.       }
  155.       
  156.       private function BT_FLECHE_UP_Init() : void
  157.       {
  158.          var clip:ExtendedClip = this.BT_FLECHE_UP = new ExtendedClip(this.config.BT_FLECHE_UP as MovieClip,_e);
  159.          clip.onPressState = {"label":"E1"};
  160.          clip.onRollOverState = {
  161.             "label":"E2",
  162.             "noiseCode":"B_FLECHE"
  163.          };
  164.          clip.onRollOutState = {"label":"E1"};
  165.          clip.onPress = function():void
  166.          {
  167.             _questionsJeuManager.previous();
  168.             BLOC_QUESTION_Refresh();
  169.          };
  170.          clip.enabled = true;
  171.          clip.init();
  172.       }
  173.       
  174.       private function GERYON_Init() : void
  175.       {
  176.          var _loc1_:ExtendedClip = this.GERYON = new ExtendedClip(this.config.GERYON as MovieClip,_e);
  177.          _loc1_.init();
  178.       }
  179.       
  180.       private function HERAKLES_Init() : void
  181.       {
  182.          var _loc1_:ExtendedClip = this.HERAKLES = new ExtendedClip(this.config.HERAKLES as MovieClip,_e);
  183.          _loc1_.init();
  184.       }
  185.       
  186.       private function JAUGE_Init() : void
  187.       {
  188.          var _loc1_:ExtendedClip = this.JAUGE = new ExtendedClip(this.config.JAUGE as MovieClip,_e);
  189.          _loc1_.init();
  190.       }
  191.       
  192.       private function jaugeChange(param1:Number) : void
  193.       {
  194.          this.jaugeValue += param1;
  195.          if(this.jaugeValue > 100)
  196.          {
  197.             this.jaugeValue = 100;
  198.          }
  199.          if(this.jaugeValue < 0)
  200.          {
  201.             this.jaugeValue = 0;
  202.          }
  203.          this.JAUGE.gotoAndStop(this.jaugeValue);
  204.       }
  205.       
  206.       private function BLOC_QUESTION_Init() : void
  207.       {
  208.          this.BLOC_QUESTIONS = new ExtendedClip(this.config.BLOC_QUESTIONS as MovieClip,_e);
  209.          this.BLOC_QUESTIONS.modelText = this.BLOC_QUESTIONS.getChildByName("TEXT");
  210.          this.BLOC_QUESTIONS.onPressState = {"label":"E1"};
  211.          this.BLOC_QUESTIONS.onRollOverState = {
  212.             "label":"E1",
  213.             "noiseCode":"B_FLECHE"
  214.          };
  215.          this.BLOC_QUESTIONS.onRollOutState = {"label":"E1"};
  216.          this.BLOC_QUESTIONS.onPress = function():void
  217.          {
  218.             BLOC_QUESTIONS.visible = false;
  219.             BT_FLECHE_DO.visible = false;
  220.             BT_FLECHE_UP.visible = false;
  221.             CURSEUR.lock = true;
  222.             CURSEUR.cursor = "mainF";
  223.             BLOC_QUESTIONS_DRAG.TEXTBLOC.text = _questionsJeuManager.question.text;
  224.             BLOC_QUESTIONS_DRAG.TEXTBLOC.x = BLOC_QUESTIONS_DRAG.modelText.x + BLOC_QUESTIONS_DRAG.modelText.width / 2 - BLOC_QUESTIONS_DRAG.TEXTBLOC.width / 2;
  225.             BLOC_QUESTIONS.TEXTBLOC.y = BLOC_QUESTIONS_DRAG.modelText.y + BLOC_QUESTIONS_DRAG.modelText.height / 2 - BLOC_QUESTIONS_DRAG.TEXTBLOC.height / 2;
  226.             BLOC_QUESTIONS_DRAG.width = BLOC_QUESTIONS.width;
  227.             BLOC_QUESTIONS_DRAG.height = BLOC_QUESTIONS.height;
  228.             BLOC_QUESTIONS_DRAG.x = CONTAINER.mouseX;
  229.             BLOC_QUESTIONS_DRAG.y = CONTAINER.mouseY;
  230.             CONTAINER.stage.addEventListener(Event.ENTER_FRAME,onDrag);
  231.             CONTAINER.stage.addEventListener(MouseEvent.MOUSE_UP,stopDrag);
  232.             BLOC_QUESTIONS_DRAG.addToParent(CONTAINER);
  233.             BLOC_QUESTIONS_DRAG.visible = true;
  234.          };
  235.          this.BLOC_QUESTIONS.onRollOver = function():void
  236.          {
  237.             CURSEUR.cursor = "mainO";
  238.          };
  239.          this.BLOC_QUESTIONS.onRollOut = function():void
  240.          {
  241.             CURSEUR.cursor = "fleche";
  242.          };
  243.          this.BLOC_QUESTIONS.enabled = true;
  244.          this.BLOC_QUESTIONS.init();
  245.          this.BLOC_QUESTIONS.TEXTBLOC = _e.textShow({
  246.             "id":this._questionsJeuManager.question.idLM,
  247.             "model":this.BLOC_QUESTIONS.modelText,
  248.             "idStyle":"LM.LM_Q"
  249.          });
  250.          this.BLOC_QUESTION_Refresh();
  251.          this.BLOC_QUESTIONS_DRAG = new ExtendedClip(this.config.BLOC_QUESTIONS_DRAG as MovieClip,_e);
  252.          this.BLOC_QUESTIONS_DRAG.modelText = this.BLOC_QUESTIONS_DRAG.getChildByName("TEXT");
  253.          this.BLOC_QUESTIONS_DRAG.init();
  254.          this.BLOC_QUESTIONS_DRAG.visible = false;
  255.          this.BLOC_QUESTIONS_DRAG.TEXTBLOC = _e.textShow({
  256.             "id":this._questionsJeuManager.question.idLM,
  257.             "model":this.BLOC_QUESTIONS_DRAG.modelText,
  258.             "idStyle":"LM.LM_Q"
  259.          });
  260.       }
  261.       
  262.       private function BLOC_QUESTION_Refresh() : void
  263.       {
  264.          this.BLOC_QUESTIONS.TEXTBLOC.text = this._questionsJeuManager.question.text;
  265.          this.BLOC_QUESTIONS.TEXTBLOC.x = this.BLOC_QUESTIONS.modelText.x + this.BLOC_QUESTIONS.modelText.width / 2 - this.BLOC_QUESTIONS.TEXTBLOC.width / 2;
  266.          this.BLOC_QUESTIONS.TEXTBLOC.y = this.BLOC_QUESTIONS.modelText.y + this.BLOC_QUESTIONS.modelText.height / 2 - this.BLOC_QUESTIONS.TEXTBLOC.height / 2;
  267.       }
  268.       
  269.       private function createQuestionsListe() : void
  270.       {
  271.          var xmllist:XMLList = null;
  272.          var question:Question = null;
  273.          var node:XML = null;
  274.          this._questionsJeuManager = new Questions();
  275.          var questions:Vector.<Question> = new Vector.<Question>();
  276.          var i:int = 1;
  277.          while(i <= 20)
  278.          {
  279.             xmllist = _e.config.XmlConfig.Module[_e.config.lang].LegendesMedias.*.(hasOwnProperty("@id") && @id.search("LM_Q_" + GlobalesFunctions.gimme2digits(i)) != -1);
  280.             if(xmllist.length() <= 0)
  281.             {
  282.                break;
  283.             }
  284.             node = xmllist[0];
  285.             question = new Question();
  286.             question.no = i;
  287.             question.idLM = node.@id;
  288.             question.text = node.toString();
  289.             question.enerve = i <= 10 ? true : false;
  290.             this._questionsJeuManager.addQuestion(question);
  291.             i++;
  292.          }
  293.          this._questionOriginalList = this._questionsJeuManager.questions.slice();
  294.       }
  295.       
  296.       private function onDrag(param1:Event) : void
  297.       {
  298.          this.CURSEUR.cursor = "mainF";
  299.          this._temp_point.x = this.CONTAINER.mouseX;
  300.          this._temp_point.y = this.CONTAINER.mouseY;
  301.          if(this._temp_point.x < this._zoneLimit.x + this.BLOC_QUESTIONS_DRAG.width / 2)
  302.          {
  303.             this._temp_point.x = this._zoneLimit.x + this.BLOC_QUESTIONS_DRAG.width / 2;
  304.          }
  305.          if(this._temp_point.x > this._zoneLimit.x + this._zoneLimit.width - this.BLOC_QUESTIONS_DRAG.width / 2)
  306.          {
  307.             this._temp_point.x = this._zoneLimit.x + this._zoneLimit.width - this.BLOC_QUESTIONS_DRAG.width / 2;
  308.          }
  309.          if(this._temp_point.y < this._zoneLimit.y + this.BLOC_QUESTIONS_DRAG.height / 2)
  310.          {
  311.             this._temp_point.y = this._zoneLimit.y + this.BLOC_QUESTIONS_DRAG.height / 2;
  312.          }
  313.          if(this._temp_point.y > this._zoneLimit.y + this._zoneLimit.height - this.BLOC_QUESTIONS_DRAG.height / 2)
  314.          {
  315.             this._temp_point.y = this._zoneLimit.y + this._zoneLimit.height - this.BLOC_QUESTIONS_DRAG.height / 2;
  316.          }
  317.          this.BLOC_QUESTIONS_DRAG.x = this.CURSEUR.x = this._temp_point.x;
  318.          this.BLOC_QUESTIONS_DRAG.y = this.CURSEUR.y = this._temp_point.y;
  319.          this.GeryonTouche = !!this.GERYON.hitTestPoint(this.CONTAINER.stage.mouseX,this.CONTAINER.stage.mouseY,true) ? true : false;
  320.       }
  321.       
  322.       private function stopDrag(param1:Event) : void
  323.       {
  324.          this.CURSEUR.lock = false;
  325.          this.CURSEUR.cursor = "fleche";
  326.          this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.onDrag);
  327.          this.CONTAINER.stage.removeEventListener(MouseEvent.MOUSE_UP,this.stopDrag);
  328.          this.BLOC_QUESTIONS_DRAG.removeFromParent(this.CONTAINER);
  329.          if(this.GeryonTouche)
  330.          {
  331.             if(this._questionsJeuManager.question.enerve)
  332.             {
  333.                this.jaugeChange(100 / 5);
  334.                this.commentSuccesA();
  335.             }
  336.             else
  337.             {
  338.                this.jaugeChange(-100 / 5);
  339.                this.commentEchecA();
  340.             }
  341.          }
  342.          else
  343.          {
  344.             _e.noisePlay({"code":"B_BACK"});
  345.             this.BT_FLECHE_DO.visible = true;
  346.             this.BT_FLECHE_UP.visible = true;
  347.             this.BLOC_QUESTIONS.visible = true;
  348.          }
  349.       }
  350.       
  351.       private function commentSuccesA() : void
  352.       {
  353.          this.HERAKLES.gotoAndStop("E3");
  354.          this.GERYON.gotoAndStop("E5");
  355.          _e.commentPlay({
  356.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_A",
  357.             "callback":this.commentSuccesB
  358.          });
  359.       }
  360.       
  361.       private function commentSuccesB() : void
  362.       {
  363.          this.HERAKLES.gotoAndStop("E1");
  364.          this.GERYON.gotoAndStop("E6");
  365.          _e.commentPlay({
  366.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_B",
  367.             "callback":this.commentSuccesC
  368.          });
  369.       }
  370.       
  371.       private function commentSuccesC() : void
  372.       {
  373.          _e.commentPlay({
  374.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_C",
  375.             "callback":this.commentFin
  376.          });
  377.          this.GERYON.gotoAndStop("E7");
  378.          this._questionsJeuManager.removeQuestion(this._questionsJeuManager.question);
  379.       }
  380.       
  381.       private function commentEchecA() : void
  382.       {
  383.          this.GERYON.gotoAndStop("E2");
  384.          this.HERAKLES.gotoAndStop("E2");
  385.          _e.commentPlay({
  386.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_A",
  387.             "callback":this.commentEchecB
  388.          });
  389.       }
  390.       
  391.       private function commentEchecB() : void
  392.       {
  393.          this.GERYON.gotoAndStop("E3");
  394.          this.HERAKLES.gotoAndStop("E1");
  395.          _e.commentPlay({
  396.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_B",
  397.             "callback":this.commentEchecC
  398.          });
  399.       }
  400.       
  401.       private function commentEchecC() : void
  402.       {
  403.          this.GERYON.gotoAndStop("E4");
  404.          _e.commentPlay({
  405.             "code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_C",
  406.             "callback":this.commentFin
  407.          });
  408.       }
  409.       
  410.       private function commentFin() : void
  411.       {
  412.          this.BLOC_QUESTION_Refresh();
  413.          this.GERYON.gotoAndStop("E1");
  414.          this.HERAKLES.gotoAndStop("E1");
  415.          if(this.jaugeValue >= 100)
  416.          {
  417.             this.end();
  418.          }
  419.          else if(this.nbBonnesReponsesRestantes() < (100 - this.jaugeValue) / 20)
  420.          {
  421.             this.echecJeu();
  422.          }
  423.          else
  424.          {
  425.             this.BT_FLECHE_DO.visible = true;
  426.             this.BT_FLECHE_UP.visible = true;
  427.             this.BLOC_QUESTIONS.visible = true;
  428.          }
  429.       }
  430.       
  431.       private function echecJeu() : void
  432.       {
  433.          _e.commentPlay({
  434.             "code":"REJOUER",
  435.             "callback":function():void
  436.             {
  437.                BT_REJOUER.visible = true;
  438.                BT_REJOUER.enabled = true;
  439.                jaugeValue = 0;
  440.                jaugeChange(0);
  441.             }
  442.          });
  443.       }
  444.       
  445.       private function nbBonnesReponsesRestantes() : int
  446.       {
  447.          var _loc1_:int = 0;
  448.          var _loc2_:int = 0;
  449.          while(_loc2_ < this._questionsJeuManager.questions.length)
  450.          {
  451.             if(this._questionsJeuManager.questions[_loc2_].enerve)
  452.             {
  453.                _loc1_++;
  454.             }
  455.             _loc2_++;
  456.          }
  457.          return _loc1_;
  458.       }
  459.       
  460.       private function rejouer() : void
  461.       {
  462.          this.BT_REJOUER.visible = false;
  463.          this._questionsJeuManager.questions = this._questionOriginalList.slice();
  464.          this._questionsJeuManager.index = 0;
  465.          this._questionsJeuManager.melanger();
  466.          this.BLOC_QUESTION_Refresh();
  467.          this.BLOC_QUESTIONS.visible = true;
  468.       }
  469.       
  470.       private function end() : void
  471.       {
  472.          this.destroy();
  473.          _e.instanceToDestroyRemove(this);
  474.          _callbackEnd();
  475.       }
  476.       
  477.       public function destroy() : void
  478.       {
  479.          this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.onDrag);
  480.          this.CONTAINER.stage.removeEventListener(MouseEvent.MOUSE_UP,this.stopDrag);
  481.       }
  482.    }
  483. }
  484.