test pour afficher les tuiles d'une manière différente
This commit is contained in:
12
TestV1/GameController.java
Normal file
12
TestV1/GameController.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
62
TestV1/GameView.java
Normal file
62
TestV1/GameView.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
TestV1/Main.java
Normal file
15
TestV1/Main.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
11
TestV1/TestEnAttendantResolutionBug/GameController.java
Normal file
11
TestV1/TestEnAttendantResolutionBug/GameController.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
public class GameController {
|
||||||
|
private GameView view;
|
||||||
|
|
||||||
|
public GameController(GameView view) {
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startGame() {
|
||||||
|
view.showTile();
|
||||||
|
}
|
||||||
|
}
|
78
TestV1/TestEnAttendantResolutionBug/GameView.java
Normal file
78
TestV1/TestEnAttendantResolutionBug/GameView.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,20 +1,15 @@
|
|||||||
import model.Game;
|
|
||||||
import view.GameView;
|
|
||||||
import controller.GameController;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(() -> {
|
// Exemple : une tuile avec deux terrains
|
||||||
Game game = new Game();
|
Tile tile = new Tile(Terrain.MER, Terrain.FORET, 1);
|
||||||
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é
|
// Vue
|
||||||
gameView.setController(controller);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
TestV1/TestEnAttendantResolutionBug/Terrain.java
Normal file
3
TestV1/TestEnAttendantResolutionBug/Terrain.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public enum Terrain {
|
||||||
|
MER, CHAMP, PRE, FORET, MONTAGNE, VIDE
|
||||||
|
}
|
48
TestV1/TestEnAttendantResolutionBug/Tile.java
Normal file
48
TestV1/TestEnAttendantResolutionBug/Tile.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
BIN
TestV1/dorfromantik.jar
Normal file
BIN
TestV1/dorfromantik.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user