ajout d'un menu de fin et de pouvoir quitter
This commit is contained in:
@@ -63,6 +63,11 @@ public class ArenaWindow extends JFrame {
|
|||||||
});
|
});
|
||||||
buttonPanel.add(backButton);
|
buttonPanel.add(backButton);
|
||||||
|
|
||||||
|
// Nouveau bouton pour quitter entièrement le jeu
|
||||||
|
JButton quitButton = new JButton("Quitter");
|
||||||
|
quitButton.addActionListener(e -> System.exit(0));
|
||||||
|
buttonPanel.add(quitButton);
|
||||||
|
|
||||||
add(buttonPanel, BorderLayout.SOUTH);
|
add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
@@ -226,13 +231,22 @@ public class ArenaWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un message de fin
|
// Afficher un message de fin avec possibilité de quitter directement
|
||||||
JOptionPane.showMessageDialog(
|
Object[] options = {"OK", "Quitter le jeu"};
|
||||||
|
int choice = JOptionPane.showOptionDialog(
|
||||||
this,
|
this,
|
||||||
"Toutes les parties sont terminées !",
|
"Toutes les parties sont terminées !",
|
||||||
"Arène terminée",
|
"Arène terminée",
|
||||||
JOptionPane.INFORMATION_MESSAGE
|
JOptionPane.DEFAULT_OPTION,
|
||||||
|
JOptionPane.INFORMATION_MESSAGE,
|
||||||
|
null,
|
||||||
|
options,
|
||||||
|
options[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (choice == 1) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public class AvalamWindow extends JFrame {
|
|||||||
/** Mode de jeu sélectionné. */
|
/** Mode de jeu sélectionné. */
|
||||||
private final GameMode mode;
|
private final GameMode mode;
|
||||||
|
|
||||||
|
/** Profondeur de recherche utilisée (utile pour les modes avec bot intelligent et pour rejouer). */
|
||||||
|
private final int searchDepth;
|
||||||
|
|
||||||
/** Joueur contrôlé par le bot (si actif). */
|
/** Joueur contrôlé par le bot (si actif). */
|
||||||
private final Player botPlayer = Player.PLAYER2;
|
private final Player botPlayer = Player.PLAYER2;
|
||||||
|
|
||||||
@@ -104,10 +107,11 @@ public class AvalamWindow extends JFrame {
|
|||||||
super("Avalam");
|
super("Avalam");
|
||||||
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
this.searchDepth = Math.max(1, alphaDepth);
|
||||||
|
|
||||||
this.idiotBot = (mode == GameMode.PVBOT) ? new IdiotBot(botPlayer) : null;
|
this.idiotBot = (mode == GameMode.PVBOT) ? new IdiotBot(botPlayer) : null;
|
||||||
|
|
||||||
int depth = Math.max(1, alphaDepth);
|
int depth = this.searchDepth;
|
||||||
this.alphaBot = (mode == GameMode.PVALPHA) ? new AlphaBetaBot(botPlayer, depth) : null;
|
this.alphaBot = (mode == GameMode.PVALPHA) ? new AlphaBetaBot(botPlayer, depth) : null;
|
||||||
|
|
||||||
// A FAIRE PLUS TARD (PVGOD)
|
// A FAIRE PLUS TARD (PVGOD)
|
||||||
@@ -169,28 +173,30 @@ public class AvalamWindow extends JFrame {
|
|||||||
if (board.isGameOver()) {
|
if (board.isGameOver()) {
|
||||||
Result res = board.getResult();
|
Result res = board.getResult();
|
||||||
|
|
||||||
String msg;
|
int scoreJaune = computeScore(Color.YELLOW);
|
||||||
switch (res) {
|
int scoreRouge = computeScore(Color.RED);
|
||||||
case WIN:
|
|
||||||
msg = "Le joueur jaune a gagné !";
|
|
||||||
break;
|
|
||||||
case LOSS:
|
|
||||||
msg = "Le joueur rouge a gagné !";
|
|
||||||
break;
|
|
||||||
case DRAW:
|
|
||||||
msg = "Égalité !";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
msg = "Fin de partie.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(
|
EndGameDialog dialog = new EndGameDialog(
|
||||||
this,
|
this,
|
||||||
msg,
|
res,
|
||||||
"Partie terminée",
|
scoreJaune,
|
||||||
JOptionPane.INFORMATION_MESSAGE
|
scoreRouge,
|
||||||
|
mode,
|
||||||
|
searchDepth,
|
||||||
|
// Rejouer : on ferme la fenêtre actuelle et on relance une nouvelle partie avec le même mode/profondeur
|
||||||
|
() -> SwingUtilities.invokeLater(() -> {
|
||||||
|
dispose();
|
||||||
|
new AvalamWindow(mode, searchDepth);
|
||||||
|
}),
|
||||||
|
// Menu principal : on ferme la fenêtre actuelle et on réaffiche le menu de mode de jeu
|
||||||
|
() -> SwingUtilities.invokeLater(() -> {
|
||||||
|
dispose();
|
||||||
|
Main.showModeSelection();
|
||||||
|
}),
|
||||||
|
// Quitter complètement l'application
|
||||||
|
() -> System.exit(0)
|
||||||
);
|
);
|
||||||
|
dialog.setVisible(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
153
fr/iut_fbleau/Avalam/EndGameDialog.java
Normal file
153
fr/iut_fbleau/Avalam/EndGameDialog.java
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
package fr.iut_fbleau.Avalam;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.GameAPI.Result;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fenêtre de fin de partie.
|
||||||
|
* Affiche le gagnant, le score et propose plusieurs actions :
|
||||||
|
* - Rejouer la même configuration
|
||||||
|
* - Retour au menu principal
|
||||||
|
* - Quitter le jeu
|
||||||
|
*/
|
||||||
|
public class EndGameDialog extends JDialog {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit la fenêtre de fin de partie.
|
||||||
|
*
|
||||||
|
* @param parent fenêtre principale (AvalamWindow)
|
||||||
|
* @param result résultat de la partie (WIN / LOSS / DRAW du point de vue de PLAYER1 / Jaune)
|
||||||
|
* @param scoreJaune score du joueur jaune
|
||||||
|
* @param scoreRouge score du joueur rouge
|
||||||
|
* @param mode mode de jeu courant (pour l'information / le rejouer)
|
||||||
|
* @param depth profondeur utilisée (pour les modes avec bot intelligent)
|
||||||
|
* @param onReplay action à exécuter pour rejouer
|
||||||
|
* @param onMenu action à exécuter pour revenir au menu
|
||||||
|
* @param onQuit action à exécuter pour quitter l'application
|
||||||
|
*/
|
||||||
|
public EndGameDialog(
|
||||||
|
JFrame parent,
|
||||||
|
Result result,
|
||||||
|
int scoreJaune,
|
||||||
|
int scoreRouge,
|
||||||
|
GameMode mode,
|
||||||
|
int depth,
|
||||||
|
Runnable onReplay,
|
||||||
|
Runnable onMenu,
|
||||||
|
Runnable onQuit
|
||||||
|
) {
|
||||||
|
super(parent, "Fin de partie", true);
|
||||||
|
|
||||||
|
setLayout(new BorderLayout(10, 10));
|
||||||
|
|
||||||
|
// Panel principal d'information
|
||||||
|
JPanel infoPanel = new JPanel();
|
||||||
|
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
|
||||||
|
infoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
|
||||||
|
JLabel titre = new JLabel("Partie terminée");
|
||||||
|
titre.setFont(titre.getFont().deriveFont(Font.BOLD, 18f));
|
||||||
|
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
String gagnant;
|
||||||
|
switch (result) {
|
||||||
|
case WIN:
|
||||||
|
gagnant = "Le joueur JAUNE a gagné !";
|
||||||
|
break;
|
||||||
|
case LOSS:
|
||||||
|
gagnant = "Le joueur ROUGE a gagné !";
|
||||||
|
break;
|
||||||
|
case DRAW:
|
||||||
|
gagnant = "Égalité parfaite !";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gagnant = "Fin de partie.";
|
||||||
|
}
|
||||||
|
|
||||||
|
JLabel gagnantLabel = new JLabel(gagnant);
|
||||||
|
gagnantLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JLabel scoreLabel = new JLabel(
|
||||||
|
"Score - Jaune : " + scoreJaune + " | Rouge : " + scoreRouge
|
||||||
|
);
|
||||||
|
scoreLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JLabel modeLabel = new JLabel("Mode : " + modeToString(mode, depth));
|
||||||
|
modeLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
infoPanel.add(titre);
|
||||||
|
infoPanel.add(Box.createVerticalStrut(10));
|
||||||
|
infoPanel.add(gagnantLabel);
|
||||||
|
infoPanel.add(Box.createVerticalStrut(5));
|
||||||
|
infoPanel.add(scoreLabel);
|
||||||
|
infoPanel.add(Box.createVerticalStrut(5));
|
||||||
|
infoPanel.add(modeLabel);
|
||||||
|
|
||||||
|
add(infoPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Panel des boutons d'action
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
|
||||||
|
|
||||||
|
JButton replayButton = new JButton("Rejouer");
|
||||||
|
replayButton.addActionListener(e -> {
|
||||||
|
if (onReplay != null) {
|
||||||
|
onReplay.run();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton menuButton = new JButton("Menu principal");
|
||||||
|
menuButton.addActionListener(e -> {
|
||||||
|
if (onMenu != null) {
|
||||||
|
onMenu.run();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton quitButton = new JButton("Quitter");
|
||||||
|
quitButton.addActionListener(e -> {
|
||||||
|
if (onQuit != null) {
|
||||||
|
onQuit.run();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonPanel.add(replayButton);
|
||||||
|
buttonPanel.add(menuButton);
|
||||||
|
buttonPanel.add(quitButton);
|
||||||
|
|
||||||
|
add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
pack();
|
||||||
|
setResizable(false);
|
||||||
|
setLocationRelativeTo(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne une description lisible du mode de jeu courant.
|
||||||
|
*
|
||||||
|
* @param mode mode de jeu
|
||||||
|
* @param depth profondeur (pour les bots intelligents)
|
||||||
|
* @return chaîne décrivant le mode
|
||||||
|
*/
|
||||||
|
private String modeToString(GameMode mode, int depth) {
|
||||||
|
switch (mode) {
|
||||||
|
case PVP:
|
||||||
|
return "Joueur vs Joueur";
|
||||||
|
case PVBOT:
|
||||||
|
return "Joueur vs Bot idiot";
|
||||||
|
case PVALPHA:
|
||||||
|
return "Joueur vs Bot Alpha (profondeur " + depth + ")";
|
||||||
|
case PVGOD:
|
||||||
|
return "Joueur vs Bot Divin (profondeur " + depth + ")";
|
||||||
|
case ARENA:
|
||||||
|
return "Arène (bots)"; // normalement non utilisé ici
|
||||||
|
default:
|
||||||
|
return mode.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user