✅ Ajout des codes de base
Co-authored-by: Juliette Charpentier <juliette1.charpentier@etu.u-pec.fr>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.charpentierbalocchi.dorfjavatik.view;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.charpentierbalocchi.dorfjavatik.model.Tuile;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
|
||||
public class AffichageTuile extends JPanel {
|
||||
private Tuile tuile;
|
||||
|
||||
public AffichageTuile(Tuile tuile) {
|
||||
this.tuile = tuile;
|
||||
setPreferredSize(new Dimension(100, 100)); // Taille préférée du panel pour afficher la tuile
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (tuile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Divise le panel en quatre quadrants pour les biomes Nord, Sud, Est, Ouest
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
drawBiome(g, tuile.getNord(), 0, 0, width / 2, height / 2);
|
||||
drawBiome(g, tuile.getSud(), 0, height / 2, width / 2, height / 2);
|
||||
drawBiome(g, tuile.getEst(), width / 2, 0, width / 2, height / 2);
|
||||
drawBiome(g, tuile.getOuest(), width / 2, height / 2, width / 2, height / 2);
|
||||
}
|
||||
|
||||
// Dessine chaque biome dans le quadrant spécifié
|
||||
private void drawBiome(Graphics g, Tuile.Biome biome, int x, int y, int width, int height) {
|
||||
switch (biome) {
|
||||
case RIVIERE:
|
||||
g.setColor(Color.BLUE);
|
||||
break;
|
||||
case FORET:
|
||||
g.setColor(Color.GREEN);
|
||||
break;
|
||||
case CHAMP:
|
||||
g.setColor(Color.YELLOW);
|
||||
break;
|
||||
case VILLAGE:
|
||||
g.setColor(Color.RED);
|
||||
break;
|
||||
case MONTAGNE:
|
||||
g.setColor(Color.GRAY);
|
||||
break;
|
||||
default:
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
g.fillRect(x, y, width, height);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(x, y, width, height); // Dessine un contour pour chaque zone
|
||||
}
|
||||
}
|
59
src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java
Normal file
59
src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.charpentierbalocchi.dorfjavatik.view;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import com.charpentierbalocchi.dorfjavatik.model.Tuile;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class FenetreJeu extends JFrame {
|
||||
private static final int TAILLE_PLATEAU = 5; // Taille du plateau 5x5
|
||||
private JButton[][] boutons; // Boutons représentant les cases du plateau
|
||||
private JLabel labelScore; // Label pour afficher le score
|
||||
|
||||
public FenetreJeu() {
|
||||
super("DorfJavaTik"); // Titre de la fenêtre
|
||||
initUI();
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Ferme l'application à la fermeture de la fenêtre
|
||||
setLocationRelativeTo(null); // Centre la fenêtre sur l'écran
|
||||
pack(); // Ajuste la taille de la fenêtre en fonction des composants
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
// Panel principal
|
||||
JPanel panelPrincipal = new JPanel(new BorderLayout());
|
||||
|
||||
// Panel pour le plateau de jeu
|
||||
JPanel plateau = new JPanel(new GridLayout(TAILLE_PLATEAU, TAILLE_PLATEAU));
|
||||
plateau.setSize(1000, 1000);
|
||||
plateau.setLocation(0, 0);
|
||||
boutons = new JButton[TAILLE_PLATEAU][TAILLE_PLATEAU];
|
||||
for (int i = 0; i < TAILLE_PLATEAU; i++) {
|
||||
for (int j = 0; j < TAILLE_PLATEAU; j++) {
|
||||
JButton bouton = new JButton();
|
||||
boutons[i][j] = bouton;
|
||||
plateau.add(bouton);
|
||||
}
|
||||
}
|
||||
|
||||
// Label pour le score
|
||||
labelScore = new JLabel("Score: 0");
|
||||
panelPrincipal.add(labelScore, BorderLayout.NORTH);
|
||||
panelPrincipal.add(plateau, BorderLayout.CENTER);
|
||||
|
||||
add(panelPrincipal);
|
||||
}
|
||||
|
||||
// Méthode pour mettre à jour le plateau après placement d'une tuile
|
||||
public void updateBoard(int x, int y, Tuile tuile) {
|
||||
JButton bouton = boutons[x][y];
|
||||
bouton.setText(tuile.toString()); // Utilisez toString ou une autre méthode pour représenter visuellement la
|
||||
// tuile
|
||||
bouton.setEnabled(false); // Désactive le bouton pour éviter le placement d'une autre tuile à cette
|
||||
// position
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
labelScore.setText("Score: " + score);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user