0
In this memory game, when I click the first button and then the second button, everything happens according to the algorithm, but when I click two clicks on the first button, there is a problem... I wanted to know how to avoid a second click on the first button clicked, type disable it so it can not receive a second click... because the button counts every click it receives, so there can be no more than one click.
for (int i=0; i<16; ++i){
if (event.getSource() == buttons[i]){
buttons[i].setGraphic(new ImageView(imgs[Aleatorio[i]]));//novo código
//buttons[i].setVisible(true);
NumeroClick++;
if (NumeroClick == 1) PrimeiroClick = i;
if (NumeroClick == 2){
SegundoClick = i;
///////////////Clicks_não_conseguidos///////////////
if (Aleatorio[PrimeiroClick] != Aleatorio[SegundoClick]){
pontos-=2;
Servico service = new Servico();
service.setOnSucceeded((WorkerStateEvent ev) -> {
buttons[PrimeiroClick].setGraphic(null); //novo código
buttons[PrimeiroClick].setDisable(false);
buttons[SegundoClick].setGraphic(null); //novo código
buttons[SegundoClick].setDisable(false);
});
service.start();
} else {
ContAcertos++;
pontos+=10;
}
NumeroClick = 0;
}
}
}
I think you’re missing one
if
if I understood your code well... After knowing that it is the second click , here I thinkif (NumeroClick == 2){
you have to check that it’s not on the same button as the first one, if it’s the same, you have to repeat the click... However I didn’t understand how your code is executed, since you always walk inside theFOR
... In my logic I should wait for a click and then check if it was the first or the second if it is the second and with the first stored in a variable you make the comparison whether it is right or not...– jsantos1991
Are you using jQuery ?
– Diego Souza