Soyez le premier à donner votre avis sur cette source.
Vue 8 125 fois - Téléchargée 1 231 fois
package { import flash.display.Sprite; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.text.TextFormat; import fl.controls.Button; import flash.utils.Timer; import fl.controls.Label; import fl.controls.TextArea; import flash.events.*; import fl.events.ComponentEvent; import flash.display.SimpleButton; import flash.display.*; import flash.net.navigateToURL; import flash.display.BitmapData; import flash.display.Bitmap; import flash.media.Sound; import flash.media.SoundChannel; public class completer extends MovieClip { private static const DICTIONARY_LOCATION:String = "dictionary.txt"; public var wordBeingSpelled:String; private static const TOTAL_TIME:Number = 60;// in seconds private static const POINTS_PER_WORD_LOOKUP:Array = [null,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; private var clockField :Label; private var t:Timer; public var contenu:String; public var motTrouve:String; public var Mots:Array = new Array(); public var newTab:Array = new Array(); public var legendeReverse:Array = new Array(); public var wordBeingSpelledLabel:Label; public var submitWordButton:Button; public var clearWordButton:Button; public var playNiveauButton:Button; public var replayButton:Button; public var buttonReplay:Button; public var buttonInst:Button; public var buttonSite:Button; public var scoreReport:TextArea; public var conteneur:Sprite = new Sprite ; public var pageConteneur:page =new page(); private var loader:URLLoader; private var wordsFound:Array; private var words:Array = new Array(); private var i:int; private var sonInitial:Sound = new son(); private var chanInitial:SoundChannel; public function completer() { initial(); } private function initial() { chanInitial = sonInitial.play();// joue le bruit addChild(pageConteneur); pageConteneur.addChild(conteneur); conteneur.x = 120; conteneur.y = 50; var playB:menuBtn; var img:BitmapData = new titre(); var monBitmap:Bitmap=new Bitmap(img); monBitmap.scaleX = .9; conteneur.addChild(monBitmap); buttonReplay = new Button ; buttonReplay.move(100,200); buttonReplay.setSize((220 / 2),20); buttonReplay.label = "START"; conteneur.addChild(buttonReplay); buttonReplay.addEventListener(MouseEvent.CLICK, jeuNouveau); buttonInst = new Button ; buttonInst.move(100,225); buttonInst.setSize((220 / 2),20); buttonInst.label = "INSTRUCTION"; conteneur.addChild(buttonInst); buttonInst.addEventListener(MouseEvent.CLICK, jeuInstruction); buttonSite = new Button; buttonSite.move(100,250); buttonSite.setSize((220 / 2),20); buttonSite.label = "MORE GAMES"; conteneur.addChild(buttonSite); buttonSite.addEventListener(MouseEvent.CLICK, acessarSite); function jeuNouveau(pEvt:MouseEvent):void { while(conteneur.numChildren>0){ conteneur.removeChildAt(0); } wordBeingSpelled = new String(); wordsFound = new Array(); loadDictionary(DICTIONARY_LOCATION); creeMenu(); startTimer(TOTAL_TIME); } function jeuInstruction(pEvt:MouseEvent):void { var inst : instruction= new instruction (); inst.x = 0; inst.y = 0; conteneur.removeChild(buttonInst); conteneur.addChild(inst); } function acessarSite(pEvt:MouseEvent):void { var requete:URLRequest = new URLRequest ("http://www.majootalk.com"); navigateToURL( requete ); } } private function loadDictionary(path:String):void { loader = new URLLoader(); loader.addEventListener(Event.COMPLETE,dictionaryLoaded); loader.load(new URLRequest(path)); } private function dictionaryLoaded(e:Event):void { var dictionaryText:String = String(e.target.data); words = dictionaryText.split("\n"); //startTimer(TOTAL_TIME); trace("-- Dictionary loaded -- " + words.length + " words"); } private function creeMenu():void { // création de l'objet URLLoader var chargeurDonnees:URLLoader = new URLLoader ; // nous souhaitons charger des données texte chargeurDonnees.dataFormat = URLLoaderDataFormat.TEXT; // chargement des données chargeurDonnees.load(new URLRequest("donnees.txt")); // écoute de l'événement Event.COMPLETE chargeurDonnees.addEventListener(Event.COMPLETE,chargementTermine); chargeurDonnees.addEventListener(IOErrorEvent.IO_ERROR,erreurChargement); var format:Object = new TextFormat(); var format2:Object = new TextFormat(); format.font = "Georgia"; format.size = 16; format.color = 0x0000FF; wordBeingSpelledLabel = new Label ; wordBeingSpelledLabel.autoSize = "center"; wordBeingSpelledLabel.move(150,100); wordBeingSpelledLabel.setStyle("textFormat",format); wordBeingSpelledLabel.text = ""; addChild(wordBeingSpelledLabel); submitWordButton = new Button ; submitWordButton.move(150,180); submitWordButton.setSize((175 / 2),20); submitWordButton.label = "CONFIRMAR"; submitWordButton.addEventListener(MouseEvent.CLICK,submitWord); addChild(submitWordButton); clearWordButton = new Button ; clearWordButton.move((150 + (175 / 2)),180); clearWordButton.setSize((175 / 2),20); clearWordButton.label = "LIMPAR"; clearWordButton.addEventListener(MouseEvent.CLICK,clearWord); addChild(clearWordButton); scoreReport = new TextArea ; scoreReport.x = 150; scoreReport.y = 220; scoreReport.setSize(175,100); scoreReport.editable = false; addChild(scoreReport); clockField = new Label; clockField.move(150,0); format2.size=16; format2.color = 0x699699; clockField.setStyle("textFormat",format2); clockField.text = ""; clockField.width =300; addChild(clockField); } private function chargementTermine(pEvt:Event):void { // accès aux données chargées contenu = pEvt.target.data; playNiveau(); } private function playNiveau():void { var num:Number =conteneur.numChildren; for(i=0; i<num; i++){ if(i>-1){ conteneur.removeChildAt(0); } } Mots = contenu.split("\n"); var b:MovieClip; var leg = Math.floor(Math.random() * (Mots.length-1)); var a:Number = leg; newTab.push(Mots[a]); var legende = Mots[a].split(',').sort(); legendeReverse = legende; var lng:int = legendeReverse.length; for (var i:int = 0; i < lng; i++) { b = new etat_global(); b.name = legendeReverse[i]; b.maLegende.text = legendeReverse[i]; b.mouseChildren = false; b.buttonMode = true; conteneur.addChild(b); b.x = b.width * Math.round((i % lng)); b.addEventListener(MouseEvent.CLICK, letterClicked); } trace(newTab.length); trace(newTab); var pos:Number =newTab.indexOf(Mots[a]) newTab.splice(pos,1); trace(Mots[a].length); } private function erreurChargement(pEvt:IOErrorEvent):void { trace("erreur de chargement"); } private function letterClicked(pEvt:MouseEvent):void { pEvt.currentTarget.removeEventListener(MouseEvent.CLICK, letterClicked); pEvt.currentTarget.alpha = 0.1; addToSpelledWord(pEvt.currentTarget.name); } private function addToSpelledWord(str:String):void { wordBeingSpelled += str; wordBeingSpelledLabel.text = wordBeingSpelled; trace("Continuing: " + wordBeingSpelled); } private function submitWord(e:MouseEvent):void { wordBeingSpelled = wordBeingSpelledLabel.text; trace(wordBeingSpelled.toLowerCase()); playNiveau(); if (wordBeingSpelled.length < conteneur.numChildren) { startNewWord(""); wordBeingSpelledLabel.text = "Minimum " + conteneur.numChildren + " letras."; } else if (!isAlreadyFound(wordBeingSpelled)) { var indexOfWord:Number = words.indexOf (wordBeingSpelled.toLowerCase()); trace(indexOfWord); if (indexOfWord > -1) { wordsFound.push(wordBeingSpelled); startNewWord(""); updateScore(); wordBeingSpelledLabel.text = "Nouveau mot rencontré!"; } else { startNewWord(""); wordBeingSpelledLabel.text = "Ne se trouve pas dans notre dictionnaire."; } } else { startNewWord(""); wordBeingSpelledLabel.text = "Déjà présenté."; } } private function clearWord(e:MouseEvent):void { startNewWord(""); } private function isAlreadyFound(word:String):Boolean { var i:uint; for (i = 0; i<wordsFound.length; i++) { if (word == wordsFound[i]) { return true; } } return false; } private function startNewWord(str:String):void { trace("Starting new word: " + wordBeingSpelled); wordBeingSpelled = str; wordBeingSpelledLabel.text = str; } private function updateScore():void { var wordList:String = new String(); var pointsTotal:Number = 0; var i:uint; for (i=0; i<wordsFound.length; i++) { var thisWord:String = wordsFound[i]; pointsTotal += POINTS_PER_WORD_LOOKUP[thisWord.length]; wordList += thisWord + "\n"; } scoreReport.text = "Total Points: " + pointsTotal + "\n" + wordList; } private function startTimer(totalTimeToExpire:Number):void { t = new Timer(1000,totalTimeToExpire); t.addEventListener(TimerEvent.TIMER,timerTick); t.addEventListener(TimerEvent.TIMER_COMPLETE,timerOutOfTime); t.start(); } private function timerTick(pEvt:TimerEvent):void { var timeRemaining:Number = TOTAL_TIME - pEvt.target.currentCount; clockField.text = "Tempo Restante: " + String(timeRemaining); } private function timerOutOfTime(e:TimerEvent):void { finale(); var i:uint; submitWordButton.enabled = false; clearWordButton.enabled = false; wordBeingSpelledLabel.text = ""; } private function finale() { clockField.text = "Tempo Esgotado!"; while(conteneur.numChildren>0){ conteneur.removeChildAt(0); } replayButton = new Button ; replayButton.move(150,180); replayButton.setSize((175 / 2),20); replayButton.label = "Replay"; replayButton.addEventListener(MouseEvent.CLICK,replayAction); removeChild(submitWordButton); removeChild(clearWordButton); addChild(replayButton); } private function replayAction(e:MouseEvent):void { initial(); } } }
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.