package
{
import flash.display.MovieClip;
import flash.text.*;
import flash.events.MouseEvent;
import flash.media.Microphone;
import flash.sensors.Accelerometer;
public class GuessANumber extends MovieClip
{
var txtRules:TextField;
var txtFeedback:TextField;
var txtInput:TextField;
var myBtnEnter: btnEnter;
var myReplybtn:btnReply;
var myRandNum:int;
var myNumTextToNumber:Number;
var RandNum:uint;
var myMaxNumGuesses:uint;
var numGuesses:uint;
var format:TextFormat;
var difficulty:uint;
var myEasyBtn:easyBtn;
var myMediumBtn:mediumBtn;
var myHardBtn:hardBtn;
public function GuessANumber()
{
myRandNum = Math.random() * 10;
numGuesses = 0;
myMaxNumGuesses = 3;
format = new TextFormat() ;
format.color = 0xFF0000
format.font = "Verdana"
format.size = 15;
format.bold = true;
txtRules = new TextField;
txtRules.width = 550;
txtRules.selectable = false;
txtRules.x = 193;
txtRules.y = 80;
txtRules.text = "";
txtRules.visible = false
addChild(txtRules);
txtFeedback = new TextField;
txtFeedback.type = TextFieldType.DYNAMIC;
txtFeedback.selectable = false;
txtFeedback.width = 550;
txtFeedback.x = 193;
txtFeedback.y = 106;
addChild (txtFeedback);
txtInput = new TextField;
txtInput.type = TextFieldType.INPUT;
txtInput.border = true;
txtInput.background = true;
txtInput.backgroundColor = 0x00FF00
txtInput.x = 193;
txtInput.y = 150;
txtInput.restrict = "0-9";
txtInput.multiline = true;
txtInput.wordWrap = true;
txtInput.text = "Input your guess";
addChild(txtInput);
myBtnEnter = new btnEnter;
myBtnEnter.x = 277;
myBtnEnter.y = 354;
myBtnEnter.scaleX = 2;
myBtnEnter.scaleY = 2;
myBtnEnter.visible = false;
addChild (myBtnEnter);
myReplybtn = new btnReply;
myReplybtn.x = 274;
myReplybtn.y = 292;
myReplybtn.visible = false
addChild (myReplybtn)
myEasyBtn = new easyBtn;
myEasyBtn.x = 493;
myEasyBtn.y = 30;
addChild(myEasyBtn)
myMediumBtn = new mediumBtn;
myMediumBtn.x = 493;
myMediumBtn.y = 63;
addChild(myMediumBtn)
myHardBtn = new hardBtn;
myHardBtn.x = 493;
myHardBtn.y = 93;
addChild(myHardBtn);
myBtnEnter.addEventListener(MouseEvent.CLICK,myInput)
myReplybtn.addEventListener(MouseEvent.CLICK,restartGame)
myEasyBtn.addEventListener(MouseEvent.CLICK, Easydifficulty)
myMediumBtn.addEventListener(MouseEvent.CLICK, Mediumdifficulty)
myHardBtn.addEventListener(MouseEvent.CLICK, Harddifficulty)
}
function Easydifficulty (e:MouseEvent)
{
trace ("Working")
myRandNum = Math.random() * 10;
numGuesses = 0;
myMaxNumGuesses = 3;
myEasyBtn.visible = false;
myMediumBtn.visible = false;
myHardBtn.visible = false;
myBtnEnter.visible = true;
txtRules.text = "guess a number between 1 and 10";
txtRules.visible = true;
txtInput.maxChars = 1;
}
function Mediumdifficulty (e:MouseEvent)
{
trace ("working")
myRandNum = Math.random() * 100;
numGuesses = 0;
myMaxNumGuesses = 10;
myEasyBtn.visible = false;
myMediumBtn.visible = false;
myHardBtn.visible = false;
myBtnEnter.visible = true;
txtRules.text = "guess a number between 1 and 100";
txtRules.visible = true;
txtInput.maxChars = 2;
}
function Harddifficulty (e:MouseEvent)
{
trace ("working")
myRandNum = Math.random() * 100;
numGuesses = 0;
myMaxNumGuesses = 15 ;
myEasyBtn.visible = false;
myMediumBtn.visible = false;
myHardBtn.visible = false;
myBtnEnter.visible = true;
txtRules.text = "guess a number between 1 and 1000";
txtRules.visible = true;
txtInput.maxChars = 3;
}
function restartGame(e:MouseEvent)
{
myRandNum = Math.random() * 10;
numGuesses = 0;
myMaxNumGuesses = 3;
txtFeedback.text = "";
txtFeedback.setTextFormat ( format ) ;
txtInput.text = "Input your guess";
myReplybtn.visible = false;
myBtnEnter.visible = true;
myMediumBtn.visible = true;
myHardBtn.visible = true;
myEasyBtn.visible = true;
myBtnEnter.visible = false
txtRules.visible = true
}
function myInput(e:MouseEvent)
{
numGuesses++
var myNumTextToNumber:int = int(txtInput.text)
if( myNumTextToNumber>myRandNum && numGuesses<myMaxNumGuesses)
{
txtFeedback.text = "Your Number is to high."
}
else if ( myNumTextToNumber<myRandNum && numGuesses<myMaxNumGuesses)
{
txtFeedback.text = "your number is to low."
}
else if ( myNumTextToNumber==myRandNum)
{
txtFeedback.text = "You Got the number, Well done"
myReplybtn.visible = true;
myBtnEnter.visible = false;
}
else
{
txtFeedback.text = "Your not getting number, Just restart retart"
myReplybtn.visible = true;
myBtnEnter.visible = false;
}
txtFeedback.setTextFormat ( format ) ;
}
}
}