package { import flash.display.MovieClip; import flash.display.Graphics; import flash.events.MouseEvent; import flash.events.TextEvent; import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; import flash.text.StyleSheet; import fereas; import Fdb; import Contur; import Campie; import flash.text.TextField; import flash.text.TextFormat; import nor; import Oaia; import orange; import rosu; import Soare; import violet; import yellow; import albastru; import backgr; import Autor; import penita; /** * ... * @author Radu */ public class Exercitiu6 { public var trece:Number = 0; private var rut:MovieClip = new MovieClip(); private var Scena:MovieClip = new MovieClip(); private var nr_hint:Number; private var st:StyleSheet = new StyleSheet(); private var pune_fdb:Fdb = new Fdb(); private var lfdb:URLLoader = new URLLoader; private var len:URLLoader = new URLLoader; //private var Norisor:nor = new nor(); private var Sorisor:Soare = new Soare(); private var Back:backgr = new backgr(); private var este_fdb:Number = 0; private var Frosie:rosu = new rosu(); private var Fgalbena:yellow = new yellow(); private var Falbastra:albastru = new albastru(); private var Forange:orange = new orange(); private var Fmov:violet = new violet(); private var Enunt:TextField = new TextField; private var NrVar:Number; private var pen:penita=new penita(); private var fpen:Autor=new Autor(); private var o:Object = new Object(); private var penc:Array = new Array(); private var autor:Array = new Array(); private var l:URLLoader=new URLLoader(); private var cr, penult, ult, xx1, nr, _nr, total_sol, total_var, numaru, gasit:Number=0; private var ok:Number=0; private var yy:Number=250; private var xx:Number=80; private var posibilitati:Array=new Array(); private var variante:Array=new Array(); private var cvnt:Array=new Array(); private var coord:Array=new Array(); private var coordx:Array=new Array(); private var coordy:Array=new Array(); private var ver:Array=new Array(); private var xcoord:Array=new Array; private var ycoord:Array=new Array; private var sol:Array=new Array(); private var cuv:Array = new Array; private var verifica:Number=new Number(); private var gr:Wrong; private var co:Good; private var fstr:TextFormat=new TextFormat(); private var copy, copy1:MovieClip= new MovieClip(); private var ref, ref1:MovieClip= new MovieClip(); private var curent:MovieClip= new MovieClip(); private var enunt_text:Array; private var enunt_text1:Array; private var enunt_text2:Array; private var t, t1:TextField; private var format_t:TextFormat=new TextFormat(); private var format_t1:TextFormat=new TextFormat(); private var i,j,h,cnt:Number=0; private var X, Y, Xprim:Number=0; private var sa_facut_evaluare:Number=0; private var de_cat:Number=1; private var txt:TextField; private var txt1:TextField; public function Exercitiu6 (mc:MovieClip, mc1:MovieClip, nrh:Number) { rut = mc; nr_hint = nrh; Scena = mc1; pun_css(); pun_fdb(); grafica(); o[fpen]=new Object(); fpen.aut_bara_sus.addEventListener (MouseEvent.MOUSE_DOWN, pornejte_pen); fpen.aut_bara_sus.addEventListener (MouseEvent.MOUSE_UP, oprejte_pen); fpen.aut_bara_sus.Inchide.addEventListener (MouseEvent.CLICK, scoate_pen); fpen.aut_bara_sus.Inchide.buttonMode = true; for (i=0; i<15; i++) { coordx[i]=new Array(); coordy[i]=new Array(); ver[i]=new Array(); } for(i=0;i<10;i++) { ver[i]=-1; } coord[0]=0; fstr.font="Verdana"; fstr.size=13; fstr.color=0x000099; format_t.size=13; format_t.font="Verdana"; format_t.color=0x990000; format_t.bold=true; } private function grafica ():void { Back.x = 0; Back.y = 0; Back.height = 499; rut.addChild (Back); //Norisor.x = 436.9; Norisor.y = 63.0; Norisor.width = 185.3; Norisor.height = 65.8; rut.addChild (Norisor); Sorisor.x = 578.0; Sorisor.y = 2.8; Sorisor.width = 118.1; Sorisor.height = 124.6; rut.addChild (Sorisor); var campie:Campie = new Campie(); campie.y = 437.6; campie.x = 0.0; rut.addChild (campie); var oaie:Oaia = new Oaia(); oaie.x = 7; oaie.y = 457.3; oaie.width = 103.8; oaie.height = 135.8; rut.addChild (oaie); var cont:Contur = new Contur(); cont.x = 1.5; cont.y = 436.7; rut.addChild (cont); Frosie.x = 146; Frosie.y = 443; Frosie.width = 19; Frosie.height = 24; Fmov.x = 289; Fmov.y = 463; Fmov.width = 19; Fmov.height = 24; Forange.x = 398; Forange.y = 457; Forange.width = 19; Forange.height = 24; Falbastra.x = 507; Falbastra.y = 448; Falbastra.width = 19; Falbastra.height = 24; Fgalbena.x = 609; Fgalbena.y = 462; Fgalbena.width = 19; Fgalbena.height = 24; Enunt.x = 146; Enunt.y = 504.6; Enunt.width = 516; Enunt.height = 59.1; rut.addChild (Enunt); Enunt.wordWrap=true; Enunt.styleSheet=st; Enunt.addEventListener (TextEvent.LINK, ataseaza); len.load (new URLRequest("exercitiu/enunt/e6.txt")); len.addEventListener(Event.COMPLETE, incarc_enunt); } private function incarc_enunt (e:Event):void { Enunt.htmlText = e.currentTarget.data; } private function ataseaza(e:TextEvent):void { var xe:fereas=new fereas(); xe.bara_sus.Gresit.addEventListener (MouseEvent.CLICK, scoate); rut.addChild (xe); var lx:URLLoader=new URLLoader(); xe.texte.styleSheet=st; xe.texte.autoSize="left"; xe.bara_sus.Titlu_obiective.text=fa_litera_mare(e.text); lx.load (new URLRequest("explicatii/"+e.text+".html")); lx.addEventListener(Event.COMPLETE, incarcx); function incarcx(e:Event):void { xe.texte.text=e.currentTarget.data; xe.Tablou.height=xe.texte.height+30; xe.x=85; xe.y=150; } function scoate (e:MouseEvent):void { rut.removeChild (xe); } } private function fa_litera_mare(cuvant:String):String { var primal:String=cuvant.substr(0, 1); var rest_cuv:String=cuvant.substr(1); return (primal.toUpperCase()+rest_cuv); } public function start_game (vr:Number):void { var alc:MovieClip; NrVar = vr; Frosie.addEventListener(MouseEvent.CLICK, go_hint); Frosie.buttonMode=true; Falbastra.addEventListener(MouseEvent.CLICK, go_hint); Falbastra.buttonMode=true; Forange.addEventListener(MouseEvent.CLICK, go_hint); Forange.buttonMode=true; Fmov.addEventListener(MouseEvent.CLICK, go_hint); Fmov.buttonMode=true; Fgalbena.addEventListener(MouseEvent.CLICK, go_hint); Fgalbena.buttonMode = true; Sorisor.buttonMode = true; Sorisor.addEventListener (MouseEvent.CLICK, go_evaluare); //Norisor.addEventListener (MouseEvent.CLICK, go_reluare); Norisor.buttonMode = true; if (nr_hint>0&&nr_hint>=1) rut.addChild (Frosie); if (nr_hint>0&&nr_hint>=2) rut.addChild (Falbastra); if (nr_hint>0&&nr_hint>=3) rut.addChild (Forange); if (nr_hint>0&&nr_hint>=4) rut.addChild (Fmov); if (nr_hint > 0 && nr_hint >= 5) rut.addChild (Fgalbena); l=new URLLoader(); l.load(new URLRequest ("exercitiu/texte/t6.txt")); l.addEventListener(Event.COMPLETE, incarc_ex); de_cat=1; total_sol=0 yy=20; xx = 35; cr = NrVar; function incarc_ex (e:Event):void { l.removeEventListener (Event.COMPLETE, incarc_ex); if (de_cat==1) { X=35; Y=140; _nr=0; posibilitati=e.currentTarget.data.split("VaRiAnTa"); variante=posibilitati[cr].split("VRT"); for (cnt=0, nr=0; cnt680) { X=20; Y=Y+17; } alc = new MovieClip(); alc.graphics.lineStyle(1,0x000099); alc.graphics.moveTo(0, 0); alc.graphics.lineTo(155, 0); alc.x = X; alc.y = Y+16; rut.addChild (alc); coordx[_nr]=X; coordy[_nr]=Y+15; _nr++; X+=159; } else place_word (txt); } //adaug var for(i=0,h=1;i<_nr;i++,h++) { copy=new MovieClip(); copy.x=xx; copy.y=yy; xcoord[i]=copy.x; ycoord[i]=copy.y; t=new TextField (); t.selectable=false; t.autoSize="left"; t.text=enunt_text1[i]; t.setTextFormat(format_t); copy.name=""+i+""; copy.addEventListener(MouseEvent.MOUSE_DOWN, start_drag); copy.addEventListener(MouseEvent.MOUSE_UP, stop_drag); copy.addChild(t); rut.addChild(copy); xx+=180; if(h==3) { xx=35; yy+=20; h=0; } } } } } } private function go_evaluare (e:MouseEvent):void { var inc:Number = 0; var str:String; if(rut.getChildByName("co.0")!=null) rut.removeChild(rut.getChildByName("co.0")); if(rut.getChildByName("gr.0")!=null) rut.removeChild(rut.getChildByName("gr.0")); for (i=0;i<_nr;i++) { if(ver[i]==-1) { str = "Incomplet!"; incarc_fdb(str); i=_nr; inc=1; } } if(inc==0) { pune_fdb.fdb_bara_sus.removeChild (pune_fdb.fdb_bara_sus.Inchide); Scena.fr.bara_sus.addChild (Scena.fr.bara_sus.Gresit); for (i=0;i<_nr;i++) { if(sol[i]==ver[i]) { verifica+=1; } } for(i=0;i<_nr;i++) { if(MovieClip(rut.getChildByName(""+i+""))!=null) { MovieClip(rut.getChildByName(""+i+"")).removeEventListener(MouseEvent.MOUSE_DOWN, start_drag); MovieClip(rut.getChildByName(""+i+"")).removeEventListener(MouseEvent.MOUSE_UP, stop_drag); } } //verificam daca toate-s corecte if(verifica==_nr) { co=new Good(); co.x=10; co.y=145; co.name="co.0"; rut.addChild(co); } else { gr=new Wrong(); gr.x=10; gr.y=143; gr.name="gr.0"; rut.addChild(gr); } if (verifica >= 5) { str = "

Ai obţinut " + verifica + " puncte din 10.\n"; trece = 1; str = str + "Succes în continuare.\n\n"; } else { str = "

Ai obţinut doar " + verifica + " puncte din 10.\n"; trece = 0; str=str+"Roagă-l pe prietenul tău, care urmează la rând să încerce şi el.\n\n" } str = str + "Închide această fereastră pentru a continua!

"; incarc_fdb(str); verifica = 0; } } /*private function go_reluare (e:MouseEvent):void { }*/ private function go_hint (e:MouseEvent):void { rut.removeChild (MovieClip(e.currentTarget)); ok=0; for (i=0;i<_nr;i++) { if(ver[i]==-1) { trace(sol[i]); curent=MovieClip(rut.getChildByName(""+sol[i]+"")); for(j=0;j<_nr;j++) if(curent.x==coordx[j]+(155/2-curent.width/2) && curent.y==coordy[j]-15) ver[j]=-1; ver[i]=sol[i]; curent.x=coordx[i]+(155/2-curent.width/2); curent.y=coordy[i]-15; curent.removeEventListener(MouseEvent.MOUSE_DOWN, start_drag); curent.removeEventListener(MouseEvent.MOUSE_UP, stop_drag); ok=1; i=_nr; } } if(ok==0) //o rez e gresita { for (i=0;i<_nr;i++) { if(ver[i]!=sol[i]) { curent=MovieClip(rut.getChildByName(""+ver[i]+"")); curent.x=xcoord[ver[i]]; curent.y=ycoord[ver[i]]; ver[i]=-1; trace("ver", ver[i]); i=_nr; } } } } private function start_drag(e:MouseEvent):void { curent=MovieClip(rut.getChildByName(e.currentTarget.name)); e.currentTarget.startDrag(); numaru=curent.name; ok=0; for(i=0;i<_nr;i++) { if(rut.mouseX>=coordx[i] && rut.mouseXcoordy[i]-15) { ok=1; ver[i]=-1; gasit=1; } } gasit=0; } private function stop_drag(e:MouseEvent):void { curent.stopDrag(); for (i=0;i<_nr;i++) { if(rut.mouseX>=coordx[i] && rut.mouseXcoordy[i]-15 && ver[i]==-1) { curent.x=coordx[i]+(155/2-curent.width/2); curent.y=coordy[i]-15; ver[i]=numaru; gasit=1; } } if(gasit==0) { if(ok==1) ok=0; curent.x=xcoord[numaru]; curent.y=ycoord[numaru]; } } private function place_word(TF:TextField):void { var lg:Number=TF.width; TF.selectable=false; if (X+lg>680||TF.text=="NL") { if (TF.text!="NL") X=20; else X=35; Y=Y+17; } if (TF.text!="NL") { TF.x=X; TF.y=Y; rut.addChild (TF); X+=lg+1; } } /*pen*/ private function pornejte_pen(e:MouseEvent):void { fpen.startDrag(); } private function oprejte_pen(e:MouseEvent):void { fpen.stopDrag(); } private function scoate_pen(e:MouseEvent):void { rut.removeChild (fpen); o[fpen].pescena=0; } private function atas (e:MouseEvent):void { var i:Number=0; if(rut.mouseY>penc[1] && rut.mouseYpenc[2] && rut.mouseYpenc[3] && rut.mouseY139) { pune_fdb.Spate.height=lf_fr; pune_fdb.Oaie.y=22+pune_fdb.Spate.height-9.2-pune_fdb.Oaie.height; } else { pune_fdb.Spate.height=150; pune_fdb.Oaie.y=30.1; } pune_fdb.x=699/2-pune_fdb.width/2; pune_fdb.y=599/2-pune_fdb.height/2; } /*Feed-Back*/ } }