您的位置:首页 > 其它

简单的小游戏(猜数字)

2010-11-05 13:20 155 查看
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;

/*
*author : SinSoul
*blogs: http://www.cnblogs.com/sinsoul

*/
public class CNumber extends MovieClip {

var an:Boolean;
var number:int;
var txt:TextField;//创建一个文本框 将 new Text 参数指定的字符串追加到文本字段的文本的末尾。

var txttmp:String;

public function CNumber():void {
init();
}
public function init():void {
an=false;
cm1.visible=false;
txt3.visible=false;
txt6.visible=false;
mc3.visible=false;
txt=new TextField  ;
txttmp="";
cm.addEventListener(MouseEvent.CLICK,chen);
cm1.addEventListener(MouseEvent.CLICK,long);
}
public function chen(e:MouseEvent):void {

txttmp+="1 > ";
txttmp.concat("1> ");
txt2.text=txttmp;

//txt2.appendText("55 > ");

if (an==false) {
number=Math.round(Math.random()*100);
cm1.visible=true;
txt6.visible=true;
txt3.visible=true;
an=true;
} else {

txt6.text="";
txt1.text="";
//txt2.text="";
txt.text="";
mc3.visible=false;
number=Math.round(Math.random()*100);
}
}
public function long(e:MouseEvent):void {

var t:int=int(txt6.text);

if (t<0||t>99) {
txt1.text="输入的数字范围有错!";
} else if (t<number) {

txt1.text="您输入的数字小了点吧?╮(╯_╰)╭";
txt.appendText(String(t)+"->");
txt2.text=txt.text;
} else if (t==number) {
txt1.text="恭喜你答对了!";
txt.appendText(String(t)+"->");
txt2.text=txt.text;
mc3.visible=true;

} else {
txt1.text="您输入的数字大了点吧?(#‵′)凸 o_O???";
txt.appendText(String(t)+"->");
txt2.text=txt.text;
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: