resolution probleme lié au conflit git
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Board {
|
||||
private List<Tile> tiles;
|
||||
|
||||
public Board() {
|
||||
tiles = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addTile(Tile tile) {
|
||||
tiles.add(tile);
|
||||
}
|
||||
|
||||
public List<Tile> 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
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
@@ -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];
|
||||
}
|
||||
}
|
18
TestV1/TestEnAttendantResolutionBug/src/Makefile
Normal file
18
TestV1/TestEnAttendantResolutionBug/src/Makefile
Normal file
@@ -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)
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
21
TestV1/TestEnAttendantResolutionBug/src/controller/Main.java
Normal file
21
TestV1/TestEnAttendantResolutionBug/src/controller/Main.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
0
TestV1/TestEnAttendantResolutionBug/src/java
Normal file
0
TestV1/TestEnAttendantResolutionBug/src/java
Normal file
0
TestV1/TestEnAttendantResolutionBug/src/javac
Normal file
0
TestV1/TestEnAttendantResolutionBug/src/javac
Normal file
29
TestV1/TestEnAttendantResolutionBug/src/model/Board.java
Normal file
29
TestV1/TestEnAttendantResolutionBug/src/model/Board.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package model;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Board {
|
||||
private final Map<Point, Tile> 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<Point, Tile> getTiles() {
|
||||
return tiles;
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package model;
|
||||
|
||||
public enum Terrain {
|
||||
MER, CHAMP, FORET, PRE, MONTAGNE
|
||||
}
|
33
TestV1/TestEnAttendantResolutionBug/src/model/Tile.java
Normal file
33
TestV1/TestEnAttendantResolutionBug/src/model/Tile.java
Normal file
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
123
TestV1/TestEnAttendantResolutionBug/src/view/GameView.java
Normal file
123
TestV1/TestEnAttendantResolutionBug/src/view/GameView.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
61
TestV1/TestEnAttendantResolutionBug/utils/Database.java
Normal file
61
TestV1/TestEnAttendantResolutionBug/utils/Database.java
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user