diff --git a/src/carte/Carte.java b/src/carte/Carte.java index e458f90..9ce64d8 100644 --- a/src/carte/Carte.java +++ b/src/carte/Carte.java @@ -1,9 +1,15 @@ package carte; +import java.io.Serializable; + import main.Joueur; -public abstract class Carte { +public abstract class Carte implements Serializable { + /** + * + */ + private static final long serialVersionUID = -3227553705226975570L; private String nom; private String description; diff --git a/src/carte/CarteCondition.java b/src/carte/CarteCondition.java index a42d513..44fe4e2 100644 --- a/src/carte/CarteCondition.java +++ b/src/carte/CarteCondition.java @@ -1,9 +1,18 @@ package carte; import main.Joueur; + +import java.io.Serializable; + import condition.Condition; -public abstract class CarteCondition extends CarteEffet{ +public abstract class CarteCondition extends CarteEffet implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 903022795821166067L; + public CarteCondition(String nom, String description) { super(nom, description); diff --git a/src/carte/CarteEffet.java b/src/carte/CarteEffet.java index f3a235d..b5c8af0 100644 --- a/src/carte/CarteEffet.java +++ b/src/carte/CarteEffet.java @@ -1,10 +1,17 @@ package carte; import main.Joueur; + +import java.io.Serializable; + import effet.Effet; -public abstract class CarteEffet extends Carte{ +public abstract class CarteEffet extends Carte implements Serializable{ + /** + * + */ + private static final long serialVersionUID = -5248405395465365805L; private Effet effet; public CarteEffet(String nom, String description) { diff --git a/src/carte/CartePiochable.java b/src/carte/CartePiochable.java index 19c3cc2..b0fb2d5 100644 --- a/src/carte/CartePiochable.java +++ b/src/carte/CartePiochable.java @@ -1,14 +1,25 @@ package carte; +import java.io.Serializable; + +import condition.Condition; +import effet.Effet; import main.Joueur; import main.Type; -public class CartePiochable extends CarteCondition{ +public class CartePiochable extends CarteCondition implements Serializable{ + + private static final long serialVersionUID = 2391013233873750967L; public CartePiochable(String nom, String description) { super(nom, description); - // TODO Auto-generated constructor stub + } + + public CartePiochable(Effet e, Condition c) { + super("",""); + this.setEffet(e); + this.setCondition(c); } /* diff --git a/src/condition/Condition.java b/src/condition/Condition.java index 2b0d1bb..4d3eaa6 100644 --- a/src/condition/Condition.java +++ b/src/condition/Condition.java @@ -1,8 +1,15 @@ package condition; +import java.io.Serializable; + import main.Joueur; -public class Condition { +public class Condition implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 8276438989479754732L; + public boolean isTrue(Joueur joueur) { return true; } diff --git a/src/database/DatabaseTesting.java b/src/database/DatabaseTesting.java index e89a2cf..a82aed5 100644 --- a/src/database/DatabaseTesting.java +++ b/src/database/DatabaseTesting.java @@ -3,7 +3,6 @@ package database; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import javax.imageio.ImageIO; diff --git a/src/database/TestAddingCard.java b/src/database/TestAddingCard.java new file mode 100644 index 0000000..8be09b9 --- /dev/null +++ b/src/database/TestAddingCard.java @@ -0,0 +1,93 @@ +package database; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import carte.CartePiochable; +import condition.Condition; +import effet.EffetSelf; +import effet.action.ActionAltererStatistiquesJoueur; +import main.Joueur; + +public class TestAddingCard { + + + private final static String url = "jdbc:postgresql://localhost:5432/ShadowHunterDatabase"; + private final static String user = "shManager"; + private final static String password = "shadowhunter1234"; + + + public static void main(String[] args) { + + CartePiochable instance = new CartePiochable(new EffetSelf(new ActionAltererStatistiquesJoueur(Joueur.PLAYER_HP, 2, true)), new Condition()); + + + try { + insertCartePiochable(instance); + System.out.println(retrieveCartePiochable(0).getEffet()); + } catch (IOException | SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public static Connection connect() throws SQLException { + return DriverManager.getConnection(url, user, password); + } + + public static void insertCartePiochable(CartePiochable instance) throws IOException, SQLException { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos; + + oos = new ObjectOutputStream(baos); + oos.writeObject(instance); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + + byte[] object = bais.readAllBytes(); + InputStream objectIS = new ByteArrayInputStream(object); + + String sql = "INSERT INTO public.\"Test\"" + "VALUES(?)"; + + Connection conn = connect(); + PreparedStatement pst = conn.prepareStatement(sql); + pst.setBinaryStream(1, objectIS); + pst.executeUpdate(); + + } + + public static CartePiochable retrieveCartePiochable(int pos) throws IOException, SQLException, ClassNotFoundException { + + Connection conn = connect(); + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery("SELECT * FROM public.\"Test\""); + + byte[] object = null; + if(rs.next()) { + object = rs.getBytes(1); + } + + + + ByteArrayInputStream in = new ByteArrayInputStream(object); + ObjectInputStream is = new ObjectInputStream(in); + return (CartePiochable) is.readObject(); + + } + + +} diff --git a/src/effet/Effet.java b/src/effet/Effet.java index 20125ce..c6b34ce 100644 --- a/src/effet/Effet.java +++ b/src/effet/Effet.java @@ -1,10 +1,14 @@ package effet; +import java.io.Serializable; + import effet.action.Action; import main.Joueur; -public abstract class Effet { +public abstract class Effet implements Serializable{ + private static final long serialVersionUID = 1121660401755188715L; + private Action action; public Effet(Action action) diff --git a/src/effet/EffetCiblerAdjacents.java b/src/effet/EffetCiblerAdjacents.java index c15fe08..5f7c529 100644 --- a/src/effet/EffetCiblerAdjacents.java +++ b/src/effet/EffetCiblerAdjacents.java @@ -9,7 +9,6 @@ public class EffetCiblerAdjacents extends Effet{ public EffetCiblerAdjacents(Action action) { super(action); } - @Override public void utiliser(Joueur joueur) @@ -21,9 +20,5 @@ public class EffetCiblerAdjacents extends Effet{ { action.affecte(joueur, j); } - } - - - } diff --git a/src/effet/action/Action.java b/src/effet/action/Action.java index 106b3c8..593c218 100644 --- a/src/effet/action/Action.java +++ b/src/effet/action/Action.java @@ -1,8 +1,13 @@ package effet.action; +import java.io.Serializable; + import main.Joueur; -public abstract class Action { +public abstract class Action implements Serializable{ + + + private static final long serialVersionUID = 4290735254363171340L; public abstract void affecte(Joueur j1, Joueur j2); diff --git a/src/ihm/PopUpBoolean.java b/src/ihm/PopUpBoolean.java index 6bc8ed7..a284ff6 100644 --- a/src/ihm/PopUpBoolean.java +++ b/src/ihm/PopUpBoolean.java @@ -13,7 +13,6 @@ import javafx.stage.StageStyle; public class PopUpBoolean { - @FXML private Pane rootPane; private Scene scene; private Stage popup; @@ -23,26 +22,19 @@ public class PopUpBoolean { public PopUpBoolean (Parent p, String titre) { - popup = new Stage(); - popup.initModality(Modality.WINDOW_MODAL); - popup.initStyle(StageStyle.UNDECORATED); - popup.setTitle(titre); - scene = new Scene(p); p.setOnMousePressed(new EventHandler() { - @Override public void handle(MouseEvent event){ xOffSet = event.getSceneX(); yOffSet = event.getSceneY(); } - }); p.setOnMouseDragged(new EventHandler() { @@ -51,19 +43,14 @@ public class PopUpBoolean { public void handle(MouseEvent event){ popup.setX(event.getScreenX() - xOffSet); - popup.setY(event.getScreenY() - yOffSet); - - } - + popup.setY(event.getScreenY() - yOffSet); + } }); } - + public boolean display() { - popup.setScene(scene); - popup.showAndWait(); - return result; } } diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index d01148b..9b7f841 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -264,7 +264,6 @@ public class PlateauController implements Initializable { public void rollDice(Joueur joueur, int typeDice, int[] rolls) { - } public void afficherChoisir(Joueur j) throws IOException { diff --git a/src/main/GestionnaireJeu.java b/src/main/GestionnaireJeu.java index 5956758..2fb883d 100644 --- a/src/main/GestionnaireJeu.java +++ b/src/main/GestionnaireJeu.java @@ -77,7 +77,6 @@ public class GestionnaireJeu { e.printStackTrace(); } - }); this.waitPlateau(); @@ -111,19 +110,16 @@ public class GestionnaireJeu { } } } - + public static void notifyPlateau() { - synchronized(plateau) { plateau.notify(); } - } public void rollDice(Joueur joueur, int typeDice, int ... rolls){ pc.rollDice(joueur,typeDice,rolls); - } public void setConfiguration(Configuration c) { @@ -131,13 +127,13 @@ public class GestionnaireJeu { Map mapJoueurs = convertConfiguration(c); this.mapJoueurs = mapJoueurs; - List joueurs = new ArrayList(); + List joueurs = new ArrayList(); for(Joueur j : mapJoueurs.values()) { joueurs.add(j); } - this.plateau = new Plateau(joueurs); + plateau = new Plateau(joueurs); } @@ -151,7 +147,7 @@ public class GestionnaireJeu { } public void setPlateauController(PlateauController pc2) { - this.pc = pc2; + pc = pc2; } diff --git a/src/main/Plateau.java b/src/main/Plateau.java index b57b9d7..083aecd 100644 --- a/src/main/Plateau.java +++ b/src/main/Plateau.java @@ -355,14 +355,10 @@ public class Plateau extends Thread{ Collections.shuffle(lieux); - for(int i = 0; i < lieux.size(); i += 2) { - + for(int i = 0; i < lieux.size(); i += 2) { lieux.get(i).setVoisin(lieux.get(i+1)); lieux.get(i+1).setVoisin(lieux.get(i)); } - - }else { - } }