diff --git a/TestV1/GameController.java b/TestV1/GameController.java new file mode 100644 index 0000000..264dc07 --- /dev/null +++ b/TestV1/GameController.java @@ -0,0 +1,12 @@ +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(); + } +} diff --git a/TestV1/GameView.java b/TestV1/GameView.java new file mode 100644 index 0000000..925a6a4 --- /dev/null +++ b/TestV1/GameView.java @@ -0,0 +1,62 @@ +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; + } + } +} diff --git a/TestV1/Main.java b/TestV1/Main.java new file mode 100644 index 0000000..86515a4 --- /dev/null +++ b/TestV1/Main.java @@ -0,0 +1,15 @@ +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(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/GameController.java b/TestV1/TestEnAttendantResolutionBug/GameController.java new file mode 100644 index 0000000..c3978d1 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/GameController.java @@ -0,0 +1,11 @@ +public class GameController { + private GameView view; + + public GameController(GameView view) { + this.view = view; + } + + public void startGame() { + view.showTile(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/GameView.java b/TestV1/TestEnAttendantResolutionBug/GameView.java new file mode 100644 index 0000000..a88ef14 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/GameView.java @@ -0,0 +1,78 @@ +import javax.swing.*; +import java.awt.*; + +public class GameView extends JFrame { + private Tile tile; + + // Constructeur + public GameView(Tile tile) { + this.tile = tile; + setTitle("Dorfromantik - Affichage de tuile"); + setSize(600, 600); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + } + + public void showTile() { + setVisible(true); + repaint(); + } + + @Override + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2d = (Graphics2D) g; + + int hexRadius = 50; // Rayon des hexagones + int hexHeight = (int) (Math.sqrt(3) * hexRadius); // Hauteur de l'hexagone + int xOffset = 150, yOffset = 150; // Décalage initial pour centrer + + Terrain[][] matrix = tile.getHexMatrix(); + + // Dessiner les hexagones en fonction de la matrice + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[i].length; j++) { + if (matrix[i][j] != Terrain.VIDE) { + // Calcul des coordonnées + int x = xOffset + j * (3 * hexRadius / 2); // Décalage horizontal + int y = yOffset + i * hexHeight + (j % 2) * (hexHeight / 2); // Décalage vertical + + drawHexagon(g2d, x, y, hexRadius, getColorForTerrain(matrix[i][j])); + } + } + } + } + + private void drawHexagon(Graphics2D g2d, int x, int y, int radius, Color color) { + int[] xPoints = new int[6]; + int[] yPoints = new int[6]; + + for (int i = 0; i < 6; i++) { + xPoints[i] = x + (int) (radius * Math.cos(i * Math.PI / 3)); + yPoints[i] = y + (int) (radius * Math.sin(i * Math.PI / 3)); + } + + g2d.setColor(color); + g2d.fillPolygon(xPoints, yPoints, 6); + + g2d.setColor(Color.BLACK); // Contour noir + g2d.drawPolygon(xPoints, yPoints, 6); + } + + 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.WHITE; + } + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/Main.java b/TestV1/TestEnAttendantResolutionBug/Main.java index baeb594..fae64f5 100644 --- a/TestV1/TestEnAttendantResolutionBug/Main.java +++ b/TestV1/TestEnAttendantResolutionBug/Main.java @@ -1,20 +1,15 @@ -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 + // Exemple : une tuile avec deux terrains + Tile tile = new Tile(Terrain.MER, Terrain.FORET, 1); - // Passe ensuite le contrôleur à la vue une fois que tout est initialisé - gameView.setController(controller); + // Vue + GameView view = new GameView(tile); - gameView.setVisible(true); // Affiche la fenêtre - }); + // Contrôleur + GameController controller = new GameController(view); + + // Démarrer le jeu + controller.startGame(); } } diff --git a/TestV1/TestEnAttendantResolutionBug/Terrain.java b/TestV1/TestEnAttendantResolutionBug/Terrain.java new file mode 100644 index 0000000..3cbbe46 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/Terrain.java @@ -0,0 +1,3 @@ +public enum Terrain { + MER, CHAMP, PRE, FORET, MONTAGNE, VIDE +} diff --git a/TestV1/TestEnAttendantResolutionBug/Tile.java b/TestV1/TestEnAttendantResolutionBug/Tile.java new file mode 100644 index 0000000..5b86d90 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/Tile.java @@ -0,0 +1,48 @@ +public class Tile { + private Terrain[][] hexMatrix; + + // Constructeur pour une tuile avec un seul terrain + public Tile(Terrain terrain) { + hexMatrix = new Terrain[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + hexMatrix[i][j] = terrain; + } + } + } + + // Constructeur pour une tuile avec deux terrains + public Tile(Terrain terrain1, Terrain terrain2, int configuration) { + hexMatrix = new Terrain[3][3]; + switch (configuration) { + case 1: + fillSides(terrain1, terrain2, 1, 5); + break; + case 2: + fillSides(terrain1, terrain2, 2, 4); + break; + case 3: + fillSides(terrain1, terrain2, 3, 3); + break; + default: + throw new IllegalArgumentException("Configuration invalide"); + } + } + + private void fillSides(Terrain terrain1, Terrain terrain2, int side1, int side2) { + // Exemple simplifié + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if ((i + j) % 2 == 0) { // Terrain1 sur certaines cases + hexMatrix[i][j] = terrain1; + } else { + hexMatrix[i][j] = terrain2; + } + } + } + } + + public Terrain[][] getHexMatrix() { + return hexMatrix; + } +} diff --git a/TestV1/dorfromantik.jar b/TestV1/dorfromantik.jar new file mode 100644 index 0000000..c3ca214 Binary files /dev/null and b/TestV1/dorfromantik.jar differ