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