Amélioration du code

This commit is contained in:
2024-11-17 13:52:42 +01:00
parent 687d55ee31
commit dec61876cf
3 changed files with 33 additions and 48 deletions

Binary file not shown.

View File

@@ -55,4 +55,6 @@ public class Options {
public static boolean AUTO_FOCUS = true; public static boolean AUTO_FOCUS = true;
public static final int MAX_TILE_NUMBER = 50; public static final int MAX_TILE_NUMBER = 50;
public static boolean FULL_SCREEN = false;
} }

View File

@@ -35,30 +35,31 @@ public class MainMenuButtonController implements ActionListener {
// Paramètrage de la fenêtre des paramètres // Paramètrage de la fenêtre des paramètres
this.settingsFrame = settingsFrame; this.settingsFrame = settingsFrame;
this.settingsFrame.setLocationRelativeTo(null); configureFrame(settingsFrame);
this.settingsFrame.setVisible(false);
this.settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Paramètrage de la fenêtre du tutoriel // Paramètrage de la fenêtre du tutoriel
this.howToPlayFrame = howToPlayFrame; this.howToPlayFrame = howToPlayFrame;
this.howToPlayFrame.setLocationRelativeTo(null); configureFrame(howToPlayFrame);
this.howToPlayFrame.setVisible(false);
this.howToPlayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Paramètrage de la fenêtre du jeu // Paramètrage de la fenêtre du jeu
this.gameModeFrame = gameModeFrame; this.gameModeFrame = gameModeFrame;
this.gameModeFrame.setLocationRelativeTo(null); configureFrame(gameModeFrame);
this.gameModeFrame.setVisible(false);
this.gameModeFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Paramètrage de la fenêtre du jeu // Paramètrage de la fenêtre du jeu
this.gameFrame = gameFrame; this.gameFrame = gameFrame;
this.gameFrame.setLocationRelativeTo(null); configureFrame(gameFrame);
this.gameFrame.setVisible(false);
this.gameFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} }
private void configureFrame(JFrame frame) {
frame.setLocationRelativeTo(null);
frame.setVisible(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand(); String command = e.getActionCommand();
@@ -86,21 +87,8 @@ public class MainMenuButtonController implements ActionListener {
} }
public void startNewGame() { public void startNewGame() {
// Récupérer la taille et la position de la fenêtre du menu principal adjustFrameDisplay(this.gameModeFrame);
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
this.gameModeFrame.setSize(mainMenuSize);
this.gameModeFrame.setLocation(mainMenuLocation);
this.gameFrame.setSize(mainMenuSize);
this.gameFrame.setLocation(mainMenuLocation);
// Cacher la fenêtre du menu principal
this.mainMenu.setVisible(false); this.mainMenu.setVisible(false);
// Afficher la fenêtre des paramètres
this.gameModeFrame.setVisible(true); this.gameModeFrame.setVisible(true);
} }
@@ -110,18 +98,8 @@ public class MainMenuButtonController implements ActionListener {
} }
public void showHowToPlay() { public void showHowToPlay() {
// Récupérer la taille et la position de la fenêtre du menu principal adjustFrameDisplay(this.howToPlayFrame);
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
this.howToPlayFrame.setSize(mainMenuSize);
this.howToPlayFrame.setLocation(mainMenuLocation);
// Cacher la fenêtre du menu principal
this.mainMenu.setVisible(false); this.mainMenu.setVisible(false);
// Afficher la fenêtre des paramètres
this.howToPlayFrame.setVisible(true); this.howToPlayFrame.setVisible(true);
} }
@@ -131,18 +109,23 @@ public class MainMenuButtonController implements ActionListener {
} }
private void openSettings() { private void openSettings() {
// Récupérer la taille et la position de la fenêtre du menu principal adjustFrameDisplay(this.settingsFrame);
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
this.settingsFrame.setSize(mainMenuSize);
this.settingsFrame.setLocation(mainMenuLocation);
// Cacher la fenêtre du menu principal
this.mainMenu.setVisible(false); this.mainMenu.setVisible(false);
// Afficher la fenêtre des paramètres
this.settingsFrame.setVisible(true); this.settingsFrame.setVisible(true);
} }
private void adjustFrameDisplay(JFrame frame) {
if (Options.FULL_SCREEN) {
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Mettre la fenêtre en plein écran
frame.setUndecorated(true); // Retirer la décoration de la fenêtre
} else {
// Récupérer la taille et la position de la fenêtre du menu principal
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
frame.setSize(mainMenuSize);
frame.setLocation(mainMenuLocation);
frame.setUndecorated(false); // Restaurer la décoration si nécessaire
}
}
} }