Récupération objet bdd
This commit is contained in:
parent
40ad1cb599
commit
222605628c
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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<T extends Type> extends CarteCondition{
|
||||
public class CartePiochable<T extends Type> 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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
93
src/database/TestAddingCard.java
Normal file
93
src/database/TestAddingCard.java
Normal file
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<MouseEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(MouseEvent event){
|
||||
|
||||
xOffSet = event.getSceneX();
|
||||
yOffSet = event.getSceneY();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
p.setOnMouseDragged(new EventHandler<MouseEvent>() {
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<Integer, Joueur> mapJoueurs = convertConfiguration(c);
|
||||
this.mapJoueurs = mapJoueurs;
|
||||
|
||||
List<Joueur> joueurs = new ArrayList();
|
||||
List<Joueur> joueurs = new ArrayList<Joueur>();
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user