resolution bug score dans le mode 1 mais bug dans le mode 2,3 et 4
@@ -1,12 +0,0 @@
|
|||||||
public class GameController {
|
|
||||||
private GameView view;
|
|
||||||
|
|
||||||
public GameController(GameView view) {
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startGame() {
|
|
||||||
System.out.println("Bienvenue dans Dorfromantik simplifié !");
|
|
||||||
view.showTile();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class GameView extends JFrame {
|
|
||||||
private Tile tile; // La tuile à afficher
|
|
||||||
|
|
||||||
// Constructeur
|
|
||||||
public GameView(Tile tile) {
|
|
||||||
this.tile = tile;
|
|
||||||
setTitle("Dorfromantik - Affichage de tuile");
|
|
||||||
setSize(400, 400);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Méthode pour démarrer l'affichage
|
|
||||||
public void showTile() {
|
|
||||||
setVisible(true);
|
|
||||||
repaint(); // Re-dessine la fenêtre
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
|
|
||||||
// Récupère la matrice de la tuile
|
|
||||||
Terrain[][] matrix = tile.getHexMatrix();
|
|
||||||
|
|
||||||
// Dessine les terrains sous forme de rectangles
|
|
||||||
int hexSize = 50; // Taille de chaque "hexagone" simplifiée
|
|
||||||
int xOffset = 100, yOffset = 100; // Décalage pour centrer
|
|
||||||
|
|
||||||
for (int i = 0; i < matrix.length; i++) {
|
|
||||||
for (int j = 0; j < matrix[i].length; j++) {
|
|
||||||
if (matrix[i][j] != Terrain.VIDE) {
|
|
||||||
// Définit une couleur en fonction du terrain
|
|
||||||
g.setColor(getColorForTerrain(matrix[i][j]));
|
|
||||||
// Dessine un rectangle pour représenter un hexagone (simplifié)
|
|
||||||
g.fillRect(xOffset + j * hexSize, yOffset + i * hexSize, hexSize, hexSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Méthode utilitaire pour associer une couleur à un terrain
|
|
||||||
private Color getColorForTerrain(Terrain terrain) {
|
|
||||||
switch (terrain) {
|
|
||||||
case MER:
|
|
||||||
return Color.BLUE;
|
|
||||||
case CHAMP:
|
|
||||||
return Color.YELLOW;
|
|
||||||
case PRE:
|
|
||||||
return Color.GREEN;
|
|
||||||
case FORET:
|
|
||||||
return new Color(34, 139, 34); // Vert foncé
|
|
||||||
case MONTAGNE:
|
|
||||||
return Color.GRAY;
|
|
||||||
default:
|
|
||||||
return Color.BLACK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Exemple : création d'une tuile avec deux terrains
|
|
||||||
Tile tile = new Tile(Terrain.MER, Terrain.FORET, 1);
|
|
||||||
|
|
||||||
// Vue graphique
|
|
||||||
GameView view = new GameView(tile);
|
|
||||||
|
|
||||||
// Contrôleur
|
|
||||||
GameController controller = new GameController(view);
|
|
||||||
|
|
||||||
// Démarrer le jeu
|
|
||||||
controller.startGame();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,6 +11,7 @@ SOURCEDIR = ./src/
|
|||||||
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
|
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
@make clean
|
||||||
@make compile
|
@make compile
|
||||||
@make jar
|
@make jar
|
||||||
@make run
|
@make run
|
||||||
|
45261
TestV1/SQL_DATABASE.sql
Normal file
@@ -1,40 +0,0 @@
|
|||||||
# Directories
|
|
||||||
SRC_DIR = src
|
|
||||||
BIN_DIR = bin
|
|
||||||
|
|
||||||
# Find all source files and corresponding class files
|
|
||||||
SOURCES = $(shell find $(SRC_DIR) -name "*.java")
|
|
||||||
CLASSES = $(SOURCES:$(SRC_DIR)/%.java=$(BIN_DIR)/%.class)
|
|
||||||
|
|
||||||
# Main class for execution
|
|
||||||
MAIN_CLASS = controller.Main
|
|
||||||
|
|
||||||
# Java compiler and runner
|
|
||||||
JAVAC = javac
|
|
||||||
JAVA = java
|
|
||||||
JFLAGS = -d $(BIN_DIR) -cp $(SRC_DIR):$(BIN_DIR) # Ajout du classpath src/ et bin/
|
|
||||||
|
|
||||||
# Default target: Compile and run
|
|
||||||
all: clean compile run
|
|
||||||
|
|
||||||
# Compile all Java source files
|
|
||||||
compile: $(CLASSES)
|
|
||||||
@echo "Compilation terminée."
|
|
||||||
|
|
||||||
# Rule to compile each .java file to a .class file
|
|
||||||
$(BIN_DIR)/%.class: $(SRC_DIR)/%.java
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
$(JAVAC) $(JFLAGS) $<
|
|
||||||
|
|
||||||
# Run the application
|
|
||||||
run:
|
|
||||||
@echo "Exécution de l'application..."
|
|
||||||
$(JAVA) -cp $(BIN_DIR):$(SRC_DIR) $(MAIN_CLASS)
|
|
||||||
|
|
||||||
# Clean compiled files
|
|
||||||
clean:
|
|
||||||
@echo "Nettoyage des fichiers compilés..."
|
|
||||||
rm -rf $(BIN_DIR)/*
|
|
||||||
|
|
||||||
# Phony targets to avoid conflicts
|
|
||||||
.PHONY: all compile run clean
|
|
@@ -1,31 +0,0 @@
|
|||||||
package controller;
|
|
||||||
|
|
||||||
import model.Board;
|
|
||||||
import view.GameView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contrôleur principal du jeu, reliant la vue et le modèle.
|
|
||||||
*/
|
|
||||||
public class GameController {
|
|
||||||
private final Board board;
|
|
||||||
private final GameView view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructeur du contrôleur du jeu.
|
|
||||||
*
|
|
||||||
* @param board Le modèle du plateau de jeu.
|
|
||||||
* @param view La vue graphique du jeu.
|
|
||||||
*/
|
|
||||||
public GameController(Board board, GameView view) {
|
|
||||||
this.board = board;
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Démarre le jeu en affichant la vue.
|
|
||||||
*/
|
|
||||||
public void startGame() {
|
|
||||||
view.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,24 +0,0 @@
|
|||||||
package controller;
|
|
||||||
|
|
||||||
import model.Board;
|
|
||||||
import view.GameView;
|
|
||||||
import model.Tile;
|
|
||||||
import utils.Database;
|
|
||||||
import utils.TileRepository;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import model.TileGenerator;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
long seed = System.currentTimeMillis();
|
|
||||||
Board board = new Board();
|
|
||||||
GameView gameView = new GameView(board, seed);
|
|
||||||
gameView.setVisible(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Board {
|
|
||||||
private final Map<Point, Tile> tiles;
|
|
||||||
|
|
||||||
public Board() {
|
|
||||||
this.tiles = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPositionOccupied(Point position) {
|
|
||||||
return tiles.containsKey(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTile(Point position, Tile tile) {
|
|
||||||
tiles.put(position, tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tile getTile(Point position) {
|
|
||||||
return tiles.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Point, Tile> getTiles() {
|
|
||||||
return tiles;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public enum Terrain {
|
|
||||||
MER, CHAMP, FORET, PRE, MONTAGNE
|
|
||||||
}
|
|
@@ -1,33 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public class Tile {
|
|
||||||
private final Terrain terrain1;
|
|
||||||
private final Terrain terrain2;
|
|
||||||
private final int terrain1Sides; // Nombre de côtés attribués à terrain1 (1, 2 ou 3)
|
|
||||||
|
|
||||||
public Tile(Terrain terrain1, Terrain terrain2, int terrain1Sides) {
|
|
||||||
this.terrain1 = terrain1;
|
|
||||||
this.terrain2 = terrain2;
|
|
||||||
this.terrain1Sides = terrain1Sides;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Terrain getTerrain1() {
|
|
||||||
return terrain1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Terrain getTerrain2() {
|
|
||||||
return terrain2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTerrain1Sides() {
|
|
||||||
return terrain1Sides;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTerrain2Sides() {
|
|
||||||
return 6 - terrain1Sides; // Le reste des côtés
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasSingleTerrain() {
|
|
||||||
return terrain2 == null;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class TileGenerator {
|
|
||||||
private final Random random;
|
|
||||||
|
|
||||||
public TileGenerator(long seed) {
|
|
||||||
this.random = new Random(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tile generateRandomTile() {
|
|
||||||
Terrain terrain1 = Terrain.values()[random.nextInt(Terrain.values().length)];
|
|
||||||
if (random.nextBoolean()) { // 50% chance d'avoir un seul terrain
|
|
||||||
return new Tile(terrain1, null, 6); // Toutes les faces au même terrain
|
|
||||||
}
|
|
||||||
|
|
||||||
Terrain terrain2;
|
|
||||||
do {
|
|
||||||
terrain2 = Terrain.values()[random.nextInt(Terrain.values().length)];
|
|
||||||
} while (terrain2 == terrain1); // Assurer deux terrains différents
|
|
||||||
|
|
||||||
int terrain1Sides = switch (random.nextInt(3)) { // 0, 1 ou 2 -> 1+5, 2+4, 3+3
|
|
||||||
case 0 -> 1;
|
|
||||||
case 1 -> 2;
|
|
||||||
default -> 3;
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Tile(terrain1, terrain2, terrain1Sides);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,63 +0,0 @@
|
|||||||
package utils;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class Database {
|
|
||||||
private static final String URL = "jdbc:mariadb://dwarves.iut-fbleau.fr/foulou";
|
|
||||||
private static final String LOGIN = "foulou";
|
|
||||||
private static final String PASSWORD = "foulou";
|
|
||||||
|
|
||||||
private Connection database;
|
|
||||||
|
|
||||||
public Database() throws SQLException {
|
|
||||||
try {
|
|
||||||
// Chargement explicite du driver
|
|
||||||
System.out.println("Tentative de chargement du driver MariaDB...");
|
|
||||||
Class.forName("org.mariadb.jdbc.Driver");
|
|
||||||
System.out.println("Driver MariaDB chargé avec succès.");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connexion à la base de données
|
|
||||||
System.out.println("Tentative de connexion à la base de données...");
|
|
||||||
this.database = DriverManager.getConnection(URL, LOGIN, PASSWORD);
|
|
||||||
System.out.println("Connexion réussie !");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Échec de la connexion à la base de données : " + e.getMessage());
|
|
||||||
throw new SQLException("Erreur de connexion : " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
System.err.println("Erreur : Le driver MariaDB n'a pas été trouvé dans le classpath.");
|
|
||||||
throw new SQLException("Driver MariaDB introuvable dans le classpath", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getDatabase() {
|
|
||||||
return this.database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
try {
|
|
||||||
if (this.database != null && !this.database.isClosed()) {
|
|
||||||
this.database.close();
|
|
||||||
System.out.println("Connexion fermée.");
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Erreur lors de la fermeture de la base de données : " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
// Crée une instance de la classe Database et teste la connexion
|
|
||||||
Database db = new Database();
|
|
||||||
System.out.println("Connexion à la base de données réussie !");
|
|
||||||
|
|
||||||
// Fermer la connexion après test
|
|
||||||
db.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Erreur lors de la connexion : " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package utils;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import model.Tile;
|
|
||||||
|
|
||||||
|
|
||||||
public class TileRepository {
|
|
||||||
|
|
||||||
private final Database database;
|
|
||||||
|
|
||||||
public TileRepository(Database database) {
|
|
||||||
this.database = database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveTile(Tile tile) throws SQLException {
|
|
||||||
String query = "INSERT INTO tiles (terrain1, terrain2) VALUES (?, ?)";
|
|
||||||
|
|
||||||
try (Connection connection = database.getDatabase();
|
|
||||||
PreparedStatement statement = connection.prepareStatement(query)) {
|
|
||||||
|
|
||||||
statement.setString(1, tile.getTerrain1().toString());
|
|
||||||
|
|
||||||
if (tile.getTerrain2() != null) {
|
|
||||||
statement.setString(2, tile.getTerrain2().toString());
|
|
||||||
} else {
|
|
||||||
statement.setNull(2, java.sql.Types.VARCHAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,147 +0,0 @@
|
|||||||
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 model.Terrain;
|
|
||||||
import model.TileGenerator;
|
|
||||||
|
|
||||||
|
|
||||||
public class GameView extends JFrame {
|
|
||||||
private final Board board;
|
|
||||||
private final TileGenerator tileGenerator;
|
|
||||||
private final int hexRadius = 60;
|
|
||||||
private final int hexWidth = (int) (Math.sqrt(3) * hexRadius); // Largeur d'un hexagone
|
|
||||||
private final int hexHeight = 2 * hexRadius; // Hauteur d'un hexagone
|
|
||||||
|
|
||||||
|
|
||||||
public GameView(Board board, long seed) {
|
|
||||||
this.board = board;
|
|
||||||
this.tileGenerator = new TileGenerator(seed); // Initialisation avec la seed
|
|
||||||
setTitle("Dorfromantik - Plateau");
|
|
||||||
setSize(800, 800);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
|
|
||||||
addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
handleMouseClick(e.getPoint());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleMouseClick(Point clickPoint) {
|
|
||||||
Point hexPosition = calculateHexCoordinates(clickPoint);
|
|
||||||
|
|
||||||
if (!board.isPositionOccupied(hexPosition)) {
|
|
||||||
Tile newTile = tileGenerator.generateRandomTile();
|
|
||||||
board.addTile(hexPosition, newTile);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
|
|
||||||
for (Point position : board.getTiles().keySet()) {
|
|
||||||
Tile tile = board.getTile(position);
|
|
||||||
int x = calculateScreenX(position);
|
|
||||||
int y = calculateScreenY(position);
|
|
||||||
drawLargeHexagon(g, x, y, tile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawLargeHexagon(Graphics g, int x, int y, Tile tile) {
|
|
||||||
int r = hexRadius;
|
|
||||||
int h = (int) (Math.sqrt(3) / 2 * r);
|
|
||||||
|
|
||||||
int[] xPoints = {x + r, x + r / 2, x - r / 2, x - r, x - r / 2, x + r / 2};
|
|
||||||
int[] yPoints = {y, y + h, y + h, y, y - h, y - h};
|
|
||||||
|
|
||||||
if (tile.hasSingleTerrain()) {
|
|
||||||
g.setColor(getColorForTerrain(tile.getTerrain1()));
|
|
||||||
g.fillPolygon(xPoints, yPoints, 6);
|
|
||||||
} else {
|
|
||||||
// Deux terrains : appliquer la répartition spécifique
|
|
||||||
int terrain1Sides = tile.getTerrain1Sides();
|
|
||||||
Color color1 = getColorForTerrain(tile.getTerrain1());
|
|
||||||
Color color2 = getColorForTerrain(tile.getTerrain2());
|
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
int next = (i + 1) % 6; // Prochain point
|
|
||||||
|
|
||||||
if (i < terrain1Sides) {
|
|
||||||
g.setColor(color1);
|
|
||||||
} else {
|
|
||||||
g.setColor(color2);
|
|
||||||
}
|
|
||||||
|
|
||||||
g.fillPolygon(
|
|
||||||
new int[]{x, xPoints[i], xPoints[next]},
|
|
||||||
new int[]{y, yPoints[i], yPoints[next]},
|
|
||||||
3
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawPolygon(xPoints, yPoints, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Dans la classe GameView.java
|
|
||||||
private Color getColorForTerrain(Terrain terrain) {
|
|
||||||
if (terrain == null) {
|
|
||||||
return Color.GRAY; // Retourner une couleur par défaut si le terrain est null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mappage des couleurs pour chaque terrain
|
|
||||||
switch (terrain) {
|
|
||||||
case MER:
|
|
||||||
return new Color(0, 0, 255); // Bleu pour MER
|
|
||||||
case CHAMP:
|
|
||||||
return new Color(0, 255, 0); // Vert pour CHAMP
|
|
||||||
case FORET:
|
|
||||||
return new Color(34, 139, 34); // Vert foncé pour FORET
|
|
||||||
case PRE:
|
|
||||||
return new Color(255, 255, 0); // Jaune pour PRE
|
|
||||||
case MONTAGNE:
|
|
||||||
return new Color(139, 69, 19); // Marron pour MONTAGNE
|
|
||||||
default:
|
|
||||||
return Color.GRAY; // Couleur par défaut pour les cas non gérés
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Point calculateHexCoordinates(Point clickPoint) {
|
|
||||||
// Rayon et espacement vertical/hexagonal
|
|
||||||
int r = hexRadius;
|
|
||||||
double h = Math.sqrt(3) * r / 2; // Hauteur effective entre deux lignes
|
|
||||||
|
|
||||||
// Calcul approximatif de la colonne et de la ligne
|
|
||||||
int col = (int) Math.round((double) clickPoint.x / (1.5 * r));
|
|
||||||
int row = (int) Math.round((double) (clickPoint.y - (col % 2) * h) / (Math.sqrt(3) * r));
|
|
||||||
|
|
||||||
return new Point(col, row);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private int calculateScreenX(Point position) {
|
|
||||||
int col = position.x;
|
|
||||||
return col * (int) (1.5 * hexRadius); // Espacement horizontal
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calculateScreenY(Point position) {
|
|
||||||
int col = position.x;
|
|
||||||
int row = position.y;
|
|
||||||
return row * (int) (Math.sqrt(3) * hexRadius) + (col % 2) * (int) (Math.sqrt(3) / 2 * hexRadius);
|
|
||||||
// Décalage vertical pour les colonnes impaires
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
BIN
TestV1/ressources/images/Icone/ExitIcon.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
TestV1/ressources/images/Icone/ExitIcon2.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
TestV1/ressources/images/MainMenu/Leaderboard/1.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
TestV1/ressources/images/MainMenu/Leaderboard/2.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
TestV1/ressources/images/MainMenu/Leaderboard/3.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
TestV1/ressources/images/Recompense/1.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
TestV1/ressources/images/Recompense/2.png
Normal file
After Width: | Height: | Size: 58 KiB |
BIN
TestV1/ressources/images/Recompense/3.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
TestV1/ressources/images/Recompense/4.png
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
TestV1/ressources/images/Recompense/5.png
Normal file
After Width: | Height: | Size: 98 KiB |
BIN
TestV1/ressources/images/Recompense/6.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
TestV1/ressources/images/Recompense/7.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
TestV1/ressources/images/Recompense/8.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
TestV1/ressources/images/Recompense/9.png
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
TestV1/src/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/monkhanny/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/monkhanny/dorfromantik/.DS_Store
vendored
Normal file
@@ -1,14 +1,16 @@
|
|||||||
package fr.monkhanny.dorfromantik;
|
package fr.monkhanny.dorfromantik;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
|
||||||
import fr.monkhanny.dorfromantik.controller.MainMenuResizeController;
|
import fr.monkhanny.dorfromantik.controller.MainMenuResizeController;
|
||||||
import fr.monkhanny.dorfromantik.controller.MainMenuButtonController;
|
import fr.monkhanny.dorfromantik.controller.MainMenuButtonController;
|
||||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||||
import fr.monkhanny.dorfromantik.enums.Musics;
|
import fr.monkhanny.dorfromantik.enums.Musics;
|
||||||
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
import fr.monkhanny.dorfromantik.listeners.CloseWindowListener;
|
||||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||||
import fr.monkhanny.dorfromantik.controller.TutorialController;
|
import fr.monkhanny.dorfromantik.controller.TutorialController;
|
||||||
|
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
@@ -20,37 +22,89 @@ import javax.swing.JFrame;
|
|||||||
* @see MainMenuResizeController
|
* @see MainMenuResizeController
|
||||||
*/
|
*/
|
||||||
public class Main {
|
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");
|
|
||||||
|
|
||||||
// Créer la fenêtre du tutoriel
|
private static JFrame gameModeFrame;
|
||||||
JFrame howToPlayFrame = new JFrame("Comment jouer ?");
|
private static JFrame gameFrame;
|
||||||
|
private static JFrame settingsFrame;
|
||||||
|
private static JFrame howToPlayFrame;
|
||||||
|
private static JFrame rewardsFrame;
|
||||||
|
|
||||||
// Menu principal
|
// Variable statique pour savoir si la musique a été jouée
|
||||||
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC);
|
private static boolean isMusicPlayed = false;
|
||||||
MusicPlayer.playMusic();
|
|
||||||
MainMenu mainMenu = new MainMenu();
|
|
||||||
MainMenuResizeController MainMenuResizeController = new MainMenuResizeController(mainMenu);
|
|
||||||
MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame);
|
|
||||||
|
|
||||||
|
// Fonction pour réinitialiser tout le jeu
|
||||||
|
public static void resetGame() {
|
||||||
|
// 1. Fermer toutes les fenêtres ouvertes
|
||||||
|
if (gameModeFrame != null) {
|
||||||
|
gameModeFrame.dispose(); // Ferme la fenêtre du choix des modes de jeu
|
||||||
|
}
|
||||||
|
if (gameFrame != null) {
|
||||||
|
gameFrame.dispose(); // Ferme la fenêtre de jeu
|
||||||
|
}
|
||||||
|
if (settingsFrame != null) {
|
||||||
|
settingsFrame.dispose(); // Ferme la fenêtre des paramètres
|
||||||
|
}
|
||||||
|
if (howToPlayFrame != null) {
|
||||||
|
howToPlayFrame.dispose(); // Ferme la fenêtre du tutoriel
|
||||||
|
}
|
||||||
|
if (rewardsFrame != null) {
|
||||||
|
rewardsFrame.dispose(); // Ferme la fenêtre des récompenses
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Réinitialiser les variables globales ou statiques si nécessaire
|
||||||
|
Options.mainMenu = new MainMenu(); // Réinitialiser le menu principal
|
||||||
|
|
||||||
|
// 3. Lancer la musique uniquement si ce n'est pas déjà fait
|
||||||
|
if (!isMusicPlayed) {
|
||||||
|
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC); // Recharger la musique du menu principal
|
||||||
|
MusicPlayer.playMusic(); // Reprendre la musique
|
||||||
|
isMusicPlayed = true; // Marquer la musique comme jouée
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Créer les fenêtres à nouveau comme au début
|
||||||
|
gameModeFrame = new JFrame("Choix des modes de jeu - Dorfromantik");
|
||||||
|
gameFrame = new JFrame("Jeu - Dorfromantik");
|
||||||
|
settingsFrame = new JFrame("Paramètres - Dorfromantik");
|
||||||
|
howToPlayFrame = new JFrame("Comment jouer ? - Dorfromantik");
|
||||||
|
rewardsFrame = new JFrame("Récompenses - Dorfromantik");
|
||||||
|
|
||||||
|
// Re-créer et réinitialiser les panels et les contrôleurs
|
||||||
|
MainMenuResizeController mainMenuResizeController = new MainMenuResizeController(Options.mainMenu);
|
||||||
|
MainMenuButtonController mainMenuButtonController = new MainMenuButtonController(Options.mainMenu, settingsFrame, howToPlayFrame, gameModeFrame, gameFrame, rewardsFrame);
|
||||||
|
|
||||||
// Fenêtre des paramètres
|
// Fenêtre des paramètres
|
||||||
SettingsWindowListener windowListener = new SettingsWindowListener(mainMenu, settingsFrame);
|
CloseWindowListener settingsWindowListener = new CloseWindowListener(Options.mainMenu, settingsFrame);
|
||||||
SettingsPanel settingsPanel = new SettingsPanel(mainMenu, settingsFrame);
|
SettingsPanel settingsPanel = new SettingsPanel(Options.mainMenu, settingsFrame);
|
||||||
settingsFrame.addWindowListener(windowListener);
|
settingsFrame.addWindowListener(settingsWindowListener);
|
||||||
settingsFrame.add(settingsPanel);
|
settingsFrame.add(settingsPanel);
|
||||||
settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
||||||
|
|
||||||
// Fenêtre du tutoriel
|
// Fenêtre du tutoriel
|
||||||
TutorialController tutorialController = new TutorialController();
|
CloseWindowListener howToPlayWindowListener = new CloseWindowListener(Options.mainMenu, howToPlayFrame);
|
||||||
howToPlayFrame.addWindowListener(windowListener);
|
TutorialController tutorialController = new TutorialController(Options.mainMenu, howToPlayFrame);
|
||||||
|
howToPlayFrame.addWindowListener(howToPlayWindowListener);
|
||||||
howToPlayFrame.add(tutorialController.getTutorialPanel());
|
howToPlayFrame.add(tutorialController.getTutorialPanel());
|
||||||
howToPlayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
||||||
|
|
||||||
|
// Fenêtre du choix des modes de jeu
|
||||||
|
CloseWindowListener gameModeWindowListener = new CloseWindowListener(Options.mainMenu, gameModeFrame);
|
||||||
|
GameModeController gameModeController = new GameModeController(gameFrame, Options.mainMenu, gameModeFrame);
|
||||||
|
GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController);
|
||||||
|
gameModeFrame.addWindowListener(gameModeWindowListener);
|
||||||
|
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
|
||||||
|
gameModeFrame.add(gameModeSelectionPanel);
|
||||||
|
|
||||||
|
// Fenêtre des récompenses
|
||||||
|
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
|
||||||
|
rewardsFrame.addWindowListener(rewardsWindowListener);
|
||||||
|
RewardsPanel rewardsPanel = new RewardsPanel();
|
||||||
|
rewardsFrame.setContentPane(rewardsPanel);
|
||||||
|
rewardsFrame.pack();
|
||||||
|
|
||||||
|
// Afficher à nouveau le menu principal
|
||||||
|
Options.mainMenu.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Appel initial pour créer les fenêtres et démarrer le jeu
|
||||||
|
resetGame(); // Appel à la fonction de réinitialisation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package fr.monkhanny.dorfromantik;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
|
||||||
public class Options {
|
public class Options {
|
||||||
|
|
||||||
@@ -51,4 +52,18 @@ public class Options {
|
|||||||
public static int SOUNDS_VOLUME = 60;
|
public static int SOUNDS_VOLUME = 60;
|
||||||
|
|
||||||
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
||||||
|
|
||||||
|
public static boolean AUTO_FOCUS = false;
|
||||||
|
|
||||||
|
public static final int MAX_TILE_NUMBER = 50;
|
||||||
|
|
||||||
|
public static boolean FULL_SCREEN = false;
|
||||||
|
|
||||||
|
public static final float SCORE_SIZE = 30f;
|
||||||
|
|
||||||
|
public static long SEED = 0;
|
||||||
|
|
||||||
|
public static MainMenu mainMenu;
|
||||||
|
|
||||||
|
public static boolean isPlaying = false;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package fr.monkhanny.dorfromantik.gui;
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.Options;
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
|
||||||
|
@@ -0,0 +1,115 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.controller;
|
||||||
|
|
||||||
|
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
import fr.monkhanny.dorfromantik.game.Board;
|
||||||
|
import fr.monkhanny.dorfromantik.utils.Database;
|
||||||
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
public class GameModeController implements ActionListener {
|
||||||
|
|
||||||
|
private GameModeSelectionPanel gameModeSelectionPanel;
|
||||||
|
private JFrame gameFrame;
|
||||||
|
private MainMenu mainMenu;
|
||||||
|
private Database database;
|
||||||
|
private JFrame gameModeFrame;
|
||||||
|
private static Board board;
|
||||||
|
|
||||||
|
// Constructeur sans le panneau
|
||||||
|
public GameModeController(JFrame gameFrame, MainMenu mainMenu, JFrame gameModeFrame) {
|
||||||
|
this.gameFrame = gameFrame;
|
||||||
|
this.mainMenu = mainMenu;
|
||||||
|
this.gameModeFrame = gameModeFrame;
|
||||||
|
|
||||||
|
// Connexion à la base de données
|
||||||
|
try {
|
||||||
|
this.database = new Database();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Erreur lors de la connexion à la base de données: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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", getSeedFromDatabaseByName("Mode 1"));
|
||||||
|
break;
|
||||||
|
case "Mode 2":
|
||||||
|
startGame("Mode 2", getSeedFromDatabaseByName("Mode 2"));
|
||||||
|
break;
|
||||||
|
case "Mode 3":
|
||||||
|
startGame("Mode 3", getSeedFromDatabaseByName("Mode 3"));
|
||||||
|
break;
|
||||||
|
case "Mode 4":
|
||||||
|
startGame("Mode 4", getSeedFromDatabaseByName("Mode 4"));
|
||||||
|
break;
|
||||||
|
case "Démarrer":
|
||||||
|
long seed = gameModeSelectionPanel.getLongSeed();
|
||||||
|
startGame("Custom Mode", seed);
|
||||||
|
addCustomSeedToDatabase("Custom Mode", seed);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Commande inconnue: " + command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getSeedFromDatabaseByName(String modeName) {
|
||||||
|
try {
|
||||||
|
Options.SEED = this.database.getSeedByName(modeName);
|
||||||
|
return Options.SEED;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return -1; // Retourner une valeur par défaut si une erreur survient
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCustomSeedToDatabase(String name, long seed) {
|
||||||
|
try {
|
||||||
|
Options.SEED = seed;
|
||||||
|
this.database.addCustomSeed(name, seed);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("Erreur lors de l'ajout de la seed custom.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startGame(String mode, long seed) {
|
||||||
|
// Supprimer la potentielle ancienne instance de board
|
||||||
|
GameModeController.board = null;
|
||||||
|
|
||||||
|
// Cacher la fenêtre avant de faire des modifications
|
||||||
|
this.gameFrame.setVisible(false);
|
||||||
|
|
||||||
|
if (Options.FULL_SCREEN) {
|
||||||
|
gameFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Set frame to full screen
|
||||||
|
} else {
|
||||||
|
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||||
|
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||||
|
gameFrame.setSize(mainMenuSize);
|
||||||
|
gameFrame.setLocation(mainMenuLocation);
|
||||||
|
}
|
||||||
|
GameModeController.board = new Board(this.gameFrame,seed);
|
||||||
|
//this.gameModeFrame.setVisible(false);
|
||||||
|
this.gameFrame.setVisible(true);
|
||||||
|
this.gameFrame.add(board);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Board getGameModeBoard() {
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +1,7 @@
|
|||||||
package fr.monkhanny.dorfromantik.controller;
|
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.MainMenu;
|
||||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||||
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -12,46 +9,68 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class MainMenuButtonController implements ActionListener {
|
public class MainMenuButtonController implements ActionListener {
|
||||||
|
|
||||||
private MainMenu mainMenu;
|
private MainMenu mainMenu;
|
||||||
|
|
||||||
private JFrame settingsFrame;
|
private JFrame settingsFrame;
|
||||||
private JFrame howToPlayFrame;
|
private JFrame howToPlayFrame;
|
||||||
|
private JFrame gameModeFrame;
|
||||||
|
private JFrame gameFrame;
|
||||||
|
private JFrame rewardsFrame;
|
||||||
|
|
||||||
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame) {
|
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame, JFrame gameFrame, JFrame rewardsFrame) {
|
||||||
this.mainMenu = mainMenu;
|
this.mainMenu = mainMenu;
|
||||||
// Ajouter les écouteurs d'événements sur les boutons
|
// Ajouter les écouteurs d'événements sur les boutons
|
||||||
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
||||||
|
|
||||||
// Attacher les actions aux boutons
|
// Attacher les actions aux boutons du menu principal
|
||||||
buttonPanel.getNewGameButton().addActionListener(this);
|
buttonPanel.getNewGameButton().addActionListener(this);
|
||||||
buttonPanel.getContinueGameButton().addActionListener(this);
|
buttonPanel.getContinueGameButton().addActionListener(this);
|
||||||
buttonPanel.getHowToPlayButton().addActionListener(this);
|
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||||
buttonPanel.getSettingsButton().addActionListener(this);
|
buttonPanel.getSettingsButton().addActionListener(this);
|
||||||
buttonPanel.getExitButton().addActionListener(this);
|
buttonPanel.getExitButton().addActionListener(this);
|
||||||
|
|
||||||
// Créer 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(this.settingsFrame);
|
||||||
this.settingsFrame.setVisible(false);
|
|
||||||
|
|
||||||
// Créer la fenêtre du tutoriel
|
// Paramètrage de la fenêtre du tutoriel
|
||||||
this.howToPlayFrame = howToPlayFrame;
|
this.howToPlayFrame = howToPlayFrame;
|
||||||
this.howToPlayFrame.setLocationRelativeTo(null);
|
configureFrame(this.howToPlayFrame);
|
||||||
this.howToPlayFrame.setVisible(false);
|
|
||||||
|
// Paramètrage de la fenêtre du jeu
|
||||||
|
this.gameModeFrame = gameModeFrame;
|
||||||
|
configureFrame(this.gameModeFrame);
|
||||||
|
|
||||||
|
// Paramètrage de la fenêtre du jeu
|
||||||
|
this.gameFrame = gameFrame;
|
||||||
|
configureFrame(this.gameFrame);
|
||||||
|
|
||||||
|
// Paramètrage de la fenêtre des récompenses
|
||||||
|
this.rewardsFrame = rewardsFrame;
|
||||||
|
configureFrame(this.rewardsFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "Nouvelle partie":
|
case "Jouer":
|
||||||
startNewGame();
|
startNewGame();
|
||||||
break;
|
break;
|
||||||
case "Continuer une partie":
|
case "Récompenses":
|
||||||
continueGame();
|
openRecompense();
|
||||||
break;
|
break;
|
||||||
case "Comment jouer ?":
|
case "Comment jouer ?":
|
||||||
showHowToPlay();
|
showHowToPlay();
|
||||||
@@ -68,29 +87,21 @@ public class MainMenuButtonController implements ActionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNewGame() {
|
public void startNewGame() {
|
||||||
System.out.println("Démarrer une nouvelle partie...");
|
adjustFrameDisplay(this.gameModeFrame);
|
||||||
// Logic to start a new game
|
this.mainMenu.setVisible(false);
|
||||||
|
this.gameModeFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void continueGame() {
|
private void openRecompense() {
|
||||||
System.out.println("Continuer une partie...");
|
adjustFrameDisplay(this.rewardsFrame);
|
||||||
// Logic to continue the game
|
this.mainMenu.setVisible(false);
|
||||||
|
this.rewardsFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,18 +111,22 @@ public class MainMenuButtonController implements ActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openSettings() {
|
private void openSettings() {
|
||||||
|
adjustFrameDisplay(this.settingsFrame);
|
||||||
|
this.mainMenu.setVisible(false);
|
||||||
|
this.settingsFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void adjustFrameDisplay(JFrame frame) {
|
||||||
|
boolean wasVisible = frame.isVisible(); // Vérifier si la fenêtre était déjà visible
|
||||||
|
|
||||||
|
if(!wasVisible){
|
||||||
// Récupérer la taille et la position de la fenêtre du menu principal
|
// Récupérer la taille et la position de la fenêtre du menu principal
|
||||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||||
|
frame.setSize(mainMenuSize);
|
||||||
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
|
frame.setLocation(mainMenuLocation);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,6 @@ import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
|||||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
public class MainMenuMouseController {
|
public class MainMenuMouseController {
|
||||||
|
|
||||||
|
@@ -6,7 +6,6 @@ import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
|||||||
|
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import javax.swing.JButton;
|
|
||||||
|
|
||||||
public class MainMenuResizeHandler extends ComponentAdapter {
|
public class MainMenuResizeHandler extends ComponentAdapter {
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package fr.monkhanny.dorfromantik.controller;
|
|||||||
import fr.monkhanny.dorfromantik.gui.TutorialPanel;
|
import fr.monkhanny.dorfromantik.gui.TutorialPanel;
|
||||||
import fr.monkhanny.dorfromantik.gui.Step;
|
import fr.monkhanny.dorfromantik.gui.Step;
|
||||||
import fr.monkhanny.dorfromantik.enums.Images;
|
import fr.monkhanny.dorfromantik.enums.Images;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -11,14 +12,20 @@ import java.util.List;
|
|||||||
public class TutorialController {
|
public class TutorialController {
|
||||||
private TutorialPanel tutorialPanel;
|
private TutorialPanel tutorialPanel;
|
||||||
|
|
||||||
public TutorialController() {
|
private MainMenu mainMenu;
|
||||||
|
private JFrame tutorialFrame;
|
||||||
|
|
||||||
|
public TutorialController(MainMenu mainMenu, JFrame tutorialFrame) {
|
||||||
|
this.mainMenu = mainMenu;
|
||||||
|
this.tutorialFrame = tutorialFrame;
|
||||||
|
|
||||||
List<Step> steps = new ArrayList<>();
|
List<Step> steps = new ArrayList<>();
|
||||||
steps.add(new Step("Étape n°1", "Explication de la première étape ici.", Images.TUTORIAL_GIF1.getImagePath()));
|
steps.add(new Step("Étape n°1", "Explication de la première étape ici.", Images.TUTORIAL_GIF1.getImagePath()));
|
||||||
steps.add(new Step("Étape n°2", "Explication de la deuxième étape ici.", Images.TUTORIAL_GIF2.getImagePath()));
|
steps.add(new Step("Étape n°2", "Explication de la deuxième étape ici.", Images.TUTORIAL_GIF2.getImagePath()));
|
||||||
steps.add(new Step("Étape n°3", "Explication de la troisième étape ici.", Images.TUTORIAL_GIF3.getImagePath()));
|
steps.add(new Step("Étape n°3", "Explication de la troisième étape ici.", Images.TUTORIAL_GIF3.getImagePath()));
|
||||||
steps.add(new Step("Étape n°4", "Explication de la quatrième étape ici.", Images.TUTORIAL_GIF4.getImagePath()));
|
steps.add(new Step("Étape n°4", "Explication de la quatrième étape ici.", Images.TUTORIAL_GIF4.getImagePath()));
|
||||||
|
|
||||||
tutorialPanel = new TutorialPanel(steps);
|
tutorialPanel = new TutorialPanel(steps, this.mainMenu, this.tutorialFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getTutorialPanel() {
|
public JPanel getTutorialPanel() {
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package fr.monkhanny.dorfromantik.enums;
|
package fr.monkhanny.dorfromantik.enums;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontFormatException;
|
||||||
|
|
||||||
public enum Fonts {
|
public enum Fonts {
|
||||||
TITLE, BUTTON;
|
TITLE, BUTTON, SCORE;
|
||||||
|
|
||||||
public String getFontPath() {
|
public String getFontPath() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
@@ -11,8 +14,29 @@ public enum Fonts {
|
|||||||
return "./ressources/fonts/Contage-Black.ttf";
|
return "./ressources/fonts/Contage-Black.ttf";
|
||||||
case BUTTON:
|
case BUTTON:
|
||||||
return "./ressources/fonts/Contage-Regular.ttf";
|
return "./ressources/fonts/Contage-Regular.ttf";
|
||||||
|
case SCORE:
|
||||||
|
return "./ressources/fonts/Contage-Bold.ttf";
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Font getFont(float size) {
|
||||||
|
try {
|
||||||
|
switch (this) {
|
||||||
|
case TITLE:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Black.ttf")).deriveFont(size);
|
||||||
|
case BUTTON:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Regular.ttf")).deriveFont(size);
|
||||||
|
case SCORE:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Bold.ttf")).deriveFont(size);
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||||
|
}
|
||||||
|
} catch (IOException | FontFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Retourner une police de secours si le fichier est introuvable ou s'il y a une erreur
|
||||||
|
return new Font("Arial", Font.PLAIN, (int) size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
BIN
TestV1/src/fr/monkhanny/dorfromantik/game/.DS_Store
vendored
Normal file
24
TestV1/src/fr/monkhanny/dorfromantik/game/BiomeGroup.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Représente un groupe de poches pour un biome spécifique.
|
||||||
|
*/
|
||||||
|
public class BiomeGroup {
|
||||||
|
private final List<Pocket> pockets;
|
||||||
|
|
||||||
|
public BiomeGroup() {
|
||||||
|
this.pockets = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pocket> getPockets() {
|
||||||
|
return pockets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPocket(Pocket pocket) {
|
||||||
|
pockets.add(pocket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
505
TestV1/src/fr/monkhanny/dorfromantik/game/Board.java
Normal file
110
TestV1/src/fr/monkhanny/dorfromantik/game/Cell.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Représente une cellule de base sur le plateau de jeu.
|
||||||
|
* C'est la classe parente pour la classe Tile.
|
||||||
|
*/
|
||||||
|
public class Cell extends JComponent {
|
||||||
|
private Board board; // Le plateau de jeu auquel cette cellule appartient
|
||||||
|
public int x; // Coordonnée x du centre de la cellule
|
||||||
|
public int y; // Coordonnée y du centre de la cellule
|
||||||
|
public int radius; // Rayon de la cellule (si on parle d'un hexagone, c'est le rayon de l'hexagone)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur de la classe Cell.
|
||||||
|
*
|
||||||
|
* @param board Le plateau de jeu auquel cette cellule appartient
|
||||||
|
* @param x La coordonnée x du centre de la cellule
|
||||||
|
* @param y La coordonnée y du centre de la cellule
|
||||||
|
* @param radius Le rayon de la cellule
|
||||||
|
*/
|
||||||
|
public Cell(Board board, int x, int y, int radius) {
|
||||||
|
this.board = board;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.radius = radius;
|
||||||
|
|
||||||
|
// Définir la taille du composant pour l'affichage
|
||||||
|
this.setSize(2 * radius, 2 * radius);
|
||||||
|
this.setLocation(x - radius, y - radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère le plateau de jeu auquel cette cellule appartient.
|
||||||
|
*
|
||||||
|
* @return Le plateau de jeu
|
||||||
|
*/
|
||||||
|
public Board getBoard() {
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère la coordonnée x du centre de la cellule.
|
||||||
|
*
|
||||||
|
* @return La coordonnée x
|
||||||
|
*/
|
||||||
|
public int getXCoord() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère la coordonnée y du centre de la cellule.
|
||||||
|
*
|
||||||
|
* @return La coordonnée y
|
||||||
|
*/
|
||||||
|
public int getYCoord() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère le rayon de la cellule.
|
||||||
|
*
|
||||||
|
* @return Le rayon de la cellule
|
||||||
|
*/
|
||||||
|
public int getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convertit une coordonnée en degrés en une valeur de 0 à 360.
|
||||||
|
*
|
||||||
|
* @param angle L'angle en degrés
|
||||||
|
* @return La valeur normalisée entre 0 et 360 degrés
|
||||||
|
*/
|
||||||
|
public static double to360Degrees(double angle) {
|
||||||
|
angle = angle % 360;
|
||||||
|
if (angle < 0) {
|
||||||
|
angle += 360;
|
||||||
|
}
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de changer la position de la cellule.
|
||||||
|
* Cette méthode met à jour les coordonnées x et y et déplace la cellule dans le composant graphique.
|
||||||
|
*
|
||||||
|
* @param x La nouvelle coordonnée x du centre de la cellule
|
||||||
|
* @param y La nouvelle coordonnée y du centre de la cellule
|
||||||
|
*/
|
||||||
|
public void setPosition(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
|
||||||
|
// Mettre à jour la position de la cellule sur le plateau
|
||||||
|
this.setLocation(x - radius, y - radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode pour redessiner la cellule si nécessaire.
|
||||||
|
* Elle sera surchargée par les classes dérivées comme Tile.
|
||||||
|
*
|
||||||
|
* @param g Le contexte graphique
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
}
|
||||||
|
}
|