Modifications + ajout du choix des modes (vues)
This commit is contained in:
@@ -11,6 +11,7 @@ SOURCEDIR = ./src/
|
||||
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
|
||||
|
||||
all:
|
||||
@make clean
|
||||
@make compile
|
||||
@make jar
|
||||
@make run
|
||||
|
@@ -0,0 +1,57 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeController implements ActionListener {
|
||||
|
||||
private GameModeSelectionPanel gameModeSelectionPanel;
|
||||
|
||||
// Constructeur sans le panneau
|
||||
public GameModeController() {
|
||||
// Initialisation sans le panneau
|
||||
}
|
||||
|
||||
// Méthode pour associer le panneau
|
||||
public void setGameModeSelectionPanel(GameModeSelectionPanel panel) {
|
||||
this.gameModeSelectionPanel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Mode 1":
|
||||
startGame("Mode 1", null);
|
||||
break;
|
||||
case "Mode 2":
|
||||
startGame("Mode 2", null);
|
||||
break;
|
||||
case "Mode 3":
|
||||
startGame("Mode 3", null);
|
||||
break;
|
||||
case "Mode 4":
|
||||
startGame("Mode 4", null);
|
||||
break;
|
||||
case "Démarrer":
|
||||
String seed = gameModeSelectionPanel.getSeed();
|
||||
if (!seed.isEmpty()) {
|
||||
startGame("Custom Mode", seed);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame(String mode, String seed) {
|
||||
System.out.println("Démarrer le jeu en mode: " + mode);
|
||||
if (seed != null) {
|
||||
System.out.println("Seed personnalisée: " + seed);
|
||||
}
|
||||
|
||||
// Implémenter la logique pour démarrer le jeu avec le mode sélectionné et la seed si applicable
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseWindowListener;
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -78,11 +79,27 @@ public class MainMenuButtonController implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void startNewGame() {
|
||||
System.out.println("Démarrer une nouvelle partie...");
|
||||
// Logic to start a new game
|
||||
public void startNewGame() {
|
||||
// Créer un contrôleur pour le mode de jeu
|
||||
GameModeController gameModeController = new GameModeController();
|
||||
|
||||
// Créer le panneau de sélection de mode de jeu
|
||||
GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController);
|
||||
|
||||
// Associer le panneau au contrôleur
|
||||
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
|
||||
|
||||
// Créer une nouvelle fenêtre pour la sélection de mode de jeu
|
||||
JFrame gameModeFrame = new JFrame("Sélectionnez un mode de jeu");
|
||||
gameModeFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
gameModeFrame.setSize(600, 400);
|
||||
gameModeFrame.setLocationRelativeTo(null);
|
||||
gameModeFrame.add(gameModeSelectionPanel);
|
||||
gameModeFrame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void continueGame() {
|
||||
System.out.println("Continuer une partie...");
|
||||
// Logic to continue the game
|
||||
|
@@ -0,0 +1,119 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeSelectionPanel extends JPanel {
|
||||
|
||||
private JLabel titleLabel;
|
||||
private JButton mode1Button;
|
||||
private JButton mode2Button;
|
||||
private JButton mode3Button;
|
||||
private JButton mode4Button;
|
||||
private JTextField seedField;
|
||||
private JButton startButton;
|
||||
|
||||
public GameModeSelectionPanel(ActionListener buttonListener) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Add background image
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
|
||||
// Main content panel
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel);
|
||||
|
||||
// Title
|
||||
titleLabel = new JLabel("Choisissez un mode de jeu", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 40));
|
||||
titleLabel.setForeground(Color.WHITE);
|
||||
mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2));
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Mode buttons - now horizontally aligned
|
||||
JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing
|
||||
modePanel.setOpaque(false);
|
||||
|
||||
mode1Button = createGameModeButton("Mode 1", buttonListener);
|
||||
mode2Button = createGameModeButton("Mode 2", buttonListener);
|
||||
mode3Button = createGameModeButton("Mode 3", buttonListener);
|
||||
mode4Button = createGameModeButton("Mode 4", buttonListener);
|
||||
|
||||
modePanel.add(mode1Button);
|
||||
modePanel.add(mode2Button);
|
||||
modePanel.add(mode3Button);
|
||||
modePanel.add(mode4Button);
|
||||
|
||||
mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
|
||||
|
||||
// Seed input and start button
|
||||
JPanel seedPanel = createSeedPanel(buttonListener);
|
||||
mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2));
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
private GridBagConstraints createGridBagConstraints(int x, int y, int gridWidth) {
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridx = x;
|
||||
gbc.gridy = y;
|
||||
gbc.gridwidth = gridWidth;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(20, 30, 20, 30);
|
||||
return gbc;
|
||||
}
|
||||
|
||||
private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
|
||||
JButton button = new JButton(modeName);
|
||||
button.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
button.setBackground(new Color(0, 122, 255));
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
button.setFocusPainted(false);
|
||||
button.addActionListener(buttonListener);
|
||||
button.setPreferredSize(new Dimension(150, 50)); // Adjust the size of the buttons
|
||||
return button;
|
||||
}
|
||||
|
||||
private JPanel createSeedPanel(ActionListener buttonListener) {
|
||||
JPanel seedPanel = new JPanel();
|
||||
seedPanel.setOpaque(false);
|
||||
seedPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JLabel seedLabel = new JLabel("Entrez votre seed:");
|
||||
seedLabel.setForeground(Color.WHITE);
|
||||
seedPanel.add(seedLabel);
|
||||
|
||||
seedField = new JTextField(20);
|
||||
seedField.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
seedField.setPreferredSize(new Dimension(250, 40));
|
||||
seedField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
seedPanel.add(seedField);
|
||||
|
||||
startButton = new JButton("Démarrer");
|
||||
startButton.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
startButton.setBackground(new Color(0, 255, 0));
|
||||
startButton.setForeground(Color.WHITE);
|
||||
startButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
startButton.setPreferredSize(new Dimension(150, 50));
|
||||
startButton.addActionListener(buttonListener);
|
||||
seedPanel.add(startButton);
|
||||
|
||||
return seedPanel;
|
||||
}
|
||||
|
||||
public String getSeed() {
|
||||
return seedField.getText();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user