赛马(小游戏)



package {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.Event;
	/*          
	
	    *author : SinSoul         
	
	     *blogs: http://www.cnblogs.com/sinsoul         
	
	 */


	public class Main extends MovieClip {

		public function Main():void {
			init();


		}
		private function init():void {

			ma1.stop();
			ma2.stop();
			ma3.stop();
			ma4.stop();
			ma5.stop();
			ma1.ed=false;
			ma2.ed=false;
			ma3.ed=false;
			ma4.ed=false;
			ma5.ed=false;
			ks.addEventListener(MouseEvent.CLICK,kaishi);
			go.addEventListener(MouseEvent.CLICK,onGo);
		}
		private function kaishi(e:MouseEvent):void {
			ma1.ed=false;
			ma2.ed=false;
			ma3.ed=false;
			ma4.ed=false;
			ma5.ed=false;

			md.text="";
			ma1.x=-38.6;
			ma2.x=-38.6;
			ma3.x=-38.6;
			ma4.x=-38.6;
			ma5.x=-38.6;
			ma1.stop();
			ma2.stop();
			ma3.stop();
			ma4.stop();
			ma5.stop();

			removeEventListener(Event.ENTER_FRAME,pao);


		}

		private function onGo(e:MouseEvent):void {
			ma1.gotoAndPlay(1);
			ma2.gotoAndPlay(1);
			ma3.gotoAndPlay(1);
			ma4.gotoAndPlay(1);
			ma5.gotoAndPlay(1);

			addEventListener(Event.ENTER_FRAME,pao);
		}

		private function pao(e:Event):void {
			var zhongdian=518.4;
			var msg="";

			if (ma1.x>zhongdian) {
				if (ma1.ed==false) {
					ma1.stop();
					ma1.ed=true;
					md.appendText("1号"+"->");
				}
			} else {
				ma1.x+=Math.random()*10;
			}

			if (ma2.x>zhongdian) {
				if (ma2.ed==false) {
					ma2.stop();
					ma2.ed=true;
					md.appendText("2号"+"->");
				}
			} else {
				ma2.x+=Math.random()*10;
			}

			if (ma3.x>zhongdian) {
				if (ma3.ed==false) {
					ma3.stop();
					ma3.ed=true;
					md.appendText("3号"+"->");
				}
			} else {
				ma3.x+=Math.random()*10;
			}

			if (ma4.x>zhongdian) {
				if (ma4.ed==false) {
					ma4.stop();
					ma4.ed=true;
					md.appendText("4号"+"->");
				}
			} else {
				ma4.x+=Math.random()*10;
			}

			if (ma5.x>zhongdian) {
				if (ma5.ed==false) {
					ma5.stop();
					ma5.ed=true;
					md.appendText("5号"+"->");
				}
			} else {
				ma5.x+=Math.random()*10;
			}
		}

		private function mingdan():void {

			if (ma1.x>518.4) {
				//removeEventListener(Event.ENTER_FRAME,pao);
				ma1.gotoAndStop(1);
				ma1.stop();
				md.appendText("1号"+"->");
			}

			if (ma2.x>518.4) {
				removeEventListener(Event.ENTER_FRAME,pao);
				ma2.stop();
				md.appendText("2号"+"->");
			}

			if (ma3.x>518.4) {
				removeEventListener(Event.ENTER_FRAME,pao);
				ma3.stop();
				md.appendText("3号"+"->");
			}

			if (ma4.x>518.4) {
				removeEventListener(Event.ENTER_FRAME,pao);
				ma4.stop();
				md.appendText("4号"+"->");
			}

			if (ma5.x>518.4) {
				removeEventListener(Event.ENTER_FRAME,pao);
				ma5.stop();
				md.appendText("5号"+"->");
			}

		}

	}
}

 

posted @ 2010-11-07 14:35  sinsoul  阅读(609)  评论(0编辑  收藏  举报