test pour afficher les tuiles d'une manière différente
This commit is contained in:
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 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();
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user