I think this may be your solution:
function clickHandler(e) {
var elem= getElementAt(e.getX(), e.getY());
if(score !=0)
{
if(elem != null && elem.getColor() == Color.red)
{
score++;
} else {
score--;
}
}
4
solved How to stop counting scores if you already win or lose? [closed]