AS3实现的拼图游戏代码的功能介绍
点评:通过AS3的拼图游戏可以有在顶部和底部的空白空间的交换,如果是左或右,它可以设置为12345678最后,感兴趣的朋友可以学习它。如下图所示,如在上、下两侧有一个空白,则可以互换,最后可按顺序排列12345678。
实现代码如下所示:
包含两个文件:
一是构建数字小档案:rectshape.as
复制代码代码如下所示:
包{
进口flash.display.sprite;
进口flash.text.textformat;
进口flash.text.textfield;
进口flash.text.textfieldautosize;
公共课rectshape延伸雪碧{
机车的xzuobiao:单元;
机车的yzuobiao:单元;
公共函数的RectShape(民数记:UINT){
init(努姆);
}
私有函数init(Num:UINT){
This.graphics.beginFill(0x00ff00);
this.graphics.linestyle(1); / /套线的厚度
this.graphics.drawrect(0,0,40,40);
This.graphics.endFill();
设置号
无功txt_format:文本格式=新的文本格式();
txt_format大小= 30;
无功txt_num:TextField =新的文本框();
txt_num。可选= false; / /设置文本字段不可选
txt_num。文本= +数字;
txt_num宽度= 40;
txt_num高度= 40;
txt_num x = 0;
txt_num y = 0;
txt_num.settextformat(txt_format);
txt_num AutoSize = textfieldautosize.center;
this.addchild(txt_num);
}
设置属性的get set方法
公共函数x():单位{
Return xzuobiao;
}
公共功能集X(xzuo:单元):无效{
这xzuobiao = xzuo;
}
公共职能得到Y():单位{
返回yzuobiao;
}
公共函数集合Y(部件:单元):无效{
这yzuobiao =部件;
}
}
}
第二是入口:Main.as改
复制代码代码如下所示:
包{
进口flash.display.sprite;
进口flash.events.mouseevent;
公共类主扩展精灵{
机车的indexshape:阵列=新的数组(1,2,3,4,5,6,7,8); / /八个文本框中显示。
私人VAR革履阵列= { { 1,1,1 },{ 1,1,1 },{ 1,1,1 } }; / /默认值是1,记录的位置放一个小盒子,没有把盒子时其值为1,把盒子后改为0
私人pielie阵列= { { var:0 },{ 40,0 },{ 800 },{ 0,40 },{ 40,40 },{ 80,40 },{ 0,80 },{ 40,80 },{ 80 } }; / / XY坐标定义排列的立方体
公共函数main(){
init();
}
私有函数init():无效{
var:雪碧=新雪碧();
kuang.graphics.linestyle(3,0xff00ff);
(00120120)kuang.graphics.drawrect;
Kuang.graphics.endFill();
轰埠,x=215;
轰埠,y=140;
addChild(轰埠);
随机数1-8 / /填充
对于(var i:单位= 1;我< = 8;i++){
VaR指标:单位= math.floor(Math.random()* indexshape。长度);
VaR Num:单位= indexshape {指数};
indexshape.splice(指数1); / /删除数组中的数字
VaR的形状:rectshape =新rectshape(努姆); / /集的生成
形状。mousechildren = false; / /解决箱文本框文本框覆盖问题
随机生成一个位置来存储框
VaR的位置:单位= math.floor(Math.random()* pielie。长度);
无功positionvalue:数组pielie {位置};
Pielie.splice(位置1); / /这个位置删除记录
形状。x = positionvalue { 0 };
形状。Y = positionvalue { 1 };
形状。x = positionvalue { 0 } / 40;
形状。Y = positionvalue { 1 } / 40;
修改记录值的位置为0。
该positionvalue { 0 } { 40 } { positionvalue / / 40 { 1 } } = 0;
kuang.addchild(形状);
添加鼠标单击事件
shape.addeventlistener(MouseEvent.CLICK,movenum);
}
}
私有函数movenum(EVT:MouseEvent):无效{
左:int var = evt.target.x-1;
无功右:int = EVT。目标。x + 1;
VaR的顶部:int = EVT。目标。y + 1;
无功底:int = evt.target.y-1;
移动左/ /处理
如果(左)!= - 1jilu {左} { EVT。目标。Y = = 1){ }
跟踪(左);
冀鲁{ EVT。目标。x } { EVT。目标。Y } = 1;
冀鲁{左} { EVT。目标。Y } = 0;
EVT。目标。x =左;
EVT。目标。x = 40; / /左移动40
}如果(右)!{右} { = 3jilu EVT。目标。Y = = 1){ }
跟踪(右);
冀鲁{ EVT。目标。x } { EVT。目标。Y } = 1;
Jilu {右} { EVT。目标。Y } = 0; / /修改记录
EVT。目标。x =权;
EVT。目标。x = 40; / /向右移动40
}如果(顶部)!= - 1jilu { EVT。} {顶}目标。x = = 1){
冀鲁{ EVT。目标。x } { EVT。目标。Y } = 1;
冀鲁{ EVT。} {顶}目标。x = 0; / /修改记录
EVT。目标。Y =顶;
EVT。目标。y + = 40; / /移动40
}如果(底部)!= 3冀鲁{ EVT。} {底}目标。X = = 1){
冀鲁{ EVT。目标。x } { EVT。目标。Y } = 1;
冀鲁{ EVT。} {底}目标。x = 0; / /修改记录
EVT。目标。Y =底;
EVT。目标。y = 40; / /移动40
}
}
}
}