Path: blob/main/public/games/files/hextris/js/checking.js
1036 views
function search(twoD,oneD){1// Searches a two dimensional array to see if it contains a one dimensional array. indexOf doesn't work in this case2for(var i=0;i<twoD.length;i++){3if(twoD[i][0] == oneD[0] && twoD[i][1] == oneD[1]) {4return true;5}6}7return false;8}910function floodFill(hex, side, index, deleting) {11if (hex.blocks[side] === undefined || hex.blocks[side][index] === undefined) return;1213//store the color14var color = hex.blocks[side][index].color;15//nested for loops for navigating the blocks16for(var x =-1;x<2;x++){17for(var y =-1;y<2;y++){18//make sure the they aren't diagonals19if(Math.abs(x)==Math.abs(y)){continue;}20//calculate the side were exploring using mods21var curSide =(side+x+hex.sides)%hex.sides;22//calculate the index23var curIndex = index+y;24//making sure the block exists at this side and index25if(hex.blocks[curSide] === undefined){continue;}26if(hex.blocks[curSide][curIndex] !== undefined){27// checking equivalency of color, if its already been explored, and if it isn't already deleted28if(hex.blocks[curSide][curIndex].color == color && search(deleting,[curSide,curIndex]) === false && hex.blocks[curSide][curIndex].deleted === 0 ) {29//add this to the array of already explored30deleting.push([curSide,curIndex]);31//recall with next block explored32floodFill(hex,curSide,curIndex,deleting);33}34}35}36}37}3839function consolidateBlocks(hex,side,index){40//record which sides have been changed41var sidesChanged =[];42var deleting=[];43var deletedBlocks = [];44//add start case45deleting.push([side,index]);46//fill deleting47floodFill(hex,side,index,deleting);48//make sure there are more than 3 blocks to be deleted49if(deleting.length<3){return;}50var i;51for(i=0; i<deleting.length;i++) {52var arr = deleting[i];53//just making sure the arrays are as they should be54if(arr !== undefined && arr.length==2) {55//add to sides changed if not in there56if(sidesChanged.indexOf(arr[0])==-1){57sidesChanged.push(arr[0]);58}59//mark as deleted60hex.blocks[arr[0]][arr[1]].deleted = 1;61deletedBlocks.push(hex.blocks[arr[0]][arr[1]]);62}63}6465// add scores66var now = MainHex.ct;67if(now - hex.lastCombo < settings.comboTime ){68settings.comboTime = (1/settings.creationSpeedModifier) * (waveone.nextGen/16.666667) * 3;69hex.comboMultiplier += 1;70hex.lastCombo = now;71var coords = findCenterOfBlocks(deletedBlocks);72hex.texts.push(new Text(coords['x'],coords['y'],"x "+hex.comboMultiplier.toString(),"bold Q","#fff",fadeUpAndOut));73}74else{75settings.comboTime = 240;76hex.lastCombo = now;77hex.comboMultiplier = 1;78}79var adder = deleting.length * deleting.length * hex.comboMultiplier;80hex.texts.push(new Text(hex.x,hex.y,"+ "+adder.toString(),"bold Q ",deletedBlocks[0].color,fadeUpAndOut));81hex.lastColorScored = deletedBlocks[0].color;82score += adder;83}848586