diff --git a/src/carte/CarteLieuMultiple.java b/src/carte/CarteLieuMultiple.java index 1c43f93..cb35003 100644 --- a/src/carte/CarteLieuMultiple.java +++ b/src/carte/CarteLieuMultiple.java @@ -25,6 +25,8 @@ public class CarteLieuMultiple extends CarteLieu{ */ public void utiliser(Joueur j) { Pioche p = (Pioche) j.choisir(pioches); + System.out.println(pioches+ " "+p); + System.out.println(p.getStack()); Carte c = p.piocher(); c.utiliser(j); } diff --git a/src/carte/CarteLieuType.java b/src/carte/CarteLieuType.java index 8982607..e0af7e0 100644 --- a/src/carte/CarteLieuType.java +++ b/src/carte/CarteLieuType.java @@ -31,6 +31,7 @@ public class CarteLieuType extends CarteLieu{ * @param j Appel la méthode utiliser de effet sur le joueur j */ public void utiliser(Joueur j) { + System.out.println(pioche); CartePiochable carte = pioche.piocher(); carte.utiliser(j); } diff --git a/src/carte/CartePiochable.java b/src/carte/CartePiochable.java index 10890e7..b5ff603 100644 --- a/src/carte/CartePiochable.java +++ b/src/carte/CartePiochable.java @@ -20,10 +20,12 @@ public class CartePiochable extends CarteCondition implements Serializable{ public CartePiochable(Type t, String nom, String description) { super(nom, description); + this.type = t; } public CartePiochable(Type t, Effet e, Condition c) { super(); + this.type = t; this.setEffet(e); this.setCondition(c); } diff --git a/src/database/CreatingCardsTest.java b/src/database/CreatingCardsTest.java index db5e5ef..cb4aa81 100644 --- a/src/database/CreatingCardsTest.java +++ b/src/database/CreatingCardsTest.java @@ -45,7 +45,7 @@ public class CreatingCardsTest { //Ange gardien try { - /* + DatabaseManager.queryInsertObject(2,new CartePiochable(CartePiochable.Type.LUMIERE, new EffetSelf(new ActionAltererStatistiquesJoueur(Joueur.PLAYER_IMMUNITY, 1, true)))); @@ -240,7 +240,7 @@ public class CreatingCardsTest { DatabaseManager.queryInsertObject(56,new Metamorphe()); DatabaseManager.queryInsertObject(57,new Vampire()); - */ + //62 diff --git a/src/database/QueryGenerator.java b/src/database/QueryGenerator.java index 7147a91..fb27905 100644 --- a/src/database/QueryGenerator.java +++ b/src/database/QueryGenerator.java @@ -54,6 +54,8 @@ public class QueryGenerator { table = getTable("CartesPersonnage"); } else if(id <= 61) { table = getTable("CartesDos"); + }else if(id <= 67) { + table = getTable("CartesLieu"); } return "SELECT * FROM " + table + " WHERE id = " + id; } diff --git a/src/database/RessourceLoader.java b/src/database/RessourceLoader.java index a5e9154..b7eb816 100644 --- a/src/database/RessourceLoader.java +++ b/src/database/RessourceLoader.java @@ -1,6 +1,7 @@ package database; -import java.awt.Image; + +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -15,6 +16,8 @@ import javax.imageio.ImageIO; import carte.Carte; import carte.CarteLieu; import carte.CartePiochable; +import javafx.embed.swing.SwingFXUtils; +import javafx.scene.image.Image; import personnage.CartePersonnage; public class RessourceLoader { @@ -35,28 +38,30 @@ public class RessourceLoader { private final int ID_DOS_TENEBRE= 59; private final int ID_DOS_VISION= 61; - private Map ressourcesCartes; - private Map ressourcesDosCartes; + private Map ressourcesCartes; + private Map ressourcesDosCartes; public RessourceLoader() { - this.ressourcesCartes = new HashMap(); - this.ressourcesDosCartes = new HashMap(); + this.ressourcesCartes = new HashMap(); + this.ressourcesDosCartes = new HashMap(); } private Map loadCards() throws ClassNotFoundException, IOException{ Table t = new Table(); Map cartes = new HashMap(); - for(int i = 0; i < 61; i++) { + for(int i = 0; i < 67; i++) { String query = QueryGenerator.selectId(i+1); t.remplirTableQuery(query); - byte[] obj = t.getList().get(i).getObjet(); + Record r = t.getList().get(i); + byte[] obj = r.getObjet(); if(obj != null) { Object o = deserialize(obj); Carte c = (Carte)o; + c.setNom(r.getNom()); cartes.put(i+1, c); } } @@ -105,21 +110,21 @@ public class RessourceLoader { return is.readObject(); } - private Image loadImage(int id) throws IOException { + private BufferedImage loadImage(int id) throws IOException { String name = ""+id+".png"; String url = "ressources/cartes/"+name; - Image picture = ImageIO.read(new File(url)); + BufferedImage picture = ImageIO.read(new File(url)); return picture; } - private Map getMapImageCarte(Map cartes) throws IOException{ + private Map getMapImageCarte(Map cartes) throws IOException{ - Map mapCarteImage = new HashMap(); + Map mapCarteImage = new HashMap(); for(Integer i : cartes.keySet()) { Carte c = cartes.get(i); - Image img = loadImage(i); + BufferedImage img = loadImage(i); mapCarteImage.put(c,img); } @@ -164,13 +169,12 @@ public class RessourceLoader { List cartesType = new ArrayList(); for(Carte c : cartes) { - - if(c instanceof CartePiochable) { CartePiochable carte = (CartePiochable) c; - + System.out.println(carte.getNom()+" "+carte.getType()); CartePiochable.Type type = carte.getType(); + if(t == type) { cartesType.add(carte); } @@ -208,4 +212,16 @@ public class RessourceLoader { return cartesLieu; } + public Map getRessourceCartes(){ + return this.ressourcesCartes; + } + + public Map getRessourceDosCartes(){ + return this.ressourcesDosCartes; + } + + public static Image toJavaFX(BufferedImage img) { + Image image = SwingFXUtils.toFXImage(img, null); + return image; + } } diff --git a/src/ihm/Main.java b/src/ihm/Main.java index 48fd41b..693c2e4 100644 --- a/src/ihm/Main.java +++ b/src/ihm/Main.java @@ -6,6 +6,7 @@ import java.net.URL; import java.util.Locale; import java.util.ResourceBundle; +import database.RessourceLoader; import javafx.application.Application; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; @@ -44,11 +45,11 @@ public class Main extends Application { public static void main(String[] args) { GestionnaireJeu gj = GestionnaireJeu.getGestionnaireJeu(); - /* + RessourceLoader rl = new RessourceLoader(); rl.loadRessources(); gj.setRessourceLoader(rl); - */ + launch(args); } } \ No newline at end of file diff --git a/src/ihm/controller/GestionnaireDePions.java b/src/ihm/controller/GestionnaireDePions.java index dd44d71..6f57989 100644 --- a/src/ihm/controller/GestionnaireDePions.java +++ b/src/ihm/controller/GestionnaireDePions.java @@ -44,8 +44,7 @@ public class GestionnaireDePions { StackPane nNew = (StackPane) gp.getChildren().get(damage); FlowPane fpNew = (FlowPane) nNew.getChildren().get(0); - fpNew.getChildren().add(pionVie); - + if(!fpNew.getChildren().contains(pionVie)) fpNew.getChildren().add(pionVie); } @@ -66,9 +65,10 @@ public class GestionnaireDePions { } StackPane sp = (StackPane) hbox.getChildren().get(indexCL%2); - FlowPane fp = (FlowPane) sp.getChildren().get(0); + FlowPane fp = (FlowPane) sp.getChildren().get(1); - fp.getChildren().add(this.pionLieu); + if(!fp.getChildren().contains(this.pionLieu)) fp.getChildren().add(this.pionLieu); + } diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index 4b9e416..00e944c 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -1,6 +1,7 @@ package ihm.controller; +import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -11,20 +12,31 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.Set; +import carte.Carte; +import carte.CarteLieu; +import database.RessourceLoader; import ihm.EffetSonore; import ihm.PopUp; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Group; -import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; +import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import main.GestionnaireJeu; @@ -41,7 +53,9 @@ public class PlateauController implements Initializable { private ChoisirBoolean cb; - + + + private Map mapRessourcesCartes; public static int DICE_SIX = 2; public static int DICE_QUATRE = 1; public static int DICE_BOTH = 0; @@ -55,6 +69,8 @@ public class PlateauController implements Initializable { this.joueursIHM = new ArrayList(); GestionnaireJeu gj = GestionnaireJeu.getGestionnaireJeu(); + RessourceLoader rl = gj.getRessourceLoader(); + Map map = gj.getMapJoueurs(); for(int i = 0 ; i < gridPaneVie.getChildren().size();i++) { @@ -75,7 +91,12 @@ public class PlateauController implements Initializable { } + mapRessourcesCartes = rl.getRessourceCartes(); + + List cl = gj.getCartesLieux(); + List ivs = this.getLieux(); + applyImages(cl,ivs); // BUTTONS ETC //System.out.println(this.joueursPane); @@ -162,6 +183,31 @@ public class PlateauController implements Initializable { } + private void applyImages(List cls, List ivs) { + + int size = cls.size(); + if(cls.size() == ivs.size()) { + + for(int i = 0; i < size; i++) { + + CarteLieu cl = cls.get(i); + ImageView iv = ivs.get(i); + + BufferedImage bi = mapRessourcesCartes.get(cl); + Image image = RessourceLoader.toJavaFX(bi); + applyImageLieu(iv,image); + } + } + } + + private void applyImageLieu(ImageView iv, Image im) { + + StackPane sp = (StackPane) iv.getParent(); + iv.setImage(im); + iv.fitHeightProperty().bind(sp.heightProperty()); + } + + private Pane getPaneJoueur(int i) { System.out.println("i "+i); @@ -197,6 +243,21 @@ public class PlateauController implements Initializable { return (Pane) gp.getChildren().get(i%2); } + private List getLieux() { + + List views = new ArrayList(); + for(int i = 0 ; i < gridPaneLieux.getChildren().size(); i++) { + + HBox p = (HBox) gridPaneLieux.getChildren().get(i); + for(int j = 0; j < p.getChildren().size(); j++) { + StackPane sp = (StackPane) p.getChildren().get(j); + ImageView iv = (ImageView) sp.getChildren().get(0); + views.add(iv); + } + } + return views; + } + /** * Affiche aux yeux de tous la carte personnage du joueur * diff --git a/src/ihm/ressources/PlateauTest2.fxml b/src/ihm/ressources/PlateauTest2.fxml index 8c4f657..b58ca3c 100644 --- a/src/ihm/ressources/PlateauTest2.fxml +++ b/src/ihm/ressources/PlateauTest2.fxml @@ -18,7 +18,7 @@ - + @@ -70,6 +70,9 @@ + + + @@ -108,6 +111,9 @@ + + + @@ -167,6 +173,9 @@