Это код для обработки разделения в игре в блэкджек. Разделенная игра запускается только в том случае, если игрок может эффективно разделить игру. В графическом интерфейсе я вижу разделение, но после этого игра заканчивается.
public void splitPlay(Giocatore g, Map giocatoreACarteContainer, Button chiedi, Button stai, Runnable callbackFineTurno) {
g.partizioneSplit();
List manoSplit = g.getManoSplit();
HBox spazioGiocatore = giocatoreACarteContainer.get(g);
spazioGiocatore.getChildren().clear();
VBox vboxCarte = new VBox(10);
vboxCarte.setAlignment(Pos.CENTER);
ArrayList hboxCarteList = new ArrayList();
for (Mano m : manoSplit) {
HBox hboxCarta = new HBox(10);
hboxCarta.setAlignment(Pos.CENTER);
hboxCarteList.add(hboxCarta);
vboxCarte.getChildren().add(hboxCarta);
}
spazioGiocatore.getChildren().add(vboxCarte);
if (g.getNome().equals("io")) {
AtomicInteger indiceCorrente = new AtomicInteger(0);
chiedi.setOnAction(e -> {
chiediCarta(g);
aggiungiCartaSplit(g, hboxCarteList.get(indiceCorrente.get()));
});
stai.setOnAction(e -> {
int nextIndex = indiceCorrente.incrementAndGet();
if (nextIndex >= manoSplit.size()) {
callbackFineTurno.run();
}
});
} else {
gestisciTurnoIA(g, hboxCarteList, callbackFineTurno);
}
}
public void gestisciTurnoIA(Giocatore g, ArrayList hboxCarteList, Runnable callbackFineTurno) {
AtomicInteger indiceManoCorrente = new AtomicInteger(0);
eseguiAzioneIA(g, hboxCarteList, indiceManoCorrente, callbackFineTurno);
}
public void eseguiAzioneIA(Giocatore g, List hboxCarteList, AtomicInteger indiceManoCorrente, Runnable callbackFineTurno) {
if (indiceManoCorrente.get() >= g.getManoSplit().size()) {
callbackFineTurno.run();
return;
}
Mano manoCorrente = g.getManoSplit().get(indiceManoCorrente.get());
HBox hboxCorrente = hboxCarteList.get(indiceManoCorrente.get());
if (manoCorrente.calcolaPunteggio() < 17) {
chiediCarta(g);
aggiungiCartaSplit(g, hboxCorrente);
if (manoCorrente.calcolaPunteggio() < 17) {
indiceManoCorrente.incrementAndGet(); // Increment here
PauseTransition pause = new PauseTransition(Duration.seconds(1));
pause.setOnFinished(e -> eseguiAzioneIA(g, hboxCarteList, indiceManoCorrente, callbackFineTurno));
pause.play();
} else {
// If the score is 17 or higher, move to the next hand or end the turn
indiceManoCorrente.incrementAndGet();
if (indiceManoCorrente.get() < g.getManoSplit().size()) {
eseguiAzioneIA(g, hboxCarteList, indiceManoCorrente, callbackFineTurno);
} else {
callbackFineTurno.run();
}
}
} else {
// If the score is already 17 or higher, move to the next hand or end the turn
indiceManoCorrente.incrementAndGet();
if (indiceManoCorrente.get() < g.getManoSplit().size()) {
eseguiAzioneIA(g, hboxCarteList, indiceManoCorrente, callbackFineTurno);
} else {
callbackFineTurno.run();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... -blackjack