标题:
[原创]连连看的Flash代码
[打印本页]
作者:
紫色流星
时间:
2007-4-21 09:05
标题:
[原创]连连看的Flash代码
首先是程序下载了~
制作比较粗糙,难度也比较高。
因为工科嘛,主要看重的是算法而不是美工,呵呵~
请大家多多拍砖。
压缩文件: 连连看.swf 没有病毒,大家放心。如果没有Flash官方播放器可以使用IE打开。
附件:
连连看.rar
(2007-4-21 09:10, 78.88 KB) / 下载次数 1116
http://heubbs.cn/attachment.php?aid=4919&k=ba6df7e5e54fa9e5a77e61c3731190f7&t=1732393671&sid=54kkHh
图片附件:
00.JPG
(2007-4-21 09:19, 131.55 KB) / 下载次数 140
http://heubbs.cn/attachment.php?aid=4920&k=30d5097d3e892f47348a4e5aaa8ba6c6&t=1732393671&sid=54kkHh
作者:
紫色流星
时间:
2007-4-21 09:12
标题:
源代码
//-----------------------------
//版本:1.0
//日期:2007-04-15
//-----------------------------
Stage.scaleMode = "noScale";
var l0:Number = 50;
var l1:Number = 4;
var xq:Number = 0;
var jl:Number = 5;
var cf:Number = 10;
var total:Number = 500;
_global.roots = new Array(22);
var tpx:Array = new Array(l0);
var tpy:Array = new Array(l0);
_root.createEmptyMovieClip("line", 10000);
_root.createEmptyMovieClip("box1", 10001);
_root.createEmptyMovieClip("box2", 10002);
_root.createEmptyMovieClip("lines", -10000);
_global.clc = new Object();
_global.tim = new Object();
var zt:Boolean = new Boolean(false);
var ts:Boolean = new Boolean(true);
var prx:Number = 0;
var pry:Number = 0;
var cx1:Number = 0;
var cy1:Number = 0;
var cx2:Number = 0;
var cy2:Number = 0;
auto = function ():Void {
if (ts) {
for (var i = 0; i<l0; i++) {
for (var j = 0; j<l1-1; j++) {
var prx = tpx[j];
var pry = tpy[j];
if (tpx[j] == 0 || roots[prx][pry] == 0) {
continue;
}
for (var k = j+1; k<l1 && ts; k++) {
var nwx = tpx[k];
var nwy = tpy[k];
if (tpx[k] == 0 || roots[nwx][nwy] == 0) {
continue;
}
if (Judge1(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
ts = false;
Boxing(_root["tp"+nz], _root["tp"+pz]);
} else if (Judge2(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
ts = false;
Boxing(_root["tp"+nz], _root["tp"+pz]);
} else if (Judge3(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
ts = false;
Boxing(_root["tp"+nz], _root["tp"+pz]);
}
}
}
}
if (ts == true) {
fresh();
}
}
};
fresh = function ():Void {
ts = false;
var zbx:Array = new Array();
var zby:Array = new Array();
var zbz:Array = new Array();
for (var i = 0; i<l0*l1-xq*2; i++) {
do {
x = random(20)+1;
y = random(10)+1;
} while (roots[x][y] == 0);
zbx.push(x);
zby.push(y);
zbz.push(roots[x][y]);
roots[x][y] = 0;
var n = x*100+y;
_root["tp"+n].removeMovieClip();
}
for (var i = 0; i<l0; i++) {
for (var j = 0; j<l1; j++) {
tpx[j] = 0;
tpy[j] = 0;
}
}
do {
var m = random(zbz.length);
var x = zbx.pop();
var y = zby.pop();
var z = zbz[m];
zbz.splice(m, 1);
var j = 0;
while (tpx[z-1][j] != 0) {
j++;
}
tpx[z-1][j] = x;
tpy[z-1][j] = y;
var n = x*100+y;
roots[x][y] = z;
_root.attachMovie("tp"+z, "tp"+n, n);
with (_root["tp"+n]) {
_x = x*30+25;
_y = y*30+25;
}
} while (zbz.length != 0);
ts = true;
};
for (var i = 0; i<l0; i++) {
tpx = new Array(l1);
tpy = new Array(l1);
for (var j = 0; j<l1; j++) {
tpx[j] = 0;
tpy[j] = 0;
}
}
for (var i = 0; i<22; i++) {
roots = new Array(12);
for (var j = 0; j<12; j++) {
roots[j] = 0;
}
}
for (var i = 1; i<=l0; i++) {
for (var j = 0; j<l1; j++) {
do {
var x = random(20)+1;
var y = random(10)+1;
} while (roots[x][y] != 0);
tpx[i-1][j] = x;
tpy[i-1][j] = y;
var n = x*100+y;
roots[x][y] = i;
_root.attachMovie("tp"+i, "tp"+n, n);
with (_root["tp"+n]) {
_x = x*30+25;
_y = y*30+25;
}
}
}
cls = function (mc1:MovieClip, mc2:MovieClip):Void {
ts = false;
mc1._alpha -= 20;
mc2._alpha -= 20;
lines._alpha -= 20;
if (mc1._alpha<=0) {
mc1._visible = false;
mc2._visible = false;
lines.clear();
lines._alpha = 100;
total += jl;
xq++;
ts = true;
clearInterval(clc);
Test();
}
};
Box = function (mc:MovieClip):Void {
with (mc) {
line.lineStyle(3, 0xFFFF00, 100);
line.moveTo(mc._x-13, mc._y-13);
line.lineTo(mc._x+13, mc._y-13);
line.lineTo(mc._x+13, mc._y+13);
line.lineTo(mc._x-13, mc._y+13);
line.lineTo(mc._x-13, mc._y-13);
}
};
Boxing = function (mc1:MovieClip, mc2:MovieClip):Void {
total -= cf;
with (box1) {
lineStyle(2, 0x00FF00, 100);
moveTo(-13, -13);
lineTo(13, -13);
lineTo(13, 13);
lineTo(-13, 13);
lineTo(-13, -13);
_x = mc1._x;
_y = mc1._y;
_xscale = 250;
_yscale = 250;
}
with (box2) {
lineStyle(2, 0x00FF00, 100);
moveTo(-13, -13);
lineTo(13, -13);
lineTo(13, 13);
lineTo(-13, 13);
lineTo(-13, -13);
_x = mc2._x;
_y = mc2._y;
_xscale = 250;
_yscale = 250;
}
c = setInterval(cl, 20);
};
cl = function ():Void {
box1._xscale -= 10;
box1._yscale -= 10;
box2._xscale -= 10;
box2._yscale -= 10;
if (box1._xscale<100) {
box1.clear();
box2.clear();
box1._xscale = 100;
box1._yscale = 100;
box2._xscale = 100;
box2._yscale = 100;
ts = true;
clearInterval(c);
}
};
Judge1 = function (prx:Number, pry:Number, nwx:Number, nwy:Number):Boolean {
if (nwx == prx) {
var n = pry;
var nz = roots[nwx][nwy];
var pz = roots[prx][pry];
if (nwy>pry) {
do {
n++;
} while (roots[nwx][n] == 0 && n<nwy);
} else {
do {
n--;
} while (roots[nwx][n] == 0 && n>nwy);
}
if (n == nwy) {
return true;
} else {
return false;
}
} else if (nwy == pry) {
var n = prx;
var nz = roots[nwx][nwy];
var pz = roots[prx][pry];
if (nwx>prx) {
do {
n++;
} while (roots[n][nwy] == 0 && n<nwx);
} else {
do {
n--;
} while (roots[n][nwy] == 0 && n>nwx);
}
if (n == nwx) {
return true;
} else {
return false;
}
} else {
return false;
}
};
Judge2 = function (prx:Number, pry:Number, nwx:Number, nwy:Number):Boolean {
if (Judge1(prx, pry, nwx, pry) && Judge1(nwx, pry, nwx, nwy) && roots[nwx][pry] == 0) {
cx1 = nwx;
cy1 = pry;
return true;
}
if (Judge1(prx, pry, prx, nwy) && Judge1(prx, nwy, nwx, nwy) && roots[prx][nwy] == 0) {
cx1 = prx;
cy1 = nwy;
return true;
}
return false;
};
Judge3 = function (prx:Number, pry:Number, nwx:Number, nwy:Number):Boolean {
for (var i = prx-1; ; i--) {
if (roots[pry] != 0 || i<0) {
break;
}
if (Judge2(i, pry, nwx, nwy)) {
cx2 = i;
cy2 = pry;
return true;
}
}
for (var i = prx+1; ; i++) {
if (roots[pry] != 0 || i>21) {
break;
}
if (Judge2(i, pry, nwx, nwy)) {
cx2 = i;
cy2 = pry;
return true;
}
}
for (var i = pry-1; ; i--) {
if (roots[prx] != 0 || i<0) {
break;
}
if (Judge2(prx, i, nwx, nwy)) {
cx2 = prx;
cy2 = i;
return true;
}
}
for (var i = pry+1; ; i++) {
if (roots[prx] != 0 || i>21) {
break;
}
if (Judge2(prx, i, nwx, nwy)) {
cx2 = prx;
cy2 = i;
return true;
}
}
return false;
};
_root.onMouseDown = function() {
line.clear();
var x = Math.floor((_root._xmouse-10)/30);
var y = Math.floor((_root._ymouse-10)/30);
if (x>0 && y>0 && x<21 && y<11 && roots[x][y] == 0 && zt == true) {
zt = false;
line.clear();
}
if (x>0 && y>0 && x<21 && y<11 && roots[x][y] != 0) {
if (zt == false) {
zt = true;
var n = x*100+y;
prx = x;
pry = y;
Box(_root["tp"+n]);
} else {
if (x == prx && y == pry) {
line.clear();
zt = false;
} else if (Judge1(prx, pry, x, y) && roots[x][y] == roots[prx][pry]) {
var nz = x*100+y;
var pz = prx*100+pry;
var nmc = _root["tp"+nz];
var pmc = _root["tp"+pz];
Box(nmc);
lines.lineStyle(3, 0xFF0000, 100);
lines.moveTo(nmc._x, nmc._y);
lines.lineTo(pmc._x, pmc._y);
for (var i = 0; i<l1; i++) {
if (tpx[roots[x][y]-1] == x && tpy[roots[x][y]-1] == y) {
tpx[roots[x][y]-1] = 0;
tpy[roots[x][y]-1] = 0;
break;
}
}
roots[prx][pry] = 0;
roots[x][y] = 0;
line.clear();
zt = false;
clc = setInterval(cls, 50, nmc, pmc);
} else if (Judge2(prx, pry, x, y) && roots[x][y] == roots[prx][pry]) {
var nz = x*100+y;
var pz = prx*100+pry;
var nmc = _root["tp"+nz];
var pmc = _root["tp"+pz];
Box(nmc);
lines.lineStyle(3, 0xFF0000, 100);
lines.moveTo(nmc._x, nmc._y);
lines.lineTo(cx1*30+25, cy1*30+25);
lines.lineTo(pmc._x, pmc._y);
for (var i = 0; i<l1; i++) {
if (tpx[roots[x][y]-1] == x && tpy[roots[x][y]-1] == y) {
tpx[roots[x][y]-1] = 0;
tpy[roots[x][y]-1] = 0;
break;
}
}
roots[prx][pry] = 0;
roots[x][y] = 0;
line.clear();
zt = false;
clc = setInterval(cls, 50, nmc, pmc);
} else if (Judge3(prx, pry, x, y) && roots[x][y] == roots[prx][pry]) {
var nz = x*100+y;
var pz = prx*100+pry;
var nmc = _root["tp"+nz];
var pmc = _root["tp"+pz];
Box(nmc);
lines.lineStyle(3, 0xFF0000, 100);
lines.moveTo(nmc._x, nmc._y);
lines.lineTo(cx1*30+25, cy1*30+25);
lines.lineTo(cx2*30+25, cy2*30+25);
lines.lineTo(pmc._x, pmc._y);
for (var i = 0; i<l1; i++) {
if (tpx[roots[x][y]-1] == x && tpy[roots[x][y]-1] == y) {
tpx[roots[x][y]-1] = 0;
tpy[roots[x][y]-1] = 0;
break;
}
}
roots[prx][pry] = 0;
roots[x][y] = 0;
line.clear();
zt = false;
clc = setInterval(cls, 50, nmc, pmc);
} else {
zt = true;
line.clear();
var n = x*100+y;
prx = x;
pry = y;
Box(_root["tp"+n]);
}
}
}
};
Test = function ():Boolean {
for (var i = 0; i<l0; i++) {
for (var j = 0; j<l1-1; j++) {
var prx = tpx[j];
var pry = tpy[j];
if (tpx[j] == 0 || roots[prx][pry] == 0) {
continue;
}
for (var k = j+1; k<l1 && ts; k++) {
var nwx = tpx[k];
var nwy = tpy[k];
if (tpx[k] == 0 || roots[nwx][nwy] == 0) {
continue;
}
if (Judge1(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
return true;
} else if (Judge2(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
return true;
} else if (Judge3(prx, pry, nwx, nwy) && roots[nwx][nwy] == roots[prx][pry]) {
var nz = nwx*100+nwy;
var pz = prx*100+pry;
return true;
}
}
}
}
if (xq != l0*l1/2) {
fresh();
return false;
}
};
count = function () {
if (xq != l0*l1/2) {
total--;
} else {
clearInterval(tim);
}
};
tim = setInterval(count, 1000);
jdq.onEnterFrame = function() {
if (total>500) {
total = 500;
} else if (total<0) {
total = 0;
} else {
this.jdd.setMask(this.jdu);
this.jdu._x = total-500;
this.jdt = total;
}
};
bn1.onRelease = function() {
auto();
};
bn2.onRelease = function() {
total -= cf;
fresh();
};
作者:
紫色流星
时间:
2007-4-21 09:14
标题:
变量解释:
库中共有50个30*30的电影剪辑,编号tp1—tp50;
l0:图片个数,这里有50个图片;
l1:每个图片重复次数,这里重4次;
xq:记录消去配对图案的次数;
jl:奖励分数,这里每消除一次增加5分;
cf:每次使用提示或者重新排列时减去的分数,这里是10分;
total:分数,初始值500;
roots:数组,记录整个平面的情况,二维;
tpx、tpy:数组,记录每个图片的XY坐标,就是在roots中的位置,方便自动寻找配对;
line、box1、box2、lines:分别用于画选择方块,两个提示方块和连接线的电影剪辑;
clc、tim:两个定时器;
zt、ts:两个布尔值,用于标记当前的选择状态和提示状态;
ptx、pty:用于记录前一个图片的位置;
cx1、cy1、cx2、cy2:用于记录折线的拐点位置;
作者:
紫色流星
时间:
2007-4-21 09:15
标题:
函数功能解释:
auto:没有返回值,提示并标记两个匹配图片;
fresh:没有返回值,更新方块的位置,并且不改变图片块的相对位置;
三个for循环:初始化数组和产生随机图片位置;
cls:没有返回值:将两个参数的电影剪辑逐渐消除,并且删除相对应的定时器;
Box:在所选择的图片周围画一个黄色的方框;
Boxing:在两个图片周围画绿色方框;
cl:让两个绿色方框由大到小地变化,以示提醒;
Judge1:返回值是布尔值,判断两个参数所表征的图片是否可以直接连在一起;
Judge2:返回值是布尔值,判断两个参数所表征的图片是否可以用一个折线连在一起;
Judge3:返回值是布尔值,判断两个参数所表征的图片是否可以用两个折线连在一起;
_root.onMouseDown:事件处理函数,判断鼠标选择的图片以及即时地处理;
Test:返回值是布尔值,判断当前是否有可以配对的图片;
count、tim:每秒分数减一的定时器;
jdq:分数条的事件,用于更新当前分数;
bn1、bn2:提示按钮和更新按钮。
作者:
紫色流星
时间:
2007-12-8 09:31
这么好的东西没人顶,唉
作者:
上将
时间:
2007-12-8 21:26
流星真能编,我顶你!
作者:
高西
时间:
2008-1-1 11:16
哇 代码都贴出来 呵呵
作者:
高西
时间:
2008-1-1 11:25
作者:
landysdq
时间:
2008-3-31 17:08
楼主太强了
作者:
123123feng
时间:
2008-10-10 15:29
ding~~~~~~~~~~~~~~~~~~~~~~~~~~~
欢迎光临 工程家园 (http://heubbs.cn/)
Powered by Discuz! 7.2