test pour faire le plateau+nouveau menu dans testV1+ probleme compilation
This commit is contained in:
41
TestV1/Makefile
Normal file
41
TestV1/Makefile
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
PACKAGE = fr.monkhanny.dorfromantik
|
||||||
|
ENTRY = Main
|
||||||
|
SOURCEDIR = ./src/fr/monkhanny/dorfromantik/
|
||||||
|
BUILDDIR = ./build/
|
||||||
|
DOCDIR = ./doc/
|
||||||
|
JARNAME = dorfromantik.jar
|
||||||
|
CLASSP = libs/*
|
||||||
|
MANIFESTPATH = Manifest.MF
|
||||||
|
SOURCEDIR = ./src/
|
||||||
|
|
||||||
|
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
|
||||||
|
|
||||||
|
all:
|
||||||
|
@make compile
|
||||||
|
@make jar
|
||||||
|
@make run
|
||||||
|
|
||||||
|
compile:
|
||||||
|
@echo "Compiling..."
|
||||||
|
@javac -cp $(CLASSP) -d $(BUILDDIR) $(SOURCES) -Xlint:unchecked -Xlint:deprecation
|
||||||
|
@echo "Done."
|
||||||
|
|
||||||
|
run:
|
||||||
|
@echo "Running..."
|
||||||
|
@java -jar $(JARNAME)
|
||||||
|
@echo "Done."
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "Cleaning up..."
|
||||||
|
@rm -rf $(BUILDDIR)* $(DOCDIR)*
|
||||||
|
@echo "Done."
|
||||||
|
|
||||||
|
javadoc:
|
||||||
|
@echo "Generating javadoc..."
|
||||||
|
@javadoc -d $(DOCDIR) -sourcepath src -subpackages $(PACKAGE)
|
||||||
|
@echo "Done."
|
||||||
|
|
||||||
|
jar:
|
||||||
|
@echo "Creating jar..."
|
||||||
|
@jar cfm $(JARNAME) $(MANIFESTPATH) -C $(BUILDDIR) fr/monkhanny/dorfromantik ressources
|
||||||
|
@echo "Done."
|
3
TestV1/Manifest.MF
Normal file
3
TestV1/Manifest.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: fr.monkhanny.dorfromantik.Main
|
||||||
|
Class-Path: libs/mariadb-client.jar
|
20
TestV1/TestEnAttendantResolutionBug/Main.java
Normal file
20
TestV1/TestEnAttendantResolutionBug/Main.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import model.Game;
|
||||||
|
import view.GameView;
|
||||||
|
import controller.GameController;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
Game game = new Game();
|
||||||
|
GameView gameView = new GameView(game); // Crée la vue sans contrôleur pour le moment
|
||||||
|
GameController controller = new GameController(game, gameView); // Initialise le contrôleur avec game et gameView
|
||||||
|
|
||||||
|
// Passe ensuite le contrôleur à la vue une fois que tout est initialisé
|
||||||
|
gameView.setController(controller);
|
||||||
|
|
||||||
|
gameView.setVisible(true); // Affiche la fenêtre
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
61
TestV1/TestEnAttendantResolutionBug/View/BoardView.java
Normal file
61
TestV1/TestEnAttendantResolutionBug/View/BoardView.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import model.Board;
|
||||||
|
import model.Tile;
|
||||||
|
import controller.GameController;
|
||||||
|
|
||||||
|
public class BoardView extends JPanel {
|
||||||
|
private GameController controller;
|
||||||
|
private int rows = 5;
|
||||||
|
private int cols = 5;
|
||||||
|
|
||||||
|
public BoardView(Board board, GameController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
setLayout(new GridLayout(rows, cols, 5, 5));
|
||||||
|
initializeBoard();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour assigner le contrôleur après création de l'instance
|
||||||
|
public void setController(GameController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeBoard() {
|
||||||
|
for (int i = 0; i < rows * cols; i++) {
|
||||||
|
JPanel tilePanel = new JPanel();
|
||||||
|
tilePanel.setBackground(Color.LIGHT_GRAY);
|
||||||
|
tilePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
|
||||||
|
tilePanel.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
handleTilePlacement(tilePanel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
add(tilePanel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleTilePlacement(JPanel tilePanel) {
|
||||||
|
if (controller != null) { // Assure que le contrôleur est bien assigné
|
||||||
|
Tile tile = controller.getNextTile();
|
||||||
|
if (tile != null) {
|
||||||
|
tilePanel.setBackground(Color.GREEN);
|
||||||
|
tilePanel.add(new JLabel(tile.getType()));
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
controller.placeTile(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshBoard() {
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
31
TestV1/TestEnAttendantResolutionBug/View/GameController.java
Normal file
31
TestV1/TestEnAttendantResolutionBug/View/GameController.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package controller;
|
||||||
|
|
||||||
|
import model.Game;
|
||||||
|
import model.Tile;
|
||||||
|
import view.GameView;
|
||||||
|
|
||||||
|
public class GameController {
|
||||||
|
private Game game;
|
||||||
|
private GameView gameView;
|
||||||
|
private Tile currentTile;
|
||||||
|
|
||||||
|
public GameController(Game game, GameView gameView) {
|
||||||
|
this.game = game;
|
||||||
|
this.gameView = gameView;
|
||||||
|
this.currentTile = null; // Initialise sans tuile au début
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectNextTile(Tile tile) {
|
||||||
|
this.currentTile = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getNextTile() {
|
||||||
|
return currentTile; // Retourne la tuile actuellement sélectionnée
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeTile(Tile tile) {
|
||||||
|
game.placeTile(tile);
|
||||||
|
gameView.update(game);
|
||||||
|
currentTile = null; // Réinitialise après placement
|
||||||
|
}
|
||||||
|
}
|
52
TestV1/TestEnAttendantResolutionBug/View/GameView.java
Normal file
52
TestV1/TestEnAttendantResolutionBug/View/GameView.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import model.Game;
|
||||||
|
import model.Tile;
|
||||||
|
import controller.GameController;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class GameView extends JFrame {
|
||||||
|
private JLabel scoreLabel;
|
||||||
|
private BoardView boardView;
|
||||||
|
private GameController controller; // Ajoute le contrôleur ici
|
||||||
|
|
||||||
|
public GameView(Game game) { // Constructeur sans le contrôleur en paramètre
|
||||||
|
setTitle("Dorfromantik en Java");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setSize(500, 500);
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
scoreLabel = new JLabel("Score : " + game.getScore());
|
||||||
|
boardView = new BoardView(game.getBoard(), null); // Initialise BoardView sans contrôleur
|
||||||
|
|
||||||
|
JButton nextTileButton = new JButton("Sélectionner une tuile");
|
||||||
|
nextTileButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (controller != null) { // Vérifie que le contrôleur est bien assigné
|
||||||
|
Tile tile = new Tile("forêt", new String[]{"terre", "terre", "eau", "terre", "eau", "terre"});
|
||||||
|
controller.selectNextTile(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
add(scoreLabel, BorderLayout.NORTH);
|
||||||
|
add(boardView, BorderLayout.CENTER);
|
||||||
|
add(nextTileButton, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nouvelle méthode setController pour permettre d'assigner le contrôleur après création
|
||||||
|
public void setController(GameController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
boardView.setController(controller); // Passe le contrôleur à BoardView
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Game game) {
|
||||||
|
scoreLabel.setText("Score : " + game.getScore());
|
||||||
|
boardView.refreshBoard();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
package controller;
|
||||||
|
|
||||||
|
import model.Game;
|
||||||
|
import model.Tile;
|
||||||
|
import view.GameView;
|
||||||
|
|
||||||
|
public class GameController {
|
||||||
|
private Game game;
|
||||||
|
private GameView gameView;
|
||||||
|
|
||||||
|
public GameController(Game game, GameView gameView) {
|
||||||
|
this.game = game;
|
||||||
|
this.gameView = gameView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeTile(Tile tile) {
|
||||||
|
game.placeTile(tile);
|
||||||
|
gameView.update(game);
|
||||||
|
}
|
||||||
|
}
|
26
TestV1/TestEnAttendantResolutionBug/model/Board.java
Normal file
26
TestV1/TestEnAttendantResolutionBug/model/Board.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Board {
|
||||||
|
private List<Tile> tiles;
|
||||||
|
|
||||||
|
public Board() {
|
||||||
|
tiles = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addTile(Tile tile) {
|
||||||
|
tiles.add(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Tile> getTiles() {
|
||||||
|
return tiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlacementValid(Tile tile) {
|
||||||
|
// Logique simplifiée pour vérifier si la tuile peut être placée
|
||||||
|
// Ici, tu pourrais vérifier les bords de la tuile et du plateau
|
||||||
|
return true; // Retourne true pour simplifier
|
||||||
|
}
|
||||||
|
}
|
26
TestV1/TestEnAttendantResolutionBug/model/Game.java
Normal file
26
TestV1/TestEnAttendantResolutionBug/model/Game.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class Game {
|
||||||
|
private Board board;
|
||||||
|
private int score;
|
||||||
|
|
||||||
|
public Game() {
|
||||||
|
board = new Board();
|
||||||
|
score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Board getBoard() {
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeTile(Tile tile) {
|
||||||
|
if (board.isPlacementValid(tile)) {
|
||||||
|
board.addTile(tile);
|
||||||
|
score += 10; // Par exemple, chaque tuile ajoute 10 points
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
TestV1/TestEnAttendantResolutionBug/model/Tile.java
Normal file
19
TestV1/TestEnAttendantResolutionBug/model/Tile.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class Tile {
|
||||||
|
private String type; // Par exemple : "forêt", "rivière", "champ", etc.
|
||||||
|
private String[] edges; // Les types des bords de la tuile (ex: "eau", "terre")
|
||||||
|
|
||||||
|
public Tile(String type, String[] edges) {
|
||||||
|
this.type = type;
|
||||||
|
this.edges = edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEdge(int index) {
|
||||||
|
return edges[index];
|
||||||
|
}
|
||||||
|
}
|
24
TestV1/TestEnAttendantResolutionBug/view/BoardView.java
Normal file
24
TestV1/TestEnAttendantResolutionBug/view/BoardView.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import model.Board;
|
||||||
|
import model.Tile;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class BoardView extends JPanel {
|
||||||
|
private Board board;
|
||||||
|
|
||||||
|
public BoardView(Board board) {
|
||||||
|
this.board = board;
|
||||||
|
setLayout(new GridLayout(5, 5, 5, 5)); // Exemple de grille 5x5 pour le plateau
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshBoard() {
|
||||||
|
removeAll();
|
||||||
|
for (Tile tile : board.getTiles()) {
|
||||||
|
add(new TileView(tile.getType()));
|
||||||
|
}
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
28
TestV1/TestEnAttendantResolutionBug/view/GameView.java
Normal file
28
TestV1/TestEnAttendantResolutionBug/view/GameView.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import model.Game;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class GameView extends JFrame {
|
||||||
|
private JLabel scoreLabel;
|
||||||
|
private BoardView boardView;
|
||||||
|
|
||||||
|
public GameView(Game game) {
|
||||||
|
setTitle("Dorfromantik en Java");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setSize(400, 400);
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
scoreLabel = new JLabel("Score : " + game.getScore());
|
||||||
|
boardView = new BoardView(game.getBoard());
|
||||||
|
|
||||||
|
add(scoreLabel, BorderLayout.NORTH);
|
||||||
|
add(boardView, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Game game) {
|
||||||
|
scoreLabel.setText("Score : " + game.getScore());
|
||||||
|
boardView.refreshBoard();
|
||||||
|
}
|
||||||
|
}
|
21
TestV1/TestEnAttendantResolutionBug/view/TileView.java
Normal file
21
TestV1/TestEnAttendantResolutionBug/view/TileView.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class TileView extends JPanel {
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public TileView(String type) {
|
||||||
|
this.type = type;
|
||||||
|
setPreferredSize(new Dimension(50, 50)); // Taille de la tuile
|
||||||
|
setBackground(Color.LIGHT_GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawString(type, 10, 25); // Affiche le type de la tuile au centre
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 421 KiB |
BIN
TestV1/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Black.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Black.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Regular.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Regular.ttf
Normal file
Binary file not shown.
BIN
TestV1/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf
Normal file
BIN
TestV1/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
TestV1/ressources/images/Application/Application_Icon.jpg
Normal file
BIN
TestV1/ressources/images/Application/Application_Icon.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
BIN
TestV1/ressources/images/MainMenu/background.jpg
Normal file
BIN
TestV1/ressources/images/MainMenu/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 444 KiB |
BIN
TestV1/ressources/images/MainMenu/backgroundBlured.jpg
Normal file
BIN
TestV1/ressources/images/MainMenu/backgroundBlured.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 231 KiB |
BIN
TestV1/ressources/images/Settings/speaker-high-volume.png
Normal file
BIN
TestV1/ressources/images/Settings/speaker-high-volume.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
TestV1/ressources/images/Settings/speaker-mute-volume.png
Normal file
BIN
TestV1/ressources/images/Settings/speaker-mute-volume.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
BIN
TestV1/ressources/sounds/Music/mainMenuMusic.wav
Normal file
BIN
TestV1/ressources/sounds/Music/mainMenuMusic.wav
Normal file
Binary file not shown.
BIN
TestV1/ressources/sounds/SFX/1.wav
Normal file
BIN
TestV1/ressources/sounds/SFX/1.wav
Normal file
Binary file not shown.
@@ -1,36 +0,0 @@
|
|||||||
package Controller; // Spécifie que cette classe fait partie du package Controller
|
|
||||||
|
|
||||||
import Model.MenuModel; // Importer la classe MenuModel
|
|
||||||
import View.MenuView;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class MenuController {
|
|
||||||
private MenuModel model;
|
|
||||||
private MenuView view;
|
|
||||||
|
|
||||||
public MenuController(MenuModel model, MenuView view) {
|
|
||||||
this.model = model;
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
view.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Initialiser le modèle avec le chemin de l'image
|
|
||||||
MenuModel model = new MenuModel("../res/fond-ecran.jpg");
|
|
||||||
|
|
||||||
// Créer la vue en lui passant l'image de fond
|
|
||||||
MenuView view = new MenuView(model);
|
|
||||||
|
|
||||||
// Démarrer le contrôleur
|
|
||||||
new MenuController(model, view).run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
### VARIABLES ###
|
|
||||||
|
|
||||||
JC = javac
|
|
||||||
JCFLAGS = -encoding UTF-8 -implicit:none
|
|
||||||
|
|
||||||
JVM = java
|
|
||||||
JVMFLAGS =
|
|
||||||
|
|
||||||
# Chemins des dossiers
|
|
||||||
SRC_CONTROLLER = Controller
|
|
||||||
SRC_MODEL = Model
|
|
||||||
SRC_VIEW = View
|
|
||||||
|
|
||||||
# Cibles pour chaque fichier .class avec leurs chemins respectifs
|
|
||||||
CONTROLLER_CLASS = $(SRC_CONTROLLER)/MenuController.class
|
|
||||||
MODEL_CLASS = $(SRC_MODEL)/MenuModel.class
|
|
||||||
VIEW_CLASS = $(SRC_VIEW)/MenuView.class
|
|
||||||
PANEL_CLASS = $(SRC_VIEW)/PanneauImage.class
|
|
||||||
TITRE_CLASS = $(SRC_VIEW)/TitreView.class
|
|
||||||
BOUTON_CLASS = $(SRC_VIEW)/BoutonView.class
|
|
||||||
### REGLES ESSENTIELLES ###
|
|
||||||
|
|
||||||
# Règle pour compiler MenuController
|
|
||||||
$(CONTROLLER_CLASS): $(SRC_CONTROLLER)/MenuController.java $(MODEL_CLASS) $(VIEW_CLASS) $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS)
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_CONTROLLER)/MenuController.java
|
|
||||||
|
|
||||||
# Règle pour compiler MenuModel
|
|
||||||
$(MODEL_CLASS): $(SRC_MODEL)/MenuModel.java
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_MODEL)/MenuModel.java
|
|
||||||
|
|
||||||
# Règle pour compiler MenuView
|
|
||||||
$(VIEW_CLASS): $(SRC_VIEW)/MenuView.java $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS)
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/MenuView.java
|
|
||||||
|
|
||||||
# Règle pour compiler PanneauImage
|
|
||||||
$(PANEL_CLASS): $(SRC_VIEW)/PanneauImage.java
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/PanneauImage.java
|
|
||||||
|
|
||||||
# Règle pour compiler TitreView
|
|
||||||
$(TITRE_CLASS): $(SRC_VIEW)/TitreView.java # Règle pour compiler TitreView
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/TitreView.java
|
|
||||||
|
|
||||||
# Règle pour compiler BoutonView
|
|
||||||
$(TITRE_CLASS): $(SRC_VIEW)/BoutonView.java # Règle pour compiler TitreView
|
|
||||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/BoutonView.java
|
|
||||||
|
|
||||||
### REGLES OPTIONNELLES ###
|
|
||||||
|
|
||||||
# Règle pour exécuter l'application
|
|
||||||
run: $(CONTROLLER_CLASS)
|
|
||||||
${JVM} ${JVMFLAGS} Controller.MenuController
|
|
||||||
|
|
||||||
# Règle pour nettoyer les fichiers .class
|
|
||||||
clean:
|
|
||||||
-rm -f $(SRC_CONTROLLER)/*.class $(SRC_MODEL)/*.class $(SRC_VIEW)/*.class
|
|
||||||
|
|
||||||
# Règle pour tout nettoyer et recompiler
|
|
||||||
mrproper: clean $(CONTROLLER_CLASS)
|
|
||||||
|
|
||||||
### BUTS FACTICES ###
|
|
||||||
|
|
||||||
.PHONY: run clean mrproper
|
|
@@ -1,50 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
public class Menu extends JFrame {
|
|
||||||
|
|
||||||
private Image imageDeFond;
|
|
||||||
|
|
||||||
public Menu() {
|
|
||||||
// Charge l'image de fond
|
|
||||||
try {
|
|
||||||
imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration de la fenêtre
|
|
||||||
setTitle(" Dorfromantik");
|
|
||||||
setSize(800, 600); // Taille de la fenêtre
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
|
|
||||||
// Ajouter le panneau avec image de fond
|
|
||||||
setContentPane(new PanneauImage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Classe interne pour le panneau personnalisé qui dessine l'image en fond
|
|
||||||
class PanneauImage extends JPanel {
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
if (imageDeFond != null) {
|
|
||||||
g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new Menu().setVisible(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
package Model;
|
|
||||||
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
public class MenuModel {
|
|
||||||
private Image imageDeFond;
|
|
||||||
|
|
||||||
public MenuModel(String imagePath) {
|
|
||||||
// Charger l'image de fond
|
|
||||||
try {
|
|
||||||
imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image getImageDeFond() {
|
|
||||||
return imageDeFond;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
package View;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
public class BoutonView extends JButton {
|
|
||||||
public BoutonView(String texte) {
|
|
||||||
super(texte);
|
|
||||||
|
|
||||||
setFont(new Font("Arial", Font.BOLD, 40));
|
|
||||||
setForeground(Color.WHITE); // Couleur du texte blanc
|
|
||||||
setFocusPainted(false); // Enlever le focus sur le bouton
|
|
||||||
setBorderPainted(false); // Enlever la bordure par défaut
|
|
||||||
setContentAreaFilled(false); // Fond transparent
|
|
||||||
setOpaque(false); // Ne dessine pas le fond par défaut
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,51 +0,0 @@
|
|||||||
package View;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import Model.MenuModel;
|
|
||||||
|
|
||||||
public class MenuView extends JFrame {
|
|
||||||
private PanneauImage panneauImage;
|
|
||||||
private TitreView titreView;
|
|
||||||
private BoutonView boutonJouer;
|
|
||||||
private BoutonView boutonCommentJouer;
|
|
||||||
private BoutonView boutonQuitter;
|
|
||||||
|
|
||||||
public MenuView(MenuModel model) {
|
|
||||||
|
|
||||||
setTitle("Dorfromantik");
|
|
||||||
setSize(800, 600);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
|
|
||||||
panneauImage = new PanneauImage(model.getImageDeFond());
|
|
||||||
setContentPane(panneauImage);
|
|
||||||
titreView = new TitreView();
|
|
||||||
|
|
||||||
JPanel panelTitre = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
|
||||||
panelTitre.setOpaque(false);
|
|
||||||
panelTitre.add(titreView.getTitre());
|
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
add(panelTitre, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
JPanel panelBouton = new JPanel();
|
|
||||||
panelBouton.setOpaque(false); // Panneau transparent pour ne pas couvrir l'image de fond
|
|
||||||
panelBouton.setLayout(new BoxLayout(panelBouton, BoxLayout.Y_AXIS)); // Disposition verticale
|
|
||||||
|
|
||||||
// Initialisation des boutons
|
|
||||||
boutonJouer = new BoutonView("Jouer");
|
|
||||||
boutonCommentJouer = new BoutonView("Comment Jouer ?");
|
|
||||||
boutonQuitter = new BoutonView("Quitter");
|
|
||||||
|
|
||||||
panelBouton.add(boutonJouer);
|
|
||||||
panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
|
||||||
panelBouton.add(boutonCommentJouer);
|
|
||||||
panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
|
||||||
panelBouton.add(boutonQuitter);
|
|
||||||
|
|
||||||
add(panelBouton, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
package View;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class PanneauImage extends JPanel {
|
|
||||||
private Image imageDeFond;
|
|
||||||
|
|
||||||
public PanneauImage(Image image) {
|
|
||||||
this.imageDeFond = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
if (imageDeFond != null) {
|
|
||||||
g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,68 +0,0 @@
|
|||||||
package View;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class TitreView {
|
|
||||||
private ContourLabel titre;
|
|
||||||
|
|
||||||
public TitreView() {
|
|
||||||
// Créer une instance de ContourLabel avec le texte souhaité
|
|
||||||
titre = new ContourLabel("Dorfromantik");
|
|
||||||
|
|
||||||
// Définir la police et les couleurs
|
|
||||||
titre.setFont(new Font("Algerian", Font.BOLD, 70));
|
|
||||||
titre.setForeground(Color.WHITE); // Couleur du texte principal
|
|
||||||
titre.setContourColor(Color.BLACK); // Couleur du contour
|
|
||||||
titre.setContourThickness(4); // Épaisseur du contour
|
|
||||||
}
|
|
||||||
|
|
||||||
public JLabel getTitre() {
|
|
||||||
return titre;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Classe interne pour gérer le contour autour du texte
|
|
||||||
private static class ContourLabel extends JLabel {
|
|
||||||
private Color contourColor = Color.BLACK;
|
|
||||||
private int contourThickness = 2;
|
|
||||||
|
|
||||||
public ContourLabel(String text) {
|
|
||||||
super(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContourColor(Color contourColor) {
|
|
||||||
this.contourColor = contourColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContourThickness(int contourThickness) {
|
|
||||||
this.contourThickness = contourThickness;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
Graphics2D g2d = (Graphics2D) g.create();
|
|
||||||
|
|
||||||
// Activer l'anti-aliasing
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
|
|
||||||
// Dessiner le contour
|
|
||||||
g2d.setFont(getFont());
|
|
||||||
g2d.setColor(contourColor);
|
|
||||||
g2d.setStroke(new BasicStroke(contourThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
|
||||||
FontMetrics fm = g2d.getFontMetrics();
|
|
||||||
int x = 0;
|
|
||||||
int y = fm.getAscent();
|
|
||||||
g2d.draw(getTextShape(g2d, getText(), x, y));
|
|
||||||
|
|
||||||
// Dessiner le texte principal
|
|
||||||
g2d.setColor(getForeground());
|
|
||||||
g2d.fill(getTextShape(g2d, getText(), x, y));
|
|
||||||
|
|
||||||
g2d.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Shape getTextShape(Graphics2D g2d, String text, int x, int y) {
|
|
||||||
return getFont().createGlyphVector(g2d.getFontRenderContext(), text).getOutline(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
45
TestV1/src/fr/monkhanny/dorfromantik/Main.java
Normal file
45
TestV1/src/fr/monkhanny/dorfromantik/Main.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package fr.monkhanny.dorfromantik;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
import fr.monkhanny.dorfromantik.controller.MainMenuResizeController;
|
||||||
|
import fr.monkhanny.dorfromantik.controller.MainMenuButtonController;
|
||||||
|
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.Musics;
|
||||||
|
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe principale du jeu
|
||||||
|
* @version 1.0
|
||||||
|
* @author Moncef STITI
|
||||||
|
* @see MainMenu
|
||||||
|
* @see MainMenuResizeController
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
/**
|
||||||
|
* Méthode principale du jeu
|
||||||
|
* @param args Tableau de String contenant les arguments passé en paramètre au programme
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Créer la fenêtre des paramètres
|
||||||
|
JFrame settingsFrame = new JFrame("Paramètres");
|
||||||
|
|
||||||
|
// Menu principal
|
||||||
|
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC);
|
||||||
|
MusicPlayer.playMusic();
|
||||||
|
MainMenu mainMenu = new MainMenu();
|
||||||
|
MainMenuResizeController MainMenuResizeController = new MainMenuResizeController(mainMenu);
|
||||||
|
MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame);
|
||||||
|
|
||||||
|
|
||||||
|
// Fenêtre des paramètres
|
||||||
|
SettingsWindowListener windowListener = new SettingsWindowListener(mainMenu, settingsFrame);
|
||||||
|
SettingsPanel settingsPanel = new SettingsPanel(mainMenu, settingsFrame);
|
||||||
|
settingsFrame.addWindowListener(windowListener);
|
||||||
|
settingsFrame.add(settingsPanel);
|
||||||
|
settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
54
TestV1/src/fr/monkhanny/dorfromantik/Options.java
Normal file
54
TestV1/src/fr/monkhanny/dorfromantik/Options.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package fr.monkhanny.dorfromantik;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
|
public class Options {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taille de police de base pour les titres du menu principal
|
||||||
|
*/
|
||||||
|
public static final float BASE_TITLE_FONT_SIZE = 80f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taille de police de base pour les boutons du menu principal
|
||||||
|
*/
|
||||||
|
public static final float BASE_BUTTON_FONT_SIZE = 45f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Niveau de volume par défaut
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_VOLUME = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Musique en sourdine ou non
|
||||||
|
*/
|
||||||
|
public static boolean MUSIC_MUTED = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sons en sourdine ou non
|
||||||
|
*/
|
||||||
|
public static boolean SOUNDS_MUTED = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Couleur de subrillance des boutons
|
||||||
|
*/
|
||||||
|
public static final Color BUTTON_HOVER_COLOR = new Color(70, 130, 180);
|
||||||
|
|
||||||
|
|
||||||
|
public static final float HOVER_FONT_SCALE = 1.1f;
|
||||||
|
public static final int ANIMATION_STEPS = 10;
|
||||||
|
public static final int ANIMATION_DELAY = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volume de la musique
|
||||||
|
*/
|
||||||
|
public static int MUSIC_VOLUME = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volume des bruitages
|
||||||
|
*/
|
||||||
|
public static int SOUNDS_VOLUME = 60;
|
||||||
|
|
||||||
|
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
||||||
|
}
|
48
TestV1/src/fr/monkhanny/dorfromantik/components/Button.java
Normal file
48
TestV1/src/fr/monkhanny/dorfromantik/components/Button.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.components;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Button {
|
||||||
|
|
||||||
|
public static JButton createCustomTextButton(String text, float fontSize) {
|
||||||
|
JButton button = new JButton(text);
|
||||||
|
button.setFocusPainted(false); // Retirer le focus
|
||||||
|
button.setBackground(new Color(102, 178, 255)); // Couleur de fond
|
||||||
|
button.setForeground(Color.WHITE); // Couleur du texte
|
||||||
|
button.setFont(FontManager.getButtonFont(fontSize)); // Appliquer la police du bouton
|
||||||
|
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); // Espacement autour du texte du bouton
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JButton createCustomIconButton(String iconPath) {
|
||||||
|
// Créer le bouton
|
||||||
|
JButton button = new JButton();
|
||||||
|
button.setFocusPainted(false); // Retirer le focus
|
||||||
|
|
||||||
|
// Charger l'icône depuis le chemin spécifié
|
||||||
|
ImageIcon icon = new ImageIcon(iconPath);
|
||||||
|
|
||||||
|
// Calculer automatiquement la taille de l'icône pour l'adapter à la taille du bouton
|
||||||
|
int buttonWidth = 100; // Taille du bouton (largeur)
|
||||||
|
int buttonHeight = 100; // Taille du bouton (hauteur)
|
||||||
|
|
||||||
|
// Vous pouvez ajuster ces valeurs ou les calculer dynamiquement en fonction de la taille du bouton
|
||||||
|
Image img = icon.getImage();
|
||||||
|
Image resizedImage = img.getScaledInstance(buttonWidth, buttonHeight, Image.SCALE_SMOOTH);
|
||||||
|
button.setIcon(new ImageIcon(resizedImage));
|
||||||
|
|
||||||
|
// Optionnel : changer la couleur de fond ou de bordure si nécessaire
|
||||||
|
button.setBackground(new Color(102, 178, 255)); // Couleur de fond (facultatif)
|
||||||
|
|
||||||
|
// Retirer la bordure du bouton (facultatif)
|
||||||
|
button.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
|
||||||
|
// Redimensionner le bouton pour s'adapter à l'icône si nécessaire
|
||||||
|
button.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
27
TestV1/src/fr/monkhanny/dorfromantik/components/Title.java
Normal file
27
TestV1/src/fr/monkhanny/dorfromantik/components/Title.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.components;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Title extends JLabel {
|
||||||
|
|
||||||
|
public Title(String text, float fontSize) {
|
||||||
|
super(text, SwingConstants.CENTER);
|
||||||
|
setFont(FontManager.getTitleFont(fontSize));
|
||||||
|
setForeground(Color.WHITE);
|
||||||
|
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Title(String text, float fontSize, Color textColor) {
|
||||||
|
super(text, SwingConstants.CENTER);
|
||||||
|
setFont(FontManager.getTitleFont(fontSize));
|
||||||
|
setForeground(textColor);
|
||||||
|
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTitleFont(float fontSize) {
|
||||||
|
setFont(FontManager.getTitleFont(fontSize));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.gui;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class ButtonHoverAnimationListener implements ActionListener {
|
||||||
|
|
||||||
|
private int step = 0;
|
||||||
|
private final float scaleIncrement;
|
||||||
|
private final boolean entering;
|
||||||
|
private final JButton button;
|
||||||
|
private final Color originalColor;
|
||||||
|
private final Font originalFont;
|
||||||
|
private float currentScale = 1.0f;
|
||||||
|
|
||||||
|
public ButtonHoverAnimationListener(boolean entering, JButton button, Color originalColor, Font originalFont) {
|
||||||
|
this.entering = entering;
|
||||||
|
this.button = button;
|
||||||
|
this.originalColor = originalColor;
|
||||||
|
this.originalFont = originalFont;
|
||||||
|
this.scaleIncrement = (Options.HOVER_FONT_SCALE - 1.0f) / Options.ANIMATION_STEPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
currentScale = entering ? (1.0f + step * scaleIncrement) : (Options.HOVER_FONT_SCALE - step * scaleIncrement);
|
||||||
|
|
||||||
|
button.setForeground(entering ? Options.BUTTON_HOVER_COLOR : originalColor);
|
||||||
|
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
|
||||||
|
|
||||||
|
step++;
|
||||||
|
if (step >= Options.ANIMATION_STEPS) {
|
||||||
|
((Timer) e.getSource()).stop();
|
||||||
|
if (!entering) {
|
||||||
|
button.setFont(originalFont); // Restore the original font
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||||
|
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.Sounds;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class ButtonHoverListener extends MouseAdapter {
|
||||||
|
|
||||||
|
private final ButtonHoverAnimator animator;
|
||||||
|
|
||||||
|
public ButtonHoverListener(ButtonHoverAnimator animator) {
|
||||||
|
this.animator = animator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
animator.startAnimation(true);
|
||||||
|
MusicPlayer.loadSound(Sounds.SOUNDS1); // Charge le son
|
||||||
|
MusicPlayer.playSound(); // Joue le son
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
animator.startAnimation(false);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,99 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
public class MainMenuButtonController implements ActionListener {
|
||||||
|
|
||||||
|
private MainMenu mainMenu;
|
||||||
|
|
||||||
|
private JFrame settingsFrame;
|
||||||
|
|
||||||
|
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame) {
|
||||||
|
this.mainMenu = mainMenu;
|
||||||
|
// Ajouter les écouteurs d'événements sur les boutons
|
||||||
|
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
||||||
|
|
||||||
|
// Attacher les actions aux boutons
|
||||||
|
buttonPanel.getNewGameButton().addActionListener(this);
|
||||||
|
buttonPanel.getContinueGameButton().addActionListener(this);
|
||||||
|
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||||
|
buttonPanel.getSettingsButton().addActionListener(this);
|
||||||
|
buttonPanel.getExitButton().addActionListener(this);
|
||||||
|
|
||||||
|
// Créer la fenêtre des paramètres
|
||||||
|
this.settingsFrame = settingsFrame;
|
||||||
|
this.settingsFrame.setLocationRelativeTo(null);
|
||||||
|
this.settingsFrame.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String command = e.getActionCommand();
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case "Nouvelle partie":
|
||||||
|
startNewGame();
|
||||||
|
break;
|
||||||
|
case "Continuer une partie":
|
||||||
|
continueGame();
|
||||||
|
break;
|
||||||
|
case "Comment jouer ?":
|
||||||
|
showHowToPlay();
|
||||||
|
break;
|
||||||
|
case "Paramètres":
|
||||||
|
openSettings();
|
||||||
|
break;
|
||||||
|
case "Quitter":
|
||||||
|
exitGame();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Commande inconnue: " + command);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startNewGame() {
|
||||||
|
System.out.println("Démarrer une nouvelle partie...");
|
||||||
|
// Logic to start a new game
|
||||||
|
}
|
||||||
|
|
||||||
|
private void continueGame() {
|
||||||
|
System.out.println("Continuer une partie...");
|
||||||
|
// Logic to continue the game
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHowToPlay() {
|
||||||
|
System.out.println("Afficher comment jouer...");
|
||||||
|
// Logic to show how to play
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitGame() {
|
||||||
|
System.exit(0); // Fermer l'application
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openSettings() {
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Afficher la fenêtre des paramètres
|
||||||
|
this.settingsFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class MainMenuMouseController {
|
||||||
|
|
||||||
|
private final ButtonPanel buttonPanel;
|
||||||
|
|
||||||
|
public MainMenuMouseController(ButtonPanel buttonPanel) {
|
||||||
|
this.buttonPanel = buttonPanel;
|
||||||
|
initMouseListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMouseListeners() {
|
||||||
|
addButtonHoverListener(buttonPanel.getNewGameButton());
|
||||||
|
addButtonHoverListener(buttonPanel.getContinueGameButton());
|
||||||
|
addButtonHoverListener(buttonPanel.getHowToPlayButton());
|
||||||
|
addButtonHoverListener(buttonPanel.getSettingsButton());
|
||||||
|
addButtonHoverListener(buttonPanel.getExitButton());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addButtonHoverListener(JButton button) {
|
||||||
|
ButtonHoverAnimator animator = new ButtonHoverAnimator(button);
|
||||||
|
button.addMouseListener(new ButtonHoverListener(animator));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,19 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
|
||||||
|
public class MainMenuResizeController {
|
||||||
|
|
||||||
|
private MainMenu mainMenu;
|
||||||
|
private MainMenuResizeHandler resizeHandler;
|
||||||
|
|
||||||
|
public MainMenuResizeController(MainMenu mainMenu) {
|
||||||
|
this.mainMenu = mainMenu;
|
||||||
|
this.resizeHandler = new MainMenuResizeHandler(mainMenu);
|
||||||
|
addComponentListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addComponentListener() {
|
||||||
|
mainMenu.addComponentListener(resizeHandler);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user