From 0586e374618e3fa259c549b933fda84a9ce893ec Mon Sep 17 00:00:00 2001 From: Mizanali Panjwani Date: Mon, 22 Jun 2020 03:12:43 +0530 Subject: [PATCH 1/2] Added a feature --- app.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 36b2a41..daf5fed 100644 --- a/app.js +++ b/app.js @@ -74,7 +74,19 @@ function dragEnd() { let validMove = validMoves.includes(squareIdBeingReplaced) if (squareIdBeingReplaced && validMove) { - squareIdBeingReplaced = null + let scoredRowOfFour = checkRowForFour(); + let scoredColumnOfFour = checkColumnForFour(); + let scoredRowOfThree = checkRowForThree(); + let scoredColumnOfThree = checkColumnForThree(); + //check if any combo was scored + if(scoredRowOfFour || scoredColumnOfFour || scoredRowOfThree || scoredColumnOfThree){ + squareIdBeingReplaced = null; + } + //if no combo scored swap back to original candies + else if(!scoredRowOfFour && !scoredColumnOfFour && !scoredRowOfThree && !scoredColumnOfThree){ + squares[squareIdBeingDragged].style.backgroundImage = colorBeingDragged; + squares[squareIdBeingReplaced].style.backgroundImage = colorBeingReplaced; + } } else if (squareIdBeingReplaced && !validMove) { squares[squareIdBeingReplaced].style.backgroundImage = colorBeingReplaced squares[squareIdBeingDragged].style.backgroundImage = colorBeingDragged From 92a476913071388e2ec7a259eae10e5d85e1ed59 Mon Sep 17 00:00:00 2001 From: Mizanali Panjwani Date: Mon, 22 Jun 2020 03:19:43 +0530 Subject: [PATCH 2/2] Added invalid swap feature --- app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index daf5fed..6b05d6b 100644 --- a/app.js +++ b/app.js @@ -127,10 +127,12 @@ function moveIntoSquareBelow() { rowOfFour.forEach(index => { squares[index].style.backgroundImage = '' }) + return true; } } + return false; } - checkRowForFour() + //for column of Four function checkColumnForFour() { @@ -145,10 +147,12 @@ function moveIntoSquareBelow() { columnOfFour.forEach(index => { squares[index].style.backgroundImage = '' }) + return true; } } + return false; } -checkColumnForFour() + //for row of Three function checkRowForThree() { @@ -166,10 +170,12 @@ checkColumnForFour() rowOfThree.forEach(index => { squares[index].style.backgroundImage = '' }) + return true; } } + return false; } - checkRowForThree() + //for column of Three function checkColumnForThree() { @@ -184,10 +190,11 @@ checkColumnForFour() columnOfThree.forEach(index => { squares[index].style.backgroundImage = '' }) + return true; } } + return false; } -checkColumnForThree() // Checks carried out indefintely - Add Butotn to clear interval for best practise window.setInterval(function(){