求flash原创游戏
包{
导入flash . display . sprite;
导入flash . text . textfield;
导入flash . events . *;
导入flash . utils . timer;
公共类AppleGame扩展Sprite {
var arrAZ:Array = new Array();
var apple contain:Sprite = new Sprite;
var arr level:Array = new Array();//当前等级的苹果数量
var水平:uint = 1;//等级
var window contain:Sprite = new Sprite;
var Num _ apple:uint = 0;
var Num _ RIGHT:uint = 0;
var Num _ Timer:uint = 0;
var t _ score:textfield = Text . return(" Text ",20,370,0x00ff00,false);
var t _ rate:textfield = Text . return(" Text ",220,370,0x00ff00,false);
var TIMER:TIMER = new TIMER(1000);
var P _ stop:Boolean = false;
公共函数AppleGame() {
arr level =;
addChild(window contain);
addChild(apple contain);
windows();
arrAZ = ["A "、" B "、" C "、" D "、" E "、" F "、" G "、" H "、" I "、" J "、" K "、" L "、" M "、" N "、" O "、" P "、" Q "、" R "、" S "、" T "、" U "、" V "、" W "、" X "、" Y "、" Z]];
stage . addevent listener(keyboard event。KEY_DOWN,catch KEY);
stage.addEventListener(事件。ENTER_FRAME,ENTER FRAME);
timer . start();
timer . addevent listener(timer event。定时器,H _ TIMER);
stage . addevent listener(keyboard event。KEY_DOWN,H _ PStop);
}
私有函数enterframe(e:Event):void {
P _ stop = true
addapple();
apple down();
t _ rate . text = " Correct rate:"+math . floor(num _ right/(num _ apple-3)* 100)+" ";
T _ rate。settextformat (tf。return (20,“天”,真));
}
私有函数addapple() {
if(apple contain . num children & lt;arrLevel[Level]) {
var Apple:Apple = new Apple();
num _ apple++;
apple . x = math . random()* 450+50;
AppleContain.addChild(苹果);
Var Txt:TextField = Text。Return ("texttext ",-8,-10,0x0000ff,false);
txt . text = arrAZ[math . floor(math . random()* 26)];
Txt.setTextFormat(TF。Return(20,《宋体》,真));
apple . addchild(Txt);
苹果。TYPE = Txt.text
}
}
私有函数appleDown() {
for(var I:int = 0;我& ltapple contain . num children;i++) {
var moving Apple:Apple = Apple contain . get child at(I)as Apple;
moving apple . y+= Level+3;
if(moving apple . y & gt;400) {
apple contain . remove child(moving apple);
}
}
}
私有函数catch key(ek:keyboard event):void {
for(var j:int = 0;j & ltapple contain . num children;j++) {
var moving Apple:Apple = Apple contain . get child at(j)as Apple;
如果(移动苹果。TYPE = = string . from charcode(ek . charcode)。toUpperCase()) {
num _ right++;
apple contain . remove child(moving apple);
打破;//检测到循环后,跳出。
}
}
}
私有函数H _ PStop(ek:keyboard event):void {
if(ek.keyCode==32){
如果(P_stop){
timer . stop();
stage.removeEventListener(事件。ENTER_FRAME,ENTER FRAME);
stage . removeeventlistener(keyboard event。KEY_DOWN,catch KEY);
P _ stop = false
}否则{
timer . start();
stage.addEventListener(事件。ENTER_FRAME,ENTER FRAME);
stage . addevent listener(keyboard event。KEY_DOWN,catch KEY);
}
}
if(ek.keyCode==13){
数字计时器=数字权利= 0;
num _ apple = 3;
}
}
私有函数H_TIMER(et:TimerEvent):void{
num _ timer++;
t _ score . text = " speed:"+math . floor(num _ right/num _ timer * 60)+"字数/分钟";
T _ score。settextformat (tf。return (20,"í",true));
}
私有函数窗口(){
t _ score . width = 180;
window contain . addchild(T _ score);
t _ rate . width = 140;
window contain . addchild(T _ Rate);
}
}
}