游戏开始制作前,先找好图标整理成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);
}
}
}
运行的效果图: