From 687d55ee31908c088d51c6bd7749a81c3ddd277a Mon Sep 17 00:00:00 2001 From: "foulou.salle224-15" Date: Sun, 17 Nov 2024 12:00:36 +0100 Subject: [PATCH] =?UTF-8?q?resolution=20probleme=20li=C3=A9=20au=20conflit?= =?UTF-8?q?=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GameController.java | 20 --- .../model/Board.java | 26 ---- .../model/Game.java | 26 ---- .../model/Tile.java | 19 --- .../TestEnAttendantResolutionBug/src/Makefile | 18 +++ .../src/controller/GameController.java | 31 +++++ .../src/controller/Main.java | 21 +++ TestV1/TestEnAttendantResolutionBug/src/java | 0 TestV1/TestEnAttendantResolutionBug/src/javac | 0 .../src/model/Board.java | 29 +++++ .../src/model/Terrain.java | 5 + .../src/model/Tile.java | 33 +++++ .../src/view/GameView.java | 123 ++++++++++++++++++ .../utils/Database.java | 61 +++++++++ .../view/BoardView.java | 24 ---- .../view/GameView.java | 28 ---- .../view/TileView.java | 21 --- 17 files changed, 321 insertions(+), 164 deletions(-) delete mode 100644 TestV1/TestEnAttendantResolutionBug/controller/GameController.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/model/Board.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/model/Game.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/model/Tile.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/Makefile create mode 100644 TestV1/TestEnAttendantResolutionBug/src/controller/GameController.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/controller/Main.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/javac create mode 100644 TestV1/TestEnAttendantResolutionBug/src/model/Board.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/model/Terrain.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/model/Tile.java create mode 100644 TestV1/TestEnAttendantResolutionBug/src/view/GameView.java create mode 100644 TestV1/TestEnAttendantResolutionBug/utils/Database.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/view/BoardView.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/view/GameView.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/view/TileView.java diff --git a/TestV1/TestEnAttendantResolutionBug/controller/GameController.java b/TestV1/TestEnAttendantResolutionBug/controller/GameController.java deleted file mode 100644 index 4b08d39..0000000 --- a/TestV1/TestEnAttendantResolutionBug/controller/GameController.java +++ /dev/null @@ -1,20 +0,0 @@ -package controller; - -import model.Game; -import model.Tile; -import view.GameView; - -public class GameController { - private Game game; - private GameView gameView; - - public GameController(Game game, GameView gameView) { - this.game = game; - this.gameView = gameView; - } - - public void placeTile(Tile tile) { - game.placeTile(tile); - gameView.update(game); - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Board.java b/TestV1/TestEnAttendantResolutionBug/model/Board.java deleted file mode 100644 index b5e26f2..0000000 --- a/TestV1/TestEnAttendantResolutionBug/model/Board.java +++ /dev/null @@ -1,26 +0,0 @@ -package model; - -import java.util.ArrayList; -import java.util.List; - -public class Board { - private List tiles; - - public Board() { - tiles = new ArrayList<>(); - } - - public void addTile(Tile tile) { - tiles.add(tile); - } - - public List getTiles() { - return tiles; - } - - public boolean isPlacementValid(Tile tile) { - // Logique simplifiée pour vérifier si la tuile peut être placée - // Ici, tu pourrais vérifier les bords de la tuile et du plateau - return true; // Retourne true pour simplifier - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Game.java b/TestV1/TestEnAttendantResolutionBug/model/Game.java deleted file mode 100644 index 5cf832a..0000000 --- a/TestV1/TestEnAttendantResolutionBug/model/Game.java +++ /dev/null @@ -1,26 +0,0 @@ -package model; - -public class Game { - private Board board; - private int score; - - public Game() { - board = new Board(); - score = 0; - } - - public Board getBoard() { - return board; - } - - public int getScore() { - return score; - } - - public void placeTile(Tile tile) { - if (board.isPlacementValid(tile)) { - board.addTile(tile); - score += 10; // Par exemple, chaque tuile ajoute 10 points - } - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Tile.java b/TestV1/TestEnAttendantResolutionBug/model/Tile.java deleted file mode 100644 index f175519..0000000 --- a/TestV1/TestEnAttendantResolutionBug/model/Tile.java +++ /dev/null @@ -1,19 +0,0 @@ -package model; - -public class Tile { - private String type; // Par exemple : "forêt", "rivière", "champ", etc. - private String[] edges; // Les types des bords de la tuile (ex: "eau", "terre") - - public Tile(String type, String[] edges) { - this.type = type; - this.edges = edges; - } - - public String getType() { - return type; - } - - public String getEdge(int index) { - return edges[index]; - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/src/Makefile b/TestV1/TestEnAttendantResolutionBug/src/Makefile new file mode 100644 index 0000000..e7d7954 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/Makefile @@ -0,0 +1,18 @@ +SRC_DIR = src +BUILD_DIR = build +MAIN_CLASS = controller.Main + +SOURCES = $(shell find $(SRC_DIR) -name "*.java") +CLASSES = $(patsubst $(SRC_DIR)/%.java, $(BUILD_DIR)/%.class, $(SOURCES)) + +all: $(CLASSES) + +$(BUILD_DIR)/%.class: $(SRC_DIR)/%.java + mkdir -p $(dir $@) + javac -d $(BUILD_DIR) $< + +run: all + java -cp $(BUILD_DIR) $(MAIN_CLASS) + +clean: + rm -rf $(BUILD_DIR) diff --git a/TestV1/TestEnAttendantResolutionBug/src/controller/GameController.java b/TestV1/TestEnAttendantResolutionBug/src/controller/GameController.java new file mode 100644 index 0000000..1acc035 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/controller/GameController.java @@ -0,0 +1,31 @@ +package controller; + +import model.Board; +import view.GameView; + +/** + * Contrôleur principal du jeu, reliant la vue et le modèle. + */ +public class GameController { + private final Board board; + private final GameView view; + + /** + * Constructeur du contrôleur du jeu. + * + * @param board Le modèle du plateau de jeu. + * @param view La vue graphique du jeu. + */ + public GameController(Board board, GameView view) { + this.board = board; + this.view = view; + } + + /** + * Démarre le jeu en affichant la vue. + */ + public void startGame() { + view.setVisible(true); + } +} + diff --git a/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java b/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java new file mode 100644 index 0000000..210d9f3 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java @@ -0,0 +1,21 @@ +package controller; + +import model.Board; +import view.GameView; + +/** + * Classe principale pour démarrer l'application. + */ +public class Main { + public static void main(String[] args) { + // Initialisation du modèle et de la vue + Board board = new Board(); // Créer une instance du modèle (Board) + GameView view = new GameView(board); // Créer une instance de la vue (GameView) + + // Création du contrôleur avec Board et GameView + GameController controller = new GameController(board, view); + + // Démarrage du jeu + controller.startGame(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/src/java b/TestV1/TestEnAttendantResolutionBug/src/java new file mode 100644 index 0000000..e69de29 diff --git a/TestV1/TestEnAttendantResolutionBug/src/javac b/TestV1/TestEnAttendantResolutionBug/src/javac new file mode 100644 index 0000000..e69de29 diff --git a/TestV1/TestEnAttendantResolutionBug/src/model/Board.java b/TestV1/TestEnAttendantResolutionBug/src/model/Board.java new file mode 100644 index 0000000..1aa5ce3 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/model/Board.java @@ -0,0 +1,29 @@ +package model; + +import java.awt.*; +import java.util.HashMap; +import java.util.Map; + +public class Board { + private final Map tiles; + + public Board() { + this.tiles = new HashMap<>(); + } + + public boolean isPositionOccupied(Point position) { + return tiles.containsKey(position); + } + + public void addTile(Point position, Tile tile) { + tiles.put(position, tile); + } + + public Tile getTile(Point position) { + return tiles.get(position); + } + + public Map getTiles() { + return tiles; + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/src/model/Terrain.java b/TestV1/TestEnAttendantResolutionBug/src/model/Terrain.java new file mode 100644 index 0000000..bcf47a0 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/model/Terrain.java @@ -0,0 +1,5 @@ +package model; + +public enum Terrain { + MER, CHAMP, FORET, PRE, MONTAGNE +} diff --git a/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java b/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java new file mode 100644 index 0000000..2cec1d5 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java @@ -0,0 +1,33 @@ +package model; + +/** + * Classe représentant une tuile du jeu. + */ +public class Tile { + private final Terrain terrain; + + /** + * Constructeur pour une tuile. + * + * @param terrain Le type de terrain de la tuile. + */ + public Tile(Terrain terrain) { + this.terrain = terrain; + } + + /** + * Obtient le terrain de la tuile. + * + * @return Le terrain de la tuile. + */ + public Terrain getTerrain() { + return terrain; + } + + @Override + public String toString() { + return "Tile{" + + "terrain=" + terrain + + '}'; + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java b/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java new file mode 100644 index 0000000..1ce23da --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java @@ -0,0 +1,123 @@ +package view; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import model.Board; +import model.Tile; +import model.Terrain; + + +public class GameView extends JFrame { + private final Board board; + private final int hexRadius = 60; + private final int hexWidth = (int) (Math.sqrt(3) * hexRadius); // Largeur d'un hexagone + private final int hexHeight = 2 * hexRadius; // Hauteur d'un hexagone + + public GameView(Board board) { + this.board = board; + setTitle("Dorfromantik - Plateau"); + setSize(800, 800); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + + addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + handleMouseClick(e.getPoint()); + } + }); + } + + private void handleMouseClick(Point clickPoint) { + // Calcul de la position en coordonnées hexagonales + Point hexPosition = calculateHexCoordinates(clickPoint); + + // Vérifie si la position est libre + if (!board.isPositionOccupied(hexPosition)) { + Tile newTile = new Tile(Terrain.FORET); // Exemple : tuile de forêt + board.addTile(hexPosition, newTile); + repaint(); + } + } + + @Override + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2d = (Graphics2D) g; + + // Dessiner toutes les tuiles placées + for (Point position : board.getTiles().keySet()) { + Tile tile = board.getTile(position); + int x = calculateScreenX(position); + int y = calculateScreenY(position); + drawLargeHexagon(g2d, x, y, tile); + } + } + + private void drawLargeHexagon(Graphics2D g2d, int x, int y, Tile tile) { + Polygon hexagon = new Polygon(); + Point center = new Point(x, y); // Centre de l'hexagone + + // Calculer les points des sommets de l'hexagone + for (int i = 0; i < 6; i++) { + double angle = Math.toRadians(60 * i); + int px = x + (int) (Math.cos(angle) * hexRadius); + int py = y + (int) (Math.sin(angle) * hexRadius); + hexagon.addPoint(px, py); + } + + // Dessiner l'intérieur de l'hexagone en divisant en triangles + for (int i = 0; i < 6; i++) { + // Trouver les coordonnées des points du côté de l'hexagone + int x1 = hexagon.xpoints[i]; + int y1 = hexagon.ypoints[i]; + int x2 = hexagon.xpoints[(i + 1) % 6]; // Le point suivant (modulo 6) + int y2 = hexagon.ypoints[(i + 1) % 6]; + + // Dessiner un triangle avec le centre de l'hexagone + Polygon triangle = new Polygon(); + triangle.addPoint(center.x, center.y); // Ajouter le centre + triangle.addPoint(x1, y1); // Ajouter le premier sommet + triangle.addPoint(x2, y2); // Ajouter le deuxième sommet + + g2d.setColor(getColorForTerrain(tile.getTerrain())); + g2d.fillPolygon(triangle); // Remplir le triangle + g2d.setColor(Color.BLACK); + g2d.drawPolygon(triangle); // Dessiner les contours du triangle + } + + // Dessiner l'extérieur de l'hexagone + g2d.setColor(Color.BLACK); + g2d.drawPolygon(hexagon); + } + + + private Color getColorForTerrain(Terrain terrain) { + return switch (terrain) { + case MER -> Color.BLUE; + case CHAMP -> Color.YELLOW; + case FORET -> new Color(34, 139, 34); + case PRE -> Color.GREEN; + case MONTAGNE -> Color.GRAY; + }; + } + + private Point calculateHexCoordinates(Point clickPoint) { + int col = (int) Math.round((clickPoint.x - hexWidth / 2.0) / (1.5 * hexRadius)); + int row = (int) Math.round((clickPoint.y - hexHeight / 2.0 - (col % 2) * hexHeight / 4.0) / hexHeight); + return new Point(col, row); + } + + private int calculateScreenX(Point position) { + int col = position.x; + return (int) (col * 1.5 * hexRadius + hexWidth / 2.0); + } + + private int calculateScreenY(Point position) { + int col = position.x; + int row = position.y; + return (int) (row * hexHeight + (col % 2) * hexHeight / 2.0 + hexHeight / 2.0); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/utils/Database.java b/TestV1/TestEnAttendantResolutionBug/utils/Database.java new file mode 100644 index 0000000..2e5aac5 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/utils/Database.java @@ -0,0 +1,61 @@ +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class Database { + private static final String URL = "jdbc:mariadb://dwarves.iut-fbleau.fr:3306/foulou"; + private static final String LOGIN = "foulou"; + private static final String PASSWORD = "foulou"; + + private Connection database; + + public Database() throws SQLException { + try { + // Chargement explicite du driver + System.out.println("Tentative de chargement du driver MariaDB..."); + Class.forName("org.mariadb.jdbc.Driver"); + System.out.println("Driver MariaDB chargé avec succès."); + + try { + // Connexion à la base de données + System.out.println("Tentative de connexion à la base de données..."); + this.database = DriverManager.getConnection(URL, LOGIN, PASSWORD); + System.out.println("Connexion réussie !"); + } catch (SQLException e) { + System.err.println("Échec de la connexion à la base de données : " + e.getMessage()); + throw new SQLException("Erreur de connexion : " + e.getMessage(), e); + } + } catch (ClassNotFoundException e) { + System.err.println("Erreur : Le driver MariaDB n'a pas été trouvé dans le classpath."); + throw new SQLException("Driver MariaDB introuvable dans le classpath", e); + } + } + + public Connection getDatabase() { + return this.database; + } + + public void close() { + try { + if (this.database != null && !this.database.isClosed()) { + this.database.close(); + System.out.println("Connexion fermée."); + } + } catch (SQLException e) { + System.err.println("Erreur lors de la fermeture de la base de données : " + e.getMessage()); + } + } + + public static void main(String[] args) { + try { + // Crée une instance de la classe Database et teste la connexion + Database db = new Database(); + System.out.println("Connexion à la base de données réussie !"); + + // Fermer la connexion après test + db.close(); + } catch (SQLException e) { + System.err.println("Erreur lors de la connexion : " + e.getMessage()); + } + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/view/BoardView.java b/TestV1/TestEnAttendantResolutionBug/view/BoardView.java deleted file mode 100644 index e81065b..0000000 --- a/TestV1/TestEnAttendantResolutionBug/view/BoardView.java +++ /dev/null @@ -1,24 +0,0 @@ -package view; - -import javax.swing.*; -import model.Board; -import model.Tile; -import java.awt.*; - -public class BoardView extends JPanel { - private Board board; - - public BoardView(Board board) { - this.board = board; - setLayout(new GridLayout(5, 5, 5, 5)); // Exemple de grille 5x5 pour le plateau - } - - public void refreshBoard() { - removeAll(); - for (Tile tile : board.getTiles()) { - add(new TileView(tile.getType())); - } - revalidate(); - repaint(); - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/view/GameView.java b/TestV1/TestEnAttendantResolutionBug/view/GameView.java deleted file mode 100644 index 4028ecb..0000000 --- a/TestV1/TestEnAttendantResolutionBug/view/GameView.java +++ /dev/null @@ -1,28 +0,0 @@ -package view; - -import model.Game; -import javax.swing.*; -import java.awt.*; - -public class GameView extends JFrame { - private JLabel scoreLabel; - private BoardView boardView; - - public GameView(Game game) { - setTitle("Dorfromantik en Java"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(400, 400); - setLayout(new BorderLayout()); - - scoreLabel = new JLabel("Score : " + game.getScore()); - boardView = new BoardView(game.getBoard()); - - add(scoreLabel, BorderLayout.NORTH); - add(boardView, BorderLayout.CENTER); - } - - public void update(Game game) { - scoreLabel.setText("Score : " + game.getScore()); - boardView.refreshBoard(); - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/view/TileView.java b/TestV1/TestEnAttendantResolutionBug/view/TileView.java deleted file mode 100644 index b5bf724..0000000 --- a/TestV1/TestEnAttendantResolutionBug/view/TileView.java +++ /dev/null @@ -1,21 +0,0 @@ -package view; - -import javax.swing.*; -import java.awt.*; - -public class TileView extends JPanel { - private String type; - - public TileView(String type) { - this.type = type; - setPreferredSize(new Dimension(50, 50)); // Taille de la tuile - setBackground(Color.LIGHT_GRAY); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - g.setColor(Color.BLACK); - g.drawString(type, 10, 25); // Affiche le type de la tuile au centre - } -}