其中的转角的算法来自网络 这只是测试的代码 诸多不足 请指正:
--------------------------------------------------------------
class angles {
var mcolor;
var wnumber:Number = 8;
var hnumber:Number = 5;
var table:Array = new Array();
var ra:Number = int((wnumber*hnumber)/4);
var obj:MovieClip;
public function angles() {
//obj = this;
init();
//var myobj = new dutp();
}
public function init() {
var firsts:Boolean = true;
var map:Array = new Array();
var colormap:Array = new Array();
var firstColor:String;
var secondColor:String;
var firstClip:MovieClip;
var secondClip:MovieClip;
var firstNum:Number;
var secondNum:Number;
var oneline:Boolean = false;
var twoline:Boolean = false;
var parr:Array = new Array();
for (var i = 0; i<wnumber+2; i++) {
map[i] = new Array(0, 0, 0, 0, 0, 0, 0);
}
for (var i = 1; i<Number(wnumber)+1; i++) {
for (var j = 1; j<Number(hnumber)+1; j++) {
colormap[i*8+j] = 0;
var nu = random(ra);
_root.createEmptyMovieClip("obj"+(8*i+j), 8*i+j);
dutp(_root["obj"+(8*i+j)], 8*i+j);
_root["obj"+(8*i+j)]._x = i*20;
_root["obj"+(8*i+j)]._y = j*20;
map[i][j] = 1;
colormap[i*8+j] = setCol(_root["obj"+(8*i+j)], nu);
_root["obj"+(8*i+j)].onPress = function() {
if (firsts) {
var str = Number(this._name.substr(3, 3));
firstColor = colormap[str];
firstClip = eval("obj"+str);
firstNum = str;
firsts = false;
//trace(firstColor+" "+firstClip+" "+firstNum+" ");
} else {
var str = Number(this._name.substr(3, 3));
secondColor = colormap[str];
secondClip = eval("obj"+str);
secondNum = str;
//trace(secondColor+" "+secondClip+" "+secondNum+" ");
findSu();
}
};
}
}
/*
for (var i = 0; i<wnumber+2; i++) {
for (var j = 0; j<hnumber+2; j++) {
trace(map[i][j]);
}
trace("\n")
}
*/
function findSu() {
//trace(firstClip+" "+secondClip+" "+firstNum+" "+secondNum+" "+firstColor+" "+secondColor);
if (firstClip<>undefined and secondClip<>undefined and firstNum<>secondNum and firstNum<>undefined and secondNum<>undefined and (firstColor == secondColor) and firstColor<>undefined and secondColor<>undefined) {
var J = int(firstNum%8);
var I = int((firstNum-J)/8);
var JJ = int(secondNum%8);
var II = int((secondNum-JJ)/8);
var p1 = new Array(I, J);
var p2 = new Array(II, JJ);
pickpoint(p1, p2);
//trace("the p1 is "+p1)
if (linelink(p1, p2)) {
//trace(p1);
//trace(p2);
removeMovieClip(firstClip);
removeMovieClip(secondClip);
map[I][J] = 0;
map[II][JJ] = 0;
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
} else {
for (var i = 0; i<parr.length; i++) {
for (var j = 0; j<parr.length; j++) {
if (linelink(p1, parr[i]) && linelink(p2, parr[j]) && linelink(parr[i], parr[j])) {
removeMovieClip(firstClip);
removeMovieClip(secondClip);
map[I][J] = 0;
map[II][JJ] = 0;
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
}
}
}
}
} else {
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
}
}
function linelink(o1, o2) {
var t = new Array(0, 0);
//trace("it'is run")
if (o1[0] == o2[0] || o1[1] == o2[1]) {
if (Math.abs(o1[0]-o2[0])+Math.abs(o1[1]-o2[1])<=1) {
return true;
//trace("it'as run");
} else {
t[0] = isNaN((o2[0]-o1[0])/Math.abs(o2[0]-o1[0])) ? o1[0] : o1[0]+((o2[0]-o1[0])/Math.abs(o2[0]-o1[0]));
t[1] = isNaN((o2[1]-o1[1])/Math.abs(o2[1]-o1[1])) ? o1[1] : o1[1]+((o2[1]-o1[1])/Math.abs(o2[1]-o1[1]));
return map[t[0]][t[1]] == 0 ? linelink(t, o2) : false;
}
} else {
return false;
}
}
function pickpoint(q1, q2) {
var j;
//var parr:Array = new Array();
parr.splice(0);
for (j=0; j<map[q1[0]].length; j++) {
parr = map[q1[0]][j] == 0 ? parr.concat([[q1[0], j]]) : parr;
}
for (j=0; j<map[q2[0]].length; j++) {
parr = map[q2[0]][j] == 0 ? parr.concat([[q2[0], j]]) : parr;
}
for (j=0; j<map.length; j++) {
parr = map[j][q1[1]] == 0 ? parr.concat([[j, q1[1]]]) : parr;
}
for (j=0; j<map.length; j++) {
parr = map[j][q2[1]] == 0 ? parr.concat([[j, q2[1]]]) : parr;
}
}
}
public function dutp(obj) {
//obj.createEmptyMovieClip("thedutp", 2323);
with (obj) {
lineStyle(1, 0xffffff, 100);
beginFill(0x000000, 100);
lineTo(20, 0);
lineTo(20, 20);
lineTo(0, 20);
lineTo(0, 0);
endFill();
}
//return obj
}
public function setCol(obj:MovieClip, ran:Number) {
var mycolor = new Color(obj);
//trace(ran)
switch (ran) {
case 0 :
mycolor.setRGB(0x000000);
return mycolor.getRGB().toString(16);
break;
case 1 :
mycolor.setRGB(0x111aaa);
return mycolor.getRGB().toString(16);
break;
case 2 :
mycolor.setRGB(0x555ccc);
return mycolor.getRGB().toString(16);
break;
case 3 :
mycolor.setRGB(0x222aaa);
return mycolor.getRGB().toString(16);
break;
case 4 :
mycolor.setRGB(0xbbbeee);
return mycolor.getRGB().toString(16);
break;
case 5 :
mycolor.setRGB(0x009911);
return mycolor.getRGB().toString(16);
break;
case 6 :
mycolor.setRGB(0x00ff00);
return mycolor.getRGB().toString(16);
break;
case 7 :
mycolor.setRGB(0x00cc0f);
return mycolor.getRGB().toString(16);
break;
case 8 :
mycolor.setRGB(0xf00099);
return mycolor.getRGB().toString(16);
break;
case 9 :
mycolor.setRGB(0xff9900);
return mycolor.getRGB().toString(16);
break;
}
//
//
}
}
--------------------------------------------------------------
class angles {
var mcolor;
var wnumber:Number = 8;
var hnumber:Number = 5;
var table:Array = new Array();
var ra:Number = int((wnumber*hnumber)/4);
var obj:MovieClip;
public function angles() {
//obj = this;
init();
//var myobj = new dutp();
}
public function init() {
var firsts:Boolean = true;
var map:Array = new Array();
var colormap:Array = new Array();
var firstColor:String;
var secondColor:String;
var firstClip:MovieClip;
var secondClip:MovieClip;
var firstNum:Number;
var secondNum:Number;
var oneline:Boolean = false;
var twoline:Boolean = false;
var parr:Array = new Array();
for (var i = 0; i<wnumber+2; i++) {
map[i] = new Array(0, 0, 0, 0, 0, 0, 0);
}
for (var i = 1; i<Number(wnumber)+1; i++) {
for (var j = 1; j<Number(hnumber)+1; j++) {
colormap[i*8+j] = 0;
var nu = random(ra);
_root.createEmptyMovieClip("obj"+(8*i+j), 8*i+j);
dutp(_root["obj"+(8*i+j)], 8*i+j);
_root["obj"+(8*i+j)]._x = i*20;
_root["obj"+(8*i+j)]._y = j*20;
map[i][j] = 1;
colormap[i*8+j] = setCol(_root["obj"+(8*i+j)], nu);
_root["obj"+(8*i+j)].onPress = function() {
if (firsts) {
var str = Number(this._name.substr(3, 3));
firstColor = colormap[str];
firstClip = eval("obj"+str);
firstNum = str;
firsts = false;
//trace(firstColor+" "+firstClip+" "+firstNum+" ");
} else {
var str = Number(this._name.substr(3, 3));
secondColor = colormap[str];
secondClip = eval("obj"+str);
secondNum = str;
//trace(secondColor+" "+secondClip+" "+secondNum+" ");
findSu();
}
};
}
}
/*
for (var i = 0; i<wnumber+2; i++) {
for (var j = 0; j<hnumber+2; j++) {
trace(map[i][j]);
}
trace("\n")
}
*/
function findSu() {
//trace(firstClip+" "+secondClip+" "+firstNum+" "+secondNum+" "+firstColor+" "+secondColor);
if (firstClip<>undefined and secondClip<>undefined and firstNum<>secondNum and firstNum<>undefined and secondNum<>undefined and (firstColor == secondColor) and firstColor<>undefined and secondColor<>undefined) {
var J = int(firstNum%8);
var I = int((firstNum-J)/8);
var JJ = int(secondNum%8);
var II = int((secondNum-JJ)/8);
var p1 = new Array(I, J);
var p2 = new Array(II, JJ);
pickpoint(p1, p2);
//trace("the p1 is "+p1)
if (linelink(p1, p2)) {
//trace(p1);
//trace(p2);
removeMovieClip(firstClip);
removeMovieClip(secondClip);
map[I][J] = 0;
map[II][JJ] = 0;
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
} else {
for (var i = 0; i<parr.length; i++) {
for (var j = 0; j<parr.length; j++) {
if (linelink(p1, parr[i]) && linelink(p2, parr[j]) && linelink(parr[i], parr[j])) {
removeMovieClip(firstClip);
removeMovieClip(secondClip);
map[I][J] = 0;
map[II][JJ] = 0;
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
}
}
}
}
} else {
firstColor = undefined;
secondColor = undefined;
firstNum = undefined;
secondNum = undefined;
firstClip = undefined;
secondClip = undefined;
firsts = true;
}
}
function linelink(o1, o2) {
var t = new Array(0, 0);
//trace("it'is run")
if (o1[0] == o2[0] || o1[1] == o2[1]) {
if (Math.abs(o1[0]-o2[0])+Math.abs(o1[1]-o2[1])<=1) {
return true;
//trace("it'as run");
} else {
t[0] = isNaN((o2[0]-o1[0])/Math.abs(o2[0]-o1[0])) ? o1[0] : o1[0]+((o2[0]-o1[0])/Math.abs(o2[0]-o1[0]));
t[1] = isNaN((o2[1]-o1[1])/Math.abs(o2[1]-o1[1])) ? o1[1] : o1[1]+((o2[1]-o1[1])/Math.abs(o2[1]-o1[1]));
return map[t[0]][t[1]] == 0 ? linelink(t, o2) : false;
}
} else {
return false;
}
}
function pickpoint(q1, q2) {
var j;
//var parr:Array = new Array();
parr.splice(0);
for (j=0; j<map[q1[0]].length; j++) {
parr = map[q1[0]][j] == 0 ? parr.concat([[q1[0], j]]) : parr;
}
for (j=0; j<map[q2[0]].length; j++) {
parr = map[q2[0]][j] == 0 ? parr.concat([[q2[0], j]]) : parr;
}
for (j=0; j<map.length; j++) {
parr = map[j][q1[1]] == 0 ? parr.concat([[j, q1[1]]]) : parr;
}
for (j=0; j<map.length; j++) {
parr = map[j][q2[1]] == 0 ? parr.concat([[j, q2[1]]]) : parr;
}
}
}
public function dutp(obj) {
//obj.createEmptyMovieClip("thedutp", 2323);
with (obj) {
lineStyle(1, 0xffffff, 100);
beginFill(0x000000, 100);
lineTo(20, 0);
lineTo(20, 20);
lineTo(0, 20);
lineTo(0, 0);
endFill();
}
//return obj
}
public function setCol(obj:MovieClip, ran:Number) {
var mycolor = new Color(obj);
//trace(ran)
switch (ran) {
case 0 :
mycolor.setRGB(0x000000);
return mycolor.getRGB().toString(16);
break;
case 1 :
mycolor.setRGB(0x111aaa);
return mycolor.getRGB().toString(16);
break;
case 2 :
mycolor.setRGB(0x555ccc);
return mycolor.getRGB().toString(16);
break;
case 3 :
mycolor.setRGB(0x222aaa);
return mycolor.getRGB().toString(16);
break;
case 4 :
mycolor.setRGB(0xbbbeee);
return mycolor.getRGB().toString(16);
break;
case 5 :
mycolor.setRGB(0x009911);
return mycolor.getRGB().toString(16);
break;
case 6 :
mycolor.setRGB(0x00ff00);
return mycolor.getRGB().toString(16);
break;
case 7 :
mycolor.setRGB(0x00cc0f);
return mycolor.getRGB().toString(16);
break;
case 8 :
mycolor.setRGB(0xf00099);
return mycolor.getRGB().toString(16);
break;
case 9 :
mycolor.setRGB(0xff9900);
return mycolor.getRGB().toString(16);
break;
}
//
//
}
}
回复Comments
作者:
{commentrecontent}