So I m building one game which is drenching the field according to selected colour and I have 4 different conditions:
let condition1 = drenchX + 1 === mixedX && drenchY === mixedY && this.mixedFields[i].style.backgroundColor === this.service.clickedColor;
let condition2 = drenchX === mixedX && drenchY + 1 === mixedY && this.mixedFields[i].style.backgroundColor === this.service.clickedColor;
let condition3 = drenchX - 1 === mixedX && drenchY === mixedY && this.mixedFields[i].style.backgroundColor === this.service.clickedColor;
let condition4 = drenchX === mixedX && drenchY - 1 === mixedY && this.mixedFields[i].style.backgroundColor === this.service.clickedColor;
I need to get all possible combinations of this conditions, all 4 of them can be true, or 3 or 2 or just one. This works fine but I think it is too long. My if statement looks like this:
if((condition1 && condition2 && condition3 && condition4) || (condition1 && condition2 && condition3) || (condition1 && condition2 && condition4) || (condition1 && condition3 && condition4) || (condition2 && condition3 && condition4) || (condition1 && condition2) || (condition1 && condition3) || (condition1 && condition4) || (condition2 && condition3) || (condition2 && condition4) || (condition3 && condition4) || condition1 || condition2 || condition3 || condition4) {
// some action
}
It all works perfectly but I m looking for a shorter solution and I m still a beginner in this. So if anyone know a better way to do this that would be great, my statement is just too long and it doesn't looks good at all. Btw, project is in Angular. Maybe to create some function for this?