adaptation interfaces boolean

This commit is contained in:
Chiara 2020-05-05 14:21:34 +02:00
commit 901f872e3e
16 changed files with 189 additions and 47 deletions

Binary file not shown.

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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);
}
/*

View File

@ -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;
}

View File

@ -0,0 +1,90 @@
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();
}
}

View File

@ -1,9 +1,13 @@
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;

View File

@ -10,7 +10,6 @@ public class EffetCiblerAdjacents extends Effet{
super(action);
}
@Override
public void utiliser(Joueur joueur)
{
@ -21,9 +20,5 @@ public class EffetCiblerAdjacents extends Effet{
{
action.affecte(joueur, j);
}
}
}

View File

@ -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);

View File

@ -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>() {
@ -52,18 +44,13 @@ public class PopUpBoolean {
popup.setX(event.getScreenX() - xOffSet);
popup.setY(event.getScreenY() - yOffSet);
}
});
}
public boolean display() {
popup.setScene(scene);
popup.showAndWait();
return result;
}
}

View File

@ -22,15 +22,12 @@ public class ChoisirBoolean implements Initializable {
this.result = true;
GestionnaireJeu.notifyPlateau();
});
nonButton.setOnAction(x -> {
this.result = false;
GestionnaireJeu.notifyPlateau();
});
}
public boolean getResult() {

View File

@ -0,0 +1,33 @@
package ihm.controller;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
public class PiocherVisionController implements Initializable{
@FXML private Pane rootPane;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
@FXML
public void voirCarte(MouseEvent mouseEvent) throws IOException{
final URL fxmlURL = getClass().getResource("/ihm/ressources/jouer_Son_Tour_donner_vision.fxml");
final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE);
final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle);
Pane pane = fxmlLoader.load();
rootPane.getChildren().setAll(pane);
}
}

View File

@ -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 {

View File

@ -77,7 +77,6 @@ public class GestionnaireJeu {
e.printStackTrace();
}
});
this.waitPlateau();
@ -113,17 +112,14 @@ 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;
}

View File

@ -356,13 +356,9 @@ public class Plateau extends Thread{
Collections.shuffle(lieux);
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 {
}
}