AS3连连看源码教程(一)

游戏开始制作前,先找好图标整理成Fla文件,库内容如下图:



然后对包和类进行分析设计:



package com 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import com.llk.page.PagePlay;
	
	/**
	 * ...
	 * @author ragged
	 */
	public class Main extends Sprite 
	{
		/**
		 * 游戏页面
		 */
		private var _page:PagePlay;
		
		
		
		
		
		
		public function Main() 
		{
			this.createPlayPage();
		}
		/**
		 * 创建游戏页面
		 */
		private function createPlayPage():void
		{
			this.delPage();
			this._page = new PagePlay();
			this.addChild(this._page);
		}
		/**
		 * 删除页面
		 */
		private function delPage():void
		{
			if (this._page)
			{
				this.removeChild(this._page);
				this._page = null;
			}
		}
	}
}


package com.llk.page 
{
	import flash.display.Sprite;
	import com.llk.icon.Icon;
	/**
	 * ...
	 * @author ragged
	 */
	public class PagePlay extends Sprite 
	{
		/**
		 * 游戏背景
		 */
		private var _bg:Sprite;
		/**
		 * 连连看图标,二维数组
		 */
		private var _iconArr:Array = [];
		
		
		
		public function PagePlay() 
		{
			super();
			this._bg = new ResPlayBg;
			this.addChild(this._bg);
			this.createIconArray();
		}
		/**
		 * 创建ICON二维数组
		 */
		private function createIconArray():void
		{
			var i:uint;
			var j:uint;
			for (i = 0; i < 8;i++ )
			{
				this._iconArr[i] = [];
				
				for (j = 0; j < 8;j++ )
				{
					this._iconArr[i][j] = new Icon(i, j);
					this.addChild(this._iconArr[i][j]);
				}
			}
		}
	}
}


package com.llk.icon 
{
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	/**
	 * ...
	 * @author ragged
	 */
	public class Icon extends Sprite 
	{
		/**
		 * 图片类型
		 */
		private var _type:uint;
		/**
		 * 图标
		 */
		private var _icon:Sprite;
		
		private var _i:uint;
		private var _j:uint;
		
		
		
		
		public function Icon($i:uint, $j:uint) 
		{
			super();
			//记录图标在二维数组中的位置
			this._i = $i;
			this._j = $j;
			//随机图标类型
			this._type = Math.random() * 8;
			this.x = this._i * 51;
			this.y = this._j * 51;
			
			this.createIcon();
		}
		/**
		 * 根据类型创建图标
		 */
		private function createIcon():void
		{
			this._icon = new (getDefinitionByName("ResIcon" + this._type) as Class);
			this.addChild(this._icon);
		}
	}
}


运行的效果图:



  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值