Commit ba58cb0f authored by zjz1994's avatar zjz1994

减少大炮的遍历

parent 241e286d
...@@ -325,6 +325,8 @@ export default class MainScene extends Scene { ...@@ -325,6 +325,8 @@ export default class MainScene extends Scene {
// cannoArr:Array<{idx:number,ele:Element}> = []; // cannoArr:Array<{idx:number,ele:Element}> = [];
//本地图炮台总数 //本地图炮台总数
cannonums:number = 0; cannonums:number = 0;
//新增调整
cannoidxArr:Array<number> = [];
//每个炮台对应的特效 //每个炮台对应的特效
cannoEffect:Array<any> = []; cannoEffect:Array<any> = [];
//准备发射的炮台 //准备发射的炮台
...@@ -643,8 +645,9 @@ export default class MainScene extends Scene { ...@@ -643,8 +645,9 @@ export default class MainScene extends Scene {
//该遍历之后尽量简化下todo //该遍历之后尽量简化下todo
getCannoByBianhao(cannoidx:number):Element{ getCannoByBianhao(cannoidx:number):Element{
var canno:Element; var canno:Element;
for(var i=0;i<this.lattices.length;i++){ // console.log("获取大炮",cannoidx,this.cannoidxArr);
var ilattice = this.lattices[i]; for(var i=0;i<this.cannoidxArr.length;i++){
var ilattice = this.lattices[this.cannoidxArr[i]];
if(ilattice&&ilattice.element&&ilattice.element.type==ElementType.CANNO){ if(ilattice&&ilattice.element&&ilattice.element.type==ElementType.CANNO){
var icannobianhao = ilattice.element.cannobianhao; var icannobianhao = ilattice.element.cannobianhao;
if(cannoidx==icannobianhao){ if(cannoidx==icannobianhao){
...@@ -653,6 +656,17 @@ export default class MainScene extends Scene { ...@@ -653,6 +656,17 @@ export default class MainScene extends Scene {
} }
} }
} }
// for(var i=0;i<this.lattices.length;i++){
// var ilattice = this.lattices[i];
// if(ilattice&&ilattice.element&&ilattice.element.type==ElementType.CANNO){
// var icannobianhao = ilattice.element.cannobianhao;
// if(cannoidx==icannobianhao){
// canno = ilattice.element;
// break;
// }
// }
// }
return canno; return canno;
} }
listenCnlight(e){ listenCnlight(e){
...@@ -1214,6 +1228,7 @@ export default class MainScene extends Scene { ...@@ -1214,6 +1228,7 @@ export default class MainScene extends Scene {
}) })
} }
this.cannonums += 1; this.cannonums += 1;
this.cannoidxArr.push(i);
//给大炮附加发射等特效 //给大炮附加发射等特效
this.initCannoSvgas(canno,cannobianhao); this.initCannoSvgas(canno,cannobianhao);
break; break;
......
...@@ -109,7 +109,17 @@ const changeData = function(worms:number[],thisObj:MainScene){ ...@@ -109,7 +109,17 @@ const changeData = function(worms:number[],thisObj:MainScene){
while(inidx<wormsleng){ while(inidx<wormsleng){
let hmapdata = getMapsp(ihlattice); let hmapdata = getMapsp(ihlattice);
let heledata = getElesp(ihlattice); let heledata = getElesp(ihlattice);
if(foreledata.ele&&foreledata.eledata["type"]==ElementType.CANNO){//重设mainscene的数组
var startidx = ilattice.index;
var toidx = ihlattice.index;
for(var c=0;c<thisObj.cannoidxArr.length;c++){
var cidx = thisObj.cannoidxArr[c];
if(cidx==startidx){
thisObj.cannoidxArr[c] = toidx;
c = thisObj.cannoidxArr.length;
}
}
}
ihlattice.changeData(formapdata,foreledata); ihlattice.changeData(formapdata,foreledata);
formapdata = hmapdata; formapdata = hmapdata;
...@@ -127,6 +137,14 @@ const changeData = function(worms:number[],thisObj:MainScene){ ...@@ -127,6 +137,14 @@ const changeData = function(worms:number[],thisObj:MainScene){
ilattice = thisObj.lattices[iwormholeidx]; ilattice = thisObj.lattices[iwormholeidx];
ihlattice = thisObj.lattices[ilwormholeidx]; ihlattice = thisObj.lattices[ilwormholeidx];
} }
var cannobianArr:Array<number> = [];
for(var j=0;j<thisObj.cannoidxArr.length;j++){
var jcannoidx = thisObj.cannoidxArr[j];
var jcannoele = thisObj.lattices[jcannoidx].element;
cannobianArr.push(jcannoele.cannobianhao);
}
// console.log("单线交换完毕",thisObj.cannoidxArr,cannobianArr);
// console.log("本条线数据交换完毕"); // console.log("本条线数据交换完毕");
} }
export default async (thisObj:MainScene)=>{ export default async (thisObj:MainScene)=>{
......
...@@ -12,7 +12,7 @@ export const Chapters25: ChapterData[] = [ ...@@ -12,7 +12,7 @@ export const Chapters25: ChapterData[] = [
starScores: [ 15000, 20000, 25000 ], starScores: [ 15000, 20000, 25000 ],
map: { map: {
lattices: [ lattices: [
1, 6, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
...@@ -52,14 +52,14 @@ export const Chapters25: ChapterData[] = [ ...@@ -52,14 +52,14 @@ export const Chapters25: ChapterData[] = [
// [ 72, 53 ] // [ 72, 53 ]
// ], // ],
elements: [ elements: [
1, 16, 1, 1, 1, 1, 1, 1, 16, 1, 19, 1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 20, 1, 1, 1, 1, 1, 1, 1,
1, 1, 16, 1, 1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 1, 1, 1, 1,
1, 1, 1, 14, 1, 1, 9, 1, 1, 1, 1, 1, 14, 1, 1, 9, 1, 22,
1, 1, 1, 1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1, 1, 1, 1, 1
], ],
baseElements: [ baseElements: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment