123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887 |
- import CellModel from "./CellModel";
- import {mergePointArray,exclusivePoint} from "../Utils/ModelUtils";
- import {ANITIME, CELL_BASENUM, CELL_STATUS, CELL_TYPE, GRID_HEIGHT, GRID_WIDTH} from "./ConstValue";
- export default class GameModel {
- constructor() {
- this.cells = null;
- this.cellBgs = null;
- this.lastPos = cc.v2(-1,-1);
- this.cellTypeNum = 5;
- this.cellCreateType = []; //生成种类只在这个数组里面查找
- this.crushNums = 0; //消除的块数
- // this.curGridPos = {};
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- }
- init(cellTypeNum){
- this.gridView = cc.find("Canvas/GameScene/Grid").getComponent("GridView")
- // console.log("gridView.width:",this.gridView.grid_width)
- this.cells = [];
- this.setCellTypeNum(cellTypeNum || this.cellTypeNum);
- for (let i = 1; i <= this.gridView.grid_width; i++){
- this.cells[i] = [];
- for (let j = 1; j <= this.gridView.grid_height; j++){
- this.cells[i][j] = new CellModel()
- }
- }
- //this.mock()
- for (let i = 1; i <= this.gridView.grid_width; i++){
- for (let j = 1; j <= this.gridView.grid_height; j++){
- //已经被mock数据生成了
- if (this.cells[i][j].type != null){
- continue;
- }
- let flag = true;
- while (flag){
- flag = false;
- this.cells[i][j].init(this.getRandomCellType());
- let result = this.checkPoint(j, i)[0];
- if (result.length > 2){
- flag = true;
- }
- this.cells[i][j].setXY(j, i);
- this.cells[i][j].setStartXY(j, i);
- }
- }
- }
- }
- mock(){
- this.mockInit(5,1,CELL_TYPE.A);
- this.mockInit(5,3,CELL_TYPE.A);
- this.mockInit(4,2,CELL_TYPE.A);
- this.mockInit(3,2,CELL_TYPE.A);
- this.mockInit(5,2,CELL_TYPE.B);
- this.mockInit(6,2,CELL_TYPE.B);
- this.mockInit(7,3,CELL_TYPE.B);
- this.mockInit(8,2,CELL_TYPE.A);
- // this.mockInit(1, 1, CELL_TYPE.A);
- // this.mockInit(1, 2, CELL_TYPE.A);
- // this.mockInit(1, 3, CELL_TYPE.A);
- // this.mockInit(1, 5, CELL_TYPE.A);
- // this.mockInit(2, 1, CELL_TYPE.B);
- // this.mockInit(2, 2, CELL_TYPE.B);
- // this.mockInit(2, 3, CELL_TYPE.B);
- // this.mockInit(2, 5, CELL_TYPE.B);
- // this.mockInit(3, 4, CELL_TYPE.A);
- // this.mockInit(4, 4, CELL_TYPE.A);
- // console.log("mock")
- }
- mockInit(x, y, type){
- this.cells[x][y].init(type);
- this.cells[x][y].setXY(y, x);
- this.cells[x][y].setStartXY(y, x);
- }
- /**
- *
- * @param x
- * @param y
- * @param recursive 是否递归查找
- * @returns {([]|string|*)[]}
- */
- checkPoint(x, y, recursive){
- // console.log("递归了x",x)
- // console.log("递归了y",y)
- let rowResult = this.checkWithDirection(x, y, [cc.v2(1,0),cc.v2(-1,0)]);
- let colResult = this.checkWithDirection(x, y, [cc.v2(0,-1),cc.v2(0,1)]);
- let samePoints = [];
- let newCellStatus = "";
- if (rowResult.length >= 5 || colResult.length >= 5){
- //任意五个'同行'或'同列'且相同的动物可以合成一个'魔力鸟'特效
- newCellStatus = CELL_STATUS.BIRD;
- }else if (rowResult.length >= 3 && colResult.length >= 3){
- //五个相同的'不同行'动物可以合成一个'爆炸特效'
- newCellStatus = CELL_STATUS.WRAP;
- }else if (rowResult.length >= 4){
- //四个相同的动物一行可以合成一个行直线特效
- newCellStatus = CELL_STATUS.LINE;
- }else if (colResult.length >= 4){
- //四个相同的动物一列可以合成一个列直线特效
- newCellStatus = CELL_STATUS.COLUMN;
- }
- if (rowResult.length >= 3){
- samePoints = rowResult;
- }
- if (colResult.length >= 3){
- samePoints = mergePointArray(samePoints, colResult);
- }
- let result = [samePoints, newCellStatus, this.cells[y][x].type, cc.v2(x, y)];
- //检查一下消除的其他节点, 能不能生成更大范围的消除
- if (recursive && result.length >= 3){
- let subCheckPoints = exclusivePoint(samePoints, cc.v2(x, y));
- for (let point of subCheckPoints){
- let subResult = this.checkPoint(point.x, point.y, false);
- if (subResult[1] > result[1] || (subResult[1] === result[1] && subResult[0].length > result[0].length)){
- result = subResult;
- }
- }
- }
- return result;
- }
- checkWithDirection(x, y, direction){
- //x是行,y是列
- let queue = [];
- let vis = [];
- vis[x + y * this.gridView.grid_height] = true; //9是行
- queue.push(cc.v2(x, y)); //x是行,y是列,生成的队列是按列从左往右
- let front = 0;
- while (front < queue.length){
- let point = queue[front];
- let cellModel = this.cells[point.y][point.x]; //point.y是行,point.x是列
- // console.log(`this.cells[point.${y}][point.${x}]:`,this.cells[point.y][point.x])
- front++;
- if (!cellModel){
- continue;
- }
- for (let i = 0; i < direction.length; i++){
- let tmpX = point.x + direction[i].x;
- let tmpY = point.y + direction[i].y;
- // console.log(`tmpX[${i}]:`,tmpX)
- // console.log(`tmpY[${i}]:`,tmpY)
- if (tmpX < 1 || tmpX > this.gridView.grid_width //9是行
- || tmpY < 1 || tmpY > this.gridView.grid_height
- || vis[tmpX + tmpY * this.gridView.grid_height]
- || !this.cells[tmpY][tmpX]){
- continue;
- }
- // console.log(`this.cells[${tmpY}][${tmpX}]`,this.cells[tmpY][tmpX])
- if (cellModel.type === this.cells[tmpY][tmpX].type){
- vis[tmpX + tmpY * this.gridView.grid_height] = true;
- queue.push(cc.v2(tmpX, tmpY));
- // console.log("cc.v2(tmpX, tmpY):",cc.v2(tmpX, tmpY))
- }
- }
- }
- return queue;
- }
- printInfo(){
- // console.log("gridView.width2:",this.gridView.grid_width)
- for (let i = 1; i <= this.gridView.grid_height; i++){
- let printStr = "";
- for (let j = 1; j <= this.gridView.grid_width; j++){
- printStr += this.cells[i][j].type + " ";
- }
- console.log("printStr:",printStr);
- }
- }
- getCells(){
- return this.cells;
- }
- //controller调用的主要入口
- //点击某个格子
- selectCell(pos){
- this.crushNums = 0;
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- // console.log("当前点击的位置:",pos);
- // this.curGridPos = pos;
- // console.log("当前点击对象:",this.curGridPos)
- this.changeModels = []; //发生改变的model,将作为返回值,给View播动作
- this.effectsQueue = []; //动物消失、爆炸等特效
- let lastPos = this.lastPos;
- let delta = Math.abs(pos.x - lastPos.x) + Math.abs(pos.y - lastPos.y);
- // console.log("x轴:",Math.abs(pos.x - lastPos.x))
- // console.log("y轴:",Math.abs(pos.y - lastPos.y))
- // console.log("delta:",delta)
- if (delta != 1){ //非相邻格子,直接返回
- this.lastPos = pos;
- return [[], []];
- }
- let curClickCell = this.cells[pos.y][pos.x]; //当前点击的格子
- let lastClickCell = this.cells[lastPos.y][lastPos.x]; //上一次点击的格子
- this.exchangeCell(lastPos, pos);
- let result1 = this.checkPoint(pos.x, pos.y)[0];
- let result2 = this.checkPoint(lastPos.x, lastPos.y)[0];
- this.curTime = 0; //动画播放的当前时间
- this.pushToChangeModels(curClickCell);
- this.pushToChangeModels(lastClickCell);
- let isCanBomb = (curClickCell.status != CELL_STATUS.COMMON && //判断两个是否是特殊的动物
- lastClickCell.status != CELL_STATUS.COMMON) ||
- curClickCell.status == CELL_STATUS.BIRD ||
- lastClickCell.status == CELL_STATUS.BIRD;
- isCanBomb = curClickCell.status == CELL_STATUS.BIRD || lastClickCell.status == CELL_STATUS.BIRD;
- if (result1.length < 3 && result2.length < 3 && !isCanBomb){ //不会发生消除的情况
- this.exchangeCell(lastPos, pos);
- curClickCell.moveToAndBack(lastPos);
- lastClickCell.moveToAndBack(pos);
- this.lastPos = cc.v2(-1,-1);
- return [this.changeModels];
- }else {
- // console.log("消除了")
- this.lastPos = cc.v2(-1,-1);
- curClickCell.moveTo(lastPos, this.curTime);
- lastClickCell.moveTo(pos, this.curTime);
- let checkPoint = [pos, lastPos];
- // console.log("select的checkpoint:",checkPoint)
- this.curTime += ANITIME.TOUCH_MOVE;
- this.processCrush(checkPoint);
- return [this.changeModels,this.effectsQueue];
- }
- }
- //消除
- processCrush(checkPoint){
- // console.log("消除checkpoint:",checkPoint)
- let cycleCount = 0;
- while (checkPoint.length > 0){
- let bombModels = [];
- if (cycleCount == 0 && checkPoint.length == 2){ //特殊消除
- let pos1 = checkPoint[0];
- let pos2 = checkPoint[1];
- let model1 = this.cells[pos1.y][pos1.x];
- let model2 = this.cells[pos2.y][pos2.x];
- if (model1.status == CELL_STATUS.BIRD || model2.status == CELL_STATUS.BIRD){
- let bombModel = null;
- if (model1.status == CELL_STATUS.BIRD){
- model1.type = model2.type;
- bombModels.push(model1);
- }else {
- model2.type = model1.type;
- bombModels.push(model2);
- }
- }
- }
- for (let i in checkPoint){
- let pos = checkPoint[i];
- // console.log("消除中的pos:",pos)
- if (!this.cells[pos.y][pos.x]){
- continue;
- }
- let [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(pos.x,pos.y,true);
- // console.log("result:",result)
- if (result.length < 3){
- continue;
- }
- for (let j in result){
- // console.log("result[" + j +"]:",result[j])
- let model = this.cells[result[j].y][result[j].x];
- this.crushCell(result[j].x, result[j].y,false, cycleCount);
- if (model.status != CELL_STATUS.COMMON){
- bombModels.push(model);
- }
- }
- this.createNewCell(crushPoint, newCellStatus, newCellType);
- // if (result.length >= 3){
- // for (let i = 0; i < result.length; i++){
- // console.log("result[" + i +"]:",result[i])
- // }
- // }
- }
- this.processBomb(bombModels,cycleCount);
- this.curTime += ANITIME.DIE;
- checkPoint = this.down();
- // console.log("cccheckPoint:",checkPoint)
- // console.log("this.down:",this.down())
- cycleCount++;
- }
- // console.log("消除块数:",this.crushNums)
- // console.log("bear:",this.targetOneTypeNum)
- const playTime = this.effectsQueue[this.effectsQueue.length - 1]["playTime"]
- // console.log("playTime:",playTime)
- //按类型消除
- // this.addCrushNums(playTime,cc.v2(0,0),this.crushNums,this.targetOneTypeNum,this.targetTwoTypeNum,this.targetThreeTypeNum);
- //不按类型消除
- this.addCrushNums(playTime,cc.v2(0,0),this.crushNums);
- }
- //道具消除一个块
- processCrushOne(pos){
- // console.log("gridView.width3:",this.gridView.grid_width)
- // console.log("gmpos:",pos)
- this.changeModels = [];
- this.effectsQueue = [];
- this.curTime = 0;
- this.crushNums = 0;
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- //移除脚本信息
- this.crushCell(pos.x,pos.y,false,0);
- //下落
- this.down();
- // let [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(pos.x,pos.y,true);
- // console.log("oneResult:",result)
- // this.processCrush(result)
- // this.processCrush(this.checkPoint(pos.x,pos.y,true))
- let onceArray = [];
- for (let i = 1;i <= this.gridView.grid_width; i++){
- // console.log(i)
- for (let j = 1;j <= this.gridView.grid_height; j++){
- var [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(i,j,true);
- // console.log("oneResult["+i+"]["+j+"]:",result)
- if (result.length > 0){
- // console.log("if的result:",result)
- // this.processCrush(result)
- onceArray = mergePointArray(onceArray,result)
- }
- }
- }
- this.processCrush(onceArray)
- //渲染
- return [this.changeModels,this.effectsQueue];
- }
- // 道具消除整行
- processCrushRow(pos){
- // console.log("gridView.width4:",this.gridView.grid_width)
- // console.log("pcr:",pos)
- // console.log("pcr:",pos.y)
- this.changeModels = [];
- this.effectsQueue = [];
- this.curTime = 0;
- this.crushNums = 0;
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- //循环点击的行的每个格子
- for (let i = 1; i <= this.gridView.grid_width; i++){
- // this.crushCell(i,pos.y,false,0)
- this.crushRow(i,pos.y,false,0)
- // this.addRowCrush(this.curTime,cc.v2(i,pos.y))
- // this.down();
- }
- //下落
- this.down();
- //定义空数组,用于记录消除整行后还能继续消除的元素
- let onceArray = [];
- //新格子下落后,再重新循环查找能消除的元素
- for (let i = 1;i <= this.gridView.grid_width; i++){
- // console.log(i)
- for (let j = 1;j <= this.gridView.grid_height; j++){
- var [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(i,j,true);
- // console.log("oneResult["+i+"]["+j+"]:",result)
- //如果找到能消除的元素,则合并到定义的数组里面
- if (result.length > 0){
- onceArray = mergePointArray(onceArray,result)
- }
- }
- }
- //调用消除事件,执行消除
- this.processCrush(onceArray)
- //渲染
- return [this.changeModels,this.effectsQueue];
- }
- //道具消除整列
- processCrushCol(pos){
- // console.log("gridView.width5:",this.gridView.grid_width)
- // console.log("消除列的pos:",pos)
- this.changeModels = [];
- this.effectsQueue = [];
- this.curTime = 0;
- this.crushNums = 0;
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- //循环点击的列的每个格子
- for (let i = 1; i <= this.gridView.grid_width; i++){
- this.crushCol(pos.x,i,false,0)
- }
- //下落
- this.down();
- //定义空数组,用于记录消除整列后还能继续消除的元素
- let onceArray = [];
- //新格子下落后,再重新循环查找能消除的元素
- for (let i = 1;i <= this.gridView.grid_width; i++){
- for (let j = 1;j <= this.gridView.grid_height; j++){
- var [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(i,j,true);
- // console.log("oneResult["+i+"]["+j+"]:",result)
- //如果找到能消除的元素,则合并到定义的数组里面
- if (result.length > 0){
- onceArray = mergePointArray(onceArray,result)
- }
- }
- }
- //调用消除事件,执行消除
- this.processCrush(onceArray)
- //渲染
- return [this.changeModels,this.effectsQueue];
- }
- //道具消除一种类型的格子
- processCrushOneType(pos){
- // console.log("gridView.width6:",this.gridView.grid_width)
- let nowAllCells = this.getCells();
- this.changeModels = [];
- this.effectsQueue = [];
- this.curTime = 0;
- this.crushNums = 0;
- // this.targetOneTypeNum = 0;
- // this.targetTwoTypeNum = 0;
- // this.targetThreeTypeNum = 0;
- let tempModel = [];
- let curType = null;
- //两层循环,找出当前点击格子的类型
- for (let i = 1; i < nowAllCells.length; i++){
- if ( i == pos.y){
- // console.log("ii:",i)
- for (let j = 1; j < nowAllCells[i].length; j++){
- // console.log("nowAllCell["+i+"]"+"["+j+"]:",nowAllCells[i][j])
- // console.log("jj:",j)
- if (j == pos.x){
- // console.log("点击的单元格:",nowAllCells[i][j])
- curType = nowAllCells[i][j].type
- break;
- }
- }
- break;
- }
- }
- //再次两层循环,找出与点击格子类型相同的所有格子
- for (let i = 1; i < nowAllCells.length; i++){
- for (let j = 1; j < nowAllCells[i].length; j++){
- // console.log("nowAllCell["+i+"]"+"["+j+"]:",nowAllCells[i][j])
- // console.log("类型:",nowAllCells[i][j].type)
- if (nowAllCells[i][j].type == curType){
- tempModel.push(nowAllCells[i][j])
- // console.log("ok")
- this.crushOneType(j,i,false,0)
- }
- }
- }
- this.changeModels = tempModel;
- // console.log("重新赋值的changeModels:",this.changeModels)
- //下落
- this.down();
- let onceArray = [];
- //新格子下落后,再重新循环查找能消除的元素
- for (let i = 1;i <= this.gridView.grid_width; i++){
- // console.log(i)
- for (let j = 1;j <= this.gridView.grid_height; j++){
- var [result, newCellStatus, newCellType, crushPoint] = this.checkPoint(i,j,true);
- // console.log("oneResult["+i+"]["+j+"]:",result)
- //如果找到能消除的元素,则合并到定义的数组里面
- if (result.length > 0){
- onceArray = mergePointArray(onceArray,result)
- }
- }
- }
- //调用消除事件,执行消除
- this.processCrush(onceArray)
- //渲染
- return [this.changeModels,this.effectsQueue];
- }
- //生成新cell
- createNewCell(pos, status, type){
- if (status == ""){
- return;
- }
- if (status == CELL_STATUS.BIRD){
- type = CELL_TYPE.BIRD;
- }
- let model = new CellModel();
- this.cells[pos.y][pos.x] = model;
- model.init(type);
- model.setStartXY(pos.x, pos.y);
- model.setXY(pos.x, pos.y);
- model.setStatus(status);
- model.setVisible(0, false);
- model.setVisible(this.curTime, true);
- this.changeModels.push(model);
- }
- //下落
- down(){
- // console.log("gridView.width7:",this.gridView.grid_width)
- let newCheckPoint = [];
- for (let i = 1; i <= this.gridView.grid_width; i++){
- for (let j = 1; j <= this.gridView.grid_height; j++){
- //找到空位
- if (this.cells[i][j] == null){
- let curRow = i;
- //往上找方块
- for (let k = curRow; k <= this.gridView.grid_height; k++){
- //找到可用的方块
- if (this.cells[k][j]){
- // console.log("下落:",this.cells[k][j])
- this.pushToChangeModels(this.cells[k][j]);
- newCheckPoint.push(this.cells[k][j]);
- this.cells[curRow][j] = this.cells[k][j];
- this.cells[k][j] = null;
- this.cells[curRow][j].setXY(j, curRow);
- this.cells[curRow][j].moveTo(cc.v2(j, curRow), this.curTime);
- curRow++;
- }
- }
- let count = 1;
- for (let k = curRow; k <= this.gridView.grid_height; k++){
- this.cells[k][j] = new CellModel();
- this.cells[k][j].init(this.getRandomCellType());
- this.cells[k][j].setStartXY(j, count + this.gridView.grid_height);
- this.cells[k][j].setXY(j, count + this.gridView.grid_height);
- this.cells[k][j].moveTo(cc.v2(j, k), this.curTime);
- count++;
- this.changeModels.push(this.cells[k][j]);
- newCheckPoint.push(this.cells[k][j]);
- // console.log("xialuo")
- }
- // console.log("下落的newCheckPoint:",newCheckPoint)
- }
- }
- }
- this.curTime += ANITIME.TOUCH_MOVE + 0.3;
- return newCheckPoint;
- }
- pushToChangeModels(model){
- if (this.changeModels.indexOf(model) != -1){
- return;
- }
- this.changeModels.push(model);
- }
- cleanCmd(){
- // console.log("gridView.width8:",this.gridView.grid_width)
- for (let i = 1; i <= this.gridView.grid_width; i++){
- for (let j = 1; j <= this.gridView.grid_height; j++){
- if (this.cells[i][j]){
- this.cells[i][j].cmd = [];
- }
- }
- }
- }
- exchangeCell(pos1, pos2){
- let tmpModel = this.cells[pos1.y][pos1.x];
- this.cells[pos1.y][pos1.x] = this.cells[pos2.y][pos2.x];
- this.cells[pos1.y][pos1.x].x = pos1.x;
- this.cells[pos1.y][pos1.x].y = pos1.y;
- this.cells[pos2.y][pos2.x] = tmpModel;
- this.cells[pos2.y][pos2.x].x = pos2.x;
- this.cells[pos2.y][pos2.x].y = pos2.y;
- }
- //设置种类
- //改成乱序算法
- setCellTypeNum(num){
- // console.log("num = ",num);
- this.cellTypeNum = num;
- this.cellCreateType = [];
- let createTypeList = this.cellCreateType;
- for (let i = 1; i <= CELL_BASENUM; i++){
- createTypeList.push(i);
- }
- for (let i = 0; i < createTypeList.length; i++){
- let index = Math.floor(Math.random() * (CELL_BASENUM - i)) + i;
- createTypeList[i],createTypeList[index] = createTypeList[index],createTypeList[i];
- }
- }
- //随机生成一个类型
- getRandomCellType(){
- let index = Math.floor(Math.random() * this.cellTypeNum);
- // console.log(index)
- return this.cellCreateType[index];
- }
- //bombModels去重
- processBomb(bombModels, cycleCount){
- // console.log("gridView.width9:",this.gridView.grid_width)
- // console.log("去重")
- // console.log("bombModels:",bombModels)
- while (bombModels.length > 0){
- let newBombModel = [];
- let bombTime = ANITIME.BOMB_DELAY;
- bombModels.forEach(function (model) {
- if (model.status == CELL_STATUS.LINE){
- for (let i = 1; i <= this.gridView.grid_width; i++){
- if (this.cells[model.y][i]){
- if (this.cells[model.y][i].status != CELL_STATUS.COMMON){
- newBombModel.push(this.cells[model.y][i]);
- }
- this.crushCell(i, model.y, false, cycleCount);
- }
- }
- this.addRowBomb(this.curTime, cc.v2(model.x, model.y));
- }else if (model.status == CELL_STATUS.COLUMN){
- for (let i = 1; i <= this.gridView.grid_height; i++){
- if (this.cells[i][model.x]){
- if (this.cells[i][model.x].status != CELL_STATUS.COMMON){
- newBombModel.push(this.cells[i][model.x]);
- }
- this.crushCell(model.x, i, false, cycleCount);
- }
- }
- this.addColBomb(this.curTime, cc.v2(model.x, model.y));
- }else if (model.status == CELL_STATUS.WRAP){
- let x = model.x;
- let y = model.y;
- for (let i = 1; i <= this.gridView.grid_height; i++){
- for (let j = 1; j <= this.gridView.grid_width; j++){
- let delta = Math.abs(x - j) + Math.abs(y - i);
- if (this.cells[i][j] && delta <= 2){
- if (this.cells[i][j].status != CELL_STATUS.COMMON){
- newBombModel.push(this.cells[i][j]);
- }
- this.crushCell(j, i, false, cycleCount);
- }
- }
- }
- }else if (model.status == CELL_STATUS.BIRD){
- let crushType = model.type;
- if (bombTime < ANITIME.BOMB_BIRD_DELAY){
- bombTime = ANITIME.BOMB_BIRD_DELAY;
- }
- if (crushType == CELL_STATUS.BIRD){
- crushType = this.getRandomCellType();
- }
- for (let i = 1; i <= this.gridView.grid_height; i++){
- for (let j = 1; j <= this.gridView.grid_width; j++){
- if (this.cells[i][j] && this.cells[i][j].type == crushType){
- if (this.cells[i][j].status != CELL_STATUS.COMMON){
- newBombModel.push(this.cells[i][j]);
- }
- this.crushCell(j, i, true, cycleCount);
- }
- }
- }
- }
- },this)
- if (bombModels.length > 0){
- this.curTime += bombTime;
- }
- bombModels = newBombModel;
- }
- }
- /**
- *
- * @param {*开始播放的时间} playTime
- * @param {*cell位置} pos
- * @param {*第几次消除,用于播放音效} step
- */
- //普通消除
- addCrushEffect(playTime, pos, step){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"crush",
- step
- });
- }
- //正常消除整行
- addRowBomb(playTime, pos){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"rowBomb"
- });
- }
- //道具消除整行
- addRowCrush(playTime, pos){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"crushRow"
- });
- }
- //道具消除整列
- addColCrush(playTime, pos){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"crushCol"
- });
- }
- //正常消除整列
- addColBomb(playTime, pos){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"colBomb"
- });
- }
- //道具消除一种类型
- addOneTypeCrush(playTime, pos){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"typeBomb"
- });
- }
- //分数动画加入队列(按类型消除)
- addCrushNums(playTime,pos,nums,oneNums,twoNums,threeNums){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"crushNums",
- nums, //分数
- oneNums, //类型1消除的数量
- twoNums, //类型2消除的数量
- threeNums, //类型3消除的数量
- });
- }
- //分数动画加入队列(不按类型消除)
- addCrushNums(playTime,pos,nums){
- this.effectsQueue.push({
- playTime,
- pos,
- action:"crushNums",
- nums, //分数
- });
- }
- //cell消除逻辑
- crushCell(x, y, needShake, step){
- let model = this.cells[y][x];
- // console.log("crushCellModel:",model)
- this.pushToChangeModels(model);
- if (needShake){
- model.toShake(this.curTime);
- }
- let shakeTime = needShake ? ANITIME.DIE_SHAKE : 0;
- model.toDie(this.curTime + shakeTime);
- this.addCrushEffect(this.curTime + shakeTime, cc.v2(model.x,model.y), step);
- this.cells[y][x] = null;
- this.crushNums++;
- // console.log("消除的类型:",model.type)
- // console.log("this.crushNums:",this.crushNums)
- //判断消除的类型是否是目标类型
- // if (model.type == 1){
- // this.targetOneTypeNum++;
- // }
- // if (model.type == 2){
- // this.targetTwoTypeNum++;
- // }
- // if (model.type == 3){
- // this.targetThreeTypeNum++;
- // }
- }
- // 道具消除整行
- crushRow(x, y, needShake, step){
- let model = this.cells[y][x];
- // console.log("crushCellModel:",model)
- this.pushToChangeModels(model);
- if (needShake){
- model.toShake(this.curTime);
- }
- let shakeTime = needShake ? ANITIME.DIE_SHAKE : 0;
- model.toDie(this.curTime + shakeTime);
- this.addRowCrush(this.curTime + shakeTime, cc.v2(model.x,model.y), step);
- this.cells[y][x] = null;
- this.crushNums++;
- // console.log("this.crushNums:",this.crushNums)
- //判断消除的类型是否是目标类型
- // if (model.type == 1){
- // this.targetOneTypeNum++;
- // }
- // if (model.type == 2){
- // this.targetTwoTypeNum++;
- // }
- // if (model.type == 3){
- // this.targetThreeTypeNum++;
- // }
- }
- // 道具消除整列
- crushCol(x, y, needShake, step){
- let model = this.cells[y][x];
- // console.log("crushCellModel:",model)
- this.pushToChangeModels(model);
- if (needShake){
- model.toShake(this.curTime);
- }
- let shakeTime = needShake ? ANITIME.DIE_SHAKE : 0;
- model.toDie(this.curTime + shakeTime);
- this.addColCrush(this.curTime + shakeTime, cc.v2(model.x,model.y), step);
- this.cells[y][x] = null;
- this.crushNums++;
- // console.log("this.crushNums:",this.crushNums)
- //判断消除的类型是否是目标类型
- // if (model.type == 1){
- // this.targetOneTypeNum++;
- // }
- // if (model.type == 2){
- // this.targetTwoTypeNum++;
- // }
- // if (model.type == 3){
- // this.targetThreeTypeNum++;
- // }
- }
- // 道具消除一种类型
- crushOneType(x, y, needShake, step){
- let model = this.cells[y][x];
- // console.log("crushOneType:",model)
- this.pushToChangeModels(model);
- if (needShake){
- model.toShake(this.curTime);
- }
- let shakeTime = needShake ? ANITIME.DIE_SHAKE : 0;
- model.toDie(this.curTime + shakeTime);
- this.addOneTypeCrush(this.curTime + shakeTime, cc.v2(model.x,model.y), step);
- this.cells[y][x] = null;
- this.crushNums++;
- // console.log("this.crushNums:",this.crushNums)
- //判断消除的类型是否是目标类型
- // if (model.type == 1){
- // this.targetOneTypeNum++;
- // }
- // if (model.type == 2){
- // this.targetTwoTypeNum++;
- // }
- // if (model.type == 3){
- // this.targetThreeTypeNum++;
- // }
- }
- }
|