一个测试时间感的小游戏

点击打开链接

package 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.text.*;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	import flash.events.KeyboardEvent;
	
	/**
	 * ...
	 * @author ...
	 */
	public class dumiao extends Sprite 
	{
		public var time:Timer;
		public var input:TextField;
		public var box:MovieClip;
		public var gameStart:Boolean;
		public var count:int = 0;
		
		public function dumiao()
		{
			time = new Timer(1000);
			gameStart = false;
			input.restrict = "0-9";
			box.stop();
			box.addEventListener(MouseEvent.CLICK, clickHandler);
			time.addEventListener(TimerEvent.TIMER, updateTimeHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,enterHandler);
		}
		
		public function enterHandler(e:KeyboardEvent):void
		{
			if (e.keyCode == Keyboard.ENTER)
			{
				if (int(input.text) == count)
				{
					//trace("you win");
					input.text = "you win";
					input.type = TextFieldType.DYNAMIC;
					stage.focus = null;
				}
				else
				{
					//trace("you lose");
					input.text = "you lose";
					input.type = TextFieldType.DYNAMIC;
					stage.focus = null;
				}
			}
		}
		
		public function updateTimeHandler(e:TimerEvent):void
		{
			//input.text = String(time.currentCount);
			if (time.currentCount == count)
			{
				time.stop();
				box.gotoAndStop(2);
				input.text = "";
				stage.focus = input;
				input.type = TextFieldType.INPUT;
				box.addEventListener(MouseEvent.CLICK, clickHandler);
			}
		}
		
		public function clickHandler(e:MouseEvent):void
		{
			gameStart = !gameStart;
			trace(gameStart);
			if (gameStart)
			{
				time.reset();
				stratGame();
			}
			else
			{
				box.gotoAndStop(1);
				input.text = "点击方块";
			}
			
			
		}
		public function stratGame():void
		{
			count = int(Math.random() * 10 + 10);
			trace(count);
			time.start();
			input.text = "计时开始";
			input.type = TextFieldType.DYNAMIC;
			box.removeEventListener(MouseEvent.CLICK, clickHandler);
		}
	}
	
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值