Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,10 +127,12 @@ function moveIntoSquareBelow() {
rowOfFour.forEach(index => {
squares[index].style.backgroundImage = ''
})
return true;
}
}
return false;
}
checkRowForFour()


//for column of Four
function checkColumnForFour() {
Expand All @@ -133,10 +147,12 @@ function moveIntoSquareBelow() {
columnOfFour.forEach(index => {
squares[index].style.backgroundImage = ''
})
return true;
}
}
return false;
}
checkColumnForFour()


//for row of Three
function checkRowForThree() {
Expand All @@ -154,10 +170,12 @@ checkColumnForFour()
rowOfThree.forEach(index => {
squares[index].style.backgroundImage = ''
})
return true;
}
}
return false;
}
checkRowForThree()


//for column of Three
function checkColumnForThree() {
Expand All @@ -172,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(){
Expand Down