猜数字游戏
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.text.*;
public class Main1 extends MovieClip
{
private var ar:Array;
public var sc_txt:TextField;
private var number:int;
public var ts_txt:TextField;
public var sr_txt:TextField;
public function Main1():void
{
qd_btn.visible = false;
kaishi_btn.addEventListener(MouseEvent.CLICK,onks);
qd_btn.addEventListener(MouseEvent.CLICK, onqueding);
}
private function onks(e:MouseEvent):void
{
number = int(Math.random() * 100);
ts_txt.text = "";
sr_txt.visible = true;
qd_btn.visible = true;
sr_txt.text = "";
sc_txt.text = "";
}
private function onqueding(e:MouseEvent):void
{
var b:int = int(sr_txt.text);
if (b < 0 || b > 99)
{
sc_txt.text = "输入的数字范围有错!";
}
else if (b < number)
{
sc_txt.text = "输入的数字太小了!";
ts_txt.appendText(String(b) + "->");
}
else if (b > number)
{
sc_txt.text = "输入的数字太大了!";
ts_txt.appendText(String(b) + "->");
}
else if (b == number)
{
sc_txt.text = "恭喜你,你猜对了!!!";
ts_txt.appendText("正确");
sr_txt.visible = false;
qd_btn.visible = false;
}
sr_txt.text = "";
}
}
}