diff --git a/lib/postgresql-42.2.12.jar b/lib/postgresql-42.2.12.jar new file mode 100644 index 0000000..1f393bb Binary files /dev/null and b/lib/postgresql-42.2.12.jar differ diff --git a/src/database/ByteaToCardImage.java b/src/database/ByteaToCardImage.java new file mode 100644 index 0000000..a3983bd --- /dev/null +++ b/src/database/ByteaToCardImage.java @@ -0,0 +1,20 @@ +package database; + +import java.io.ByteArrayInputStream; +import java.awt.image.BufferedImage; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class ByteaToCardImage { + + public static BufferedImage getImg(byte[] imageData) { + ByteArrayInputStream bais = new ByteArrayInputStream(imageData); + try { + return ImageIO.read(bais); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} \ No newline at end of file diff --git a/src/database/DatabaseTesting.java b/src/database/DatabaseTesting.java index 93dc71e..e5aad7c 100644 --- a/src/database/DatabaseTesting.java +++ b/src/database/DatabaseTesting.java @@ -1,5 +1,7 @@ package database; +import java.awt.image.BufferedImage; + /* import java.sql.Connection; import java.sql.DriverManager; @@ -10,29 +12,20 @@ import java.sql.Statement; public class DatabaseTesting { public static void main(String[] args) { - /* - try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: - - System.out.println("Connected to PostgreSQL database!"); - Statement statement = connection.createStatement(); - System.out.println("Reading records..."); - System.out.printf("%-20.30s %-30.30s %-30.30s%n", "id", "nom", "image"); - ResultSet resultSet = statement.executeQuery(QueryGenerator.AllFrom("CartesAll")); - //ResultSet resultSet = statement.executeQuery(QueryGenerator.WithId("CartesAll", 15)); - //ResultSet resultSet = statement.executeQuery(QueryGenerator.WithName("CartesAll", "Vision Cupide")); - while (resultSet.next()) { - System.out.printf("%-20.30s %-30.30s %-20.30s%n", resultSet.getString("id"), resultSet.getString("nom"), resultSet.getBytes("image")); //resultSet.getBytes("image")); - } - - } catch (SQLException e) { - System.out.println("Connection failure."); - e.printStackTrace(); - } - */ - Table a = new Table("a"); - a.remplirTable("CartesLumiere"); - + a.remplirTableAllFrom("CartesAll"); + System.out.println(a.toString()); + BufferedImage jpg = new BufferedImage(467, 652, 1); + + + /* + try { + ByteaToCardImage.getImg(a.getList().get(5).getImg()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ diff --git a/src/database/QueryGenerator.java b/src/database/QueryGenerator.java index 1821da9..3ec85ee 100644 --- a/src/database/QueryGenerator.java +++ b/src/database/QueryGenerator.java @@ -10,12 +10,12 @@ public class QueryGenerator { return "SELECT * FROM " + getTable(table) + "WHERE id =" + d; } - public static String WithName(String s, String name) { - return "SELECT * FROM " + getTable(s) + "WHERE nom ='" + name + "'"; + public static String WithName(String table, String name) { + return "SELECT * FROM " + getTable(table) + "WHERE nom ='" + name + "'"; } public static String getTable(String s) { - return "public.\"" + s + "\""; + return "public." + '"' + s + '"'; } } diff --git a/src/database/Record.java b/src/database/Record.java index 6f2aad1..f95f1b9 100644 --- a/src/database/Record.java +++ b/src/database/Record.java @@ -35,6 +35,10 @@ public class Record { public byte[] getImg() { return img; } + + public String toString() { + return String.format("%-20.30s %-30.30s %-20.30s%n", this.getId(), this.getNom(), this.getImg()); + } } diff --git a/src/database/Table.java b/src/database/Table.java index b8cc929..2545740 100644 --- a/src/database/Table.java +++ b/src/database/Table.java @@ -16,8 +16,8 @@ public class Table { public Table(String JavaTableName) { this.name = JavaTableName; } - - public void remplirTable(String DatabaseTableName) { + + public void remplirTableAllFrom(String DatabaseTableName) { try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: System.out.println("Connected to PostgreSQL database!"); @@ -25,9 +25,41 @@ public class Table { System.out.println("Reading records..."); ResultSet retour = statement.executeQuery(QueryGenerator.AllFrom(DatabaseTableName)); while (retour.next()) { - Record r = new Record(retour.getString("id"), retour.getString("nom"), retour.getBytes("image")); - list.add(r); - System.out.printf("%-20.30s %-30.30s %-20.30s%n", retour.getString("id"), retour.getString("nom"), retour.getBytes("image")); + list.add(new Record(retour.getString("id"), retour.getString("nom"), retour.getBytes("image"))); + } + + } catch (SQLException e) { + System.out.println("Connection failure."); + e.printStackTrace(); + } + } + + public void remplirTableWithId(String DatabaseTableName, int id) { + try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: + + System.out.println("Connected to PostgreSQL database!"); + Statement statement = connection.createStatement(); + System.out.println("Reading records..."); + ResultSet retour = statement.executeQuery(QueryGenerator.WithId(DatabaseTableName, id)); + while (retour.next()) { + list.add(new Record(retour.getString("id"), retour.getString("nom"), retour.getBytes("image"))); + } + + } catch (SQLException e) { + System.out.println("Connection failure."); + e.printStackTrace(); + } + } + + public void remplirTableWithName(String DatabaseTableName, String s) { + try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: + + System.out.println("Connected to PostgreSQL database!"); + Statement statement = connection.createStatement(); + System.out.println("Reading records..."); + ResultSet retour = statement.executeQuery(QueryGenerator.WithName(DatabaseTableName, s)); + while (retour.next()) { + list.add(new Record(retour.getString("id"), retour.getString("nom"), retour.getBytes("image"))); } } catch (SQLException e) { @@ -48,6 +80,10 @@ public class Table { return list; } + public String toString() { + return " " + this.getList(); + } + diff --git a/src/ihm/Dice.java b/src/ihm/Dice.java new file mode 100644 index 0000000..586c07a --- /dev/null +++ b/src/ihm/Dice.java @@ -0,0 +1,60 @@ +package ihm; + +/** + * @author https://www.programcreek.com/java-api-examples/?code=AlmasB%2FFXTutorials%2FFXTutorials-master%2Fsrc%2Fcom%2Falmasb%2Ftutorial5%2FDice.java + * + */ + +import javafx.animation.RotateTransition; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.geometry.Pos; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; +import javafx.util.Duration; + +public class Dice extends StackPane { + + public static int MAX_VALUE = 6; + public static final int MIN_VALUE = 1; + + public final SimpleIntegerProperty valueProperty = new SimpleIntegerProperty(); + + int i = 0; + + public Dice(int valeurMax) { + + MAX_VALUE = valeurMax; + Rectangle rect = new Rectangle(50, 50); + + Text text = new Text(); + text.setFill(Color.WHITE); + text.textProperty().bind(valueProperty.asString()); + + this.setAlignment(Pos.CENTER); + getChildren().addAll(rect, text); + + this.setOnMouseClicked(event -> roll()); + } + + public void roll() { + RotateTransition rt = new RotateTransition(Duration.seconds(0.5), this); + rt.setFromAngle(0); + rt.setToAngle(360); + int cycles = 2000; + + rt.setOnFinished(event -> { + + valueProperty.set((int)(Math.random() * (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE); + + if(cycles < i) { + + rt.play(); + i++; + } + + }); + rt.play(); + } +} \ No newline at end of file diff --git a/src/ihm/Main.java b/src/ihm/Main.java index 21893df..297b9b5 100644 --- a/src/ihm/Main.java +++ b/src/ihm/Main.java @@ -23,6 +23,7 @@ public class Main extends Application { primaryStage.setTitle("Shadow Hunters"); primaryStage.setScene(new Scene(root)); primaryStage.centerOnScreen(); + primaryStage.setMaximized(true); primaryStage.show(); } diff --git a/src/ihm/PopUpBoolean.java b/src/ihm/PopUpBoolean.java index 9d98bc3..6bc8ed7 100644 --- a/src/ihm/PopUpBoolean.java +++ b/src/ihm/PopUpBoolean.java @@ -21,10 +21,6 @@ public class PopUpBoolean { private double xOffSet = 0; private double yOffSet = 0; - - - - public PopUpBoolean (Parent p, String titre) { @@ -62,8 +58,6 @@ public class PopUpBoolean { }); } - - public boolean display() { popup.setScene(scene); diff --git a/src/ihm/SpriteAnimation.java b/src/ihm/SpriteAnimation.java index b9d58af..9733d20 100644 --- a/src/ihm/SpriteAnimation.java +++ b/src/ihm/SpriteAnimation.java @@ -45,3 +45,4 @@ public class SpriteAnimation extends Transition { } } } + diff --git a/src/ihm/controller/ChoisirBoolean.java b/src/ihm/controller/ChoisirBoolean.java index 57c3f45..483c5c2 100644 --- a/src/ihm/controller/ChoisirBoolean.java +++ b/src/ihm/controller/ChoisirBoolean.java @@ -23,14 +23,13 @@ public class ChoisirBoolean implements Initializable{ public void initialize(URL arg0, ResourceBundle arg1) { } + @FXML public void choixOui(MouseEvent mouseEvent) throws IOException{ PopUpBoolean.result = true; final Node source = (Node) mouseEvent.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); stage.close(); - return; - } @FXML @@ -40,6 +39,5 @@ public class ChoisirBoolean implements Initializable{ final Node source = (Node) mouseEvent.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); stage.close(); - return; } } diff --git a/src/ihm/controller/MenuJoueurController.java b/src/ihm/controller/MenuJoueurController.java new file mode 100644 index 0000000..ebb8263 --- /dev/null +++ b/src/ihm/controller/MenuJoueurController.java @@ -0,0 +1,37 @@ +package ihm.controller; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.control.SplitPane; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; + +public class MenuJoueurController implements Initializable{ + + @Override + public void initialize(URL arg0, ResourceBundle arg1) { + //nomJoueur.setText(joueur.getNom()); + } + + @FXML + public void changeZoneToScrollPaneJoueur(MouseEvent me) throws IOException { + + AnchorPane bp = FXMLLoader.load(getClass().getResource("../ressources/ScrollPaneJoueur.fxml")); + ImageView iv = ((ImageView)me.getSource()); + Parent p = iv.getParent().getParent(); + AnchorPane ap = (AnchorPane)p; + ap.getChildren().setAll(bp); + AnchorPane.setTopAnchor(bp, 0.0); + AnchorPane.setBottomAnchor(bp, 0.0); + AnchorPane.setLeftAnchor(bp, 0.0); + AnchorPane.setRightAnchor(bp, 0.0); + } + +} diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index 03a9ceb..54a100b 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -11,9 +11,15 @@ import java.util.ResourceBundle; import ihm.PopUp; import ihm.PopUpBoolean; +import ihm.SpriteAnimation; +import javafx.animation.Animation; +import javafx.event.Event; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.geometry.Rectangle2D; +import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -21,6 +27,10 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +<<<<<<< HEAD +======= +import javafx.util.Duration; +>>>>>>> eea99d2341b1df015a2831034aa39534addff16e import main.Joueur; import main.View; @@ -41,6 +51,10 @@ public class PlateauController implements Initializable { @FXML private VBox joueur7; @FXML private VBox joueur8; + public static int DICE_SIX = 2; + public static int DICE_QUATRE = 1; + public static int DICE_BOTH = 0; + /** * initialise les données du plateau */ @@ -120,9 +134,7 @@ public class PlateauController implements Initializable { Parent root = loader.load(); PopUpBoolean popup = new PopUpBoolean(root, "Consulter sa carte"); - return popup.display(); - - + return popup.display(); } /** @@ -162,4 +174,11 @@ public class PlateauController implements Initializable { } }*/ } + + public void rollDice(Joueur joueur, int typeDice, int[] rolls) { + + + + } + } diff --git a/src/ihm/controller/PlateauControllerTest.java b/src/ihm/controller/PlateauControllerTest.java new file mode 100644 index 0000000..a551adc --- /dev/null +++ b/src/ihm/controller/PlateauControllerTest.java @@ -0,0 +1,182 @@ +package ihm.controller; + + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import ihm.PopUpBoolean; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.control.ScrollPane; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import main.Joueur; + +public class PlateauControllerTest implements Initializable { + + + @FXML private BorderPane root; + + + + /** + * initialise les donn�es du plateau + */ + @Override + public void initialize(URL arg0, ResourceBundle arg1) { + //initialisation des attributs des joueurs + + for(int i = 0; i < 8; i++) { + + + AnchorPane ap = getAnchorPaneJoueur(i); + Pane p; + try { + p = FXMLLoader.load(getClass().getResource("../ressources/MenuJoueur.fxml")); + if(i > 1 && i < 3) { + rotateContent(p, 90); + } + setContentAnchorPane(ap, p); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + } + + public GridPane getGridPaneJoueur(int pos) { + + int position = pos%8 / 2; + + position++; + + AnchorPane apParent = (AnchorPane) root.getChildren().get(position); + + GridPane gp = (GridPane) apParent.getChildren().get(0); + + return (GridPane) gp.getChildren().get(pos%2); + } + + + public AnchorPane getAnchorPaneJoueur(int pos) { + + GridPane gp = getGridPaneJoueur(pos); + return (AnchorPane) gp.getChildren().get(0); + } + + public ImageView getImageViewJoueur(int pos) { + + GridPane gp = getGridPaneJoueur(pos); + return (ImageView) gp.getChildren().get(1); + } + + public ScrollPane getScrollPaneJoueur(int pos) { + + GridPane gp = getGridPaneJoueur(pos); + return (ScrollPane) gp.getChildren().get(2); + } + + + public void setContentAnchorPane(AnchorPane ap, Pane p) { + + ap.getChildren().setAll(p); + + AnchorPane.setTopAnchor(p, 0.0); + AnchorPane.setBottomAnchor(p, 0.0); + AnchorPane.setLeftAnchor(p, 0.0); + AnchorPane.setRightAnchor(p, 0.0); + + } + + public void rotateContent(Pane p, double rotation) { + p.setRotate(rotation); + } + + + + /* + int OFFSET_X = 0; + int OFFSET_Y = 0; + int WIDTH = 557; + int HEIGHT = 557; + int COUNT = 6; + int COLUMNS = 6; + + //anchorPane1.getChildren().setAll(imageView); + + + ImageView imageView; + try { + imageView = FXMLLoader.load(getClass().getResource("../ressources/Dés.fxml")); + imageView.setViewport(new Rectangle2D(OFFSET_X, OFFSET_Y, WIDTH, HEIGHT)); + + imageView.fitWidthProperty().bind(anchorPane1.widthProperty()); + final SpriteAnimation animation = new SpriteAnimation( + imageView, + Duration.millis(250), + COUNT, COLUMNS, + OFFSET_X, OFFSET_Y, + WIDTH, HEIGHT + ); + animation.setCycleCount(Animation.INDEFINITE); + animation.play(); + anchorPane1.getChildren().addAll(new Group(imageView)); + anchorPane1.setOnMousePressed(new EventHandler( + + ) { + + @Override + public void handle(Event arg0) { + animation.stop(); + + } + }); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +*/ + + + + + + + /** + * Affiche aux yeux de tous la carte personnage du joueur + * + * @param j : Le joueur sur lequel on a cliqu� + */ + + + public boolean choisir(Joueur j) throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ressources/choisirBoolean.fxml")); + Parent root = loader.load(); + + PopUpBoolean popup = new PopUpBoolean(root, "Consulter sa carte"); + return popup.display(); + + + } + + public void rollDice(Joueur j, int typeDice, int[] resultats) { + + } + + /** + * Permet de consulter sa carte perssonage en cas d'oublie + * + * @param j : Le joueur sur lequel on a cliqu� + */ + + +} diff --git a/src/ihm/controller/PlayersController.java b/src/ihm/controller/PlayersController.java index 4a737b8..dcab38b 100644 --- a/src/ihm/controller/PlayersController.java +++ b/src/ihm/controller/PlayersController.java @@ -16,8 +16,6 @@ import javafx.fxml.Initializable; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.TextField; diff --git a/src/ihm/controller/ScrollPaneJoueurController.java b/src/ihm/controller/ScrollPaneJoueurController.java new file mode 100644 index 0000000..51dec9c --- /dev/null +++ b/src/ihm/controller/ScrollPaneJoueurController.java @@ -0,0 +1,44 @@ +package ihm.controller; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.control.SplitPane; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Pane; + +public class ScrollPaneJoueurController implements Initializable{ + + + + @Override + public void initialize(URL arg0, ResourceBundle arg1) { + + } + + @FXML + public void changeZoneJoueurToMenuJoueur(MouseEvent me) throws IOException { + + BorderPane bp = FXMLLoader.load(getClass().getResource("../ressources/MenuJoueur.fxml")); + ImageView iv = ((ImageView)me.getSource()); + Parent p = iv.getParent().getParent().getParent().getParent(); + AnchorPane ap = (AnchorPane)p; + + System.out.println(bp.getRotate()+" "+ ap.getRotate()); + ap.getChildren().setAll(bp); + + AnchorPane.setTopAnchor(bp, 0.0); + AnchorPane.setBottomAnchor(bp, 0.0); + AnchorPane.setLeftAnchor(bp, 0.0); + AnchorPane.setRightAnchor(bp, 0.0); + + } +} diff --git a/src/ihm/ressources/Dialog.fxml b/src/ihm/ressources/Dialog.fxml new file mode 100644 index 0000000..38e8622 --- /dev/null +++ b/src/ihm/ressources/Dialog.fxml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/ihm/ressources/Dés.fxml b/src/ihm/ressources/Dés.fxml new file mode 100644 index 0000000..3c2699a --- /dev/null +++ b/src/ihm/ressources/Dés.fxml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/ihm/ressources/MenuJoueur.fxml b/src/ihm/ressources/MenuJoueur.fxml new file mode 100644 index 0000000..badbf9c --- /dev/null +++ b/src/ihm/ressources/MenuJoueur.fxml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/ihm/ressources/PlateauTestPaul.fxml b/src/ihm/ressources/PlateauTestPaul.fxml new file mode 100644 index 0000000..1616744 --- /dev/null +++ b/src/ihm/ressources/PlateauTestPaul.fxml @@ -0,0 +1,585 @@ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/src/ihm/ressources/ScrollPaneJoueur.fxml b/src/ihm/ressources/ScrollPaneJoueur.fxml new file mode 100644 index 0000000..80c9874 --- /dev/null +++ b/src/ihm/ressources/ScrollPaneJoueur.fxml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ihm/ressources/ZoneJoueur.fxml b/src/ihm/ressources/ZoneJoueur.fxml new file mode 100644 index 0000000..2259923 --- /dev/null +++ b/src/ihm/ressources/ZoneJoueur.fxml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/ihm/ressources/choisirBoolean.fxml b/src/ihm/ressources/choisirBoolean.fxml index 28c2a49..fa0213f 100644 --- a/src/ihm/ressources/choisirBoolean.fxml +++ b/src/ihm/ressources/choisirBoolean.fxml @@ -2,22 +2,23 @@ - + - + + -