Commit fd2d0560 authored by Jolan RENOUX's avatar Jolan RENOUX
Browse files

maj appp

parent 869ae2cf
import PremiereFenetre.PremiereFenetre; import PremiereFenetre.PremiereFenetre;
import com.mashape.unirest.http.exceptions.UnirestException; import com.mashape.unirest.http.exceptions.UnirestException;
import com.sun.jdi.connect.Connector;
import info1.network.*; import info1.network.*;
import info1.ships.BadCoordException; import info1.ships.BadCoordException;
import info1.ships.CoordsBadShipException; import info1.ships.CoordsBadShipException;
...@@ -23,8 +24,17 @@ public class Application { ...@@ -23,8 +24,17 @@ public class Application {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
Game jeu;
boolean done = false;
Player jaquie; Player jaquie;
int valtouche;
Game jeu = null;
try {
jeu = new Game(0);
} catch (BadIdException e) { e.printStackTrace();}
/* /*
FenetreConnexion fc = new FenetreConnexion("Connexion au serveur et aux parties"); FenetreConnexion fc = new FenetreConnexion("Connexion au serveur et aux parties");
...@@ -44,12 +54,15 @@ public class Application { ...@@ -44,12 +54,15 @@ public class Application {
//TODO Init fleet avec boucle listener ect //TODO Init fleet avec boucle listener ect
NavyFleet fleet = new NavyFleet(); NavyFleet fleet = new NavyFleet();
/* flotte de test
try { try {
fleet.add(new AircraftCarrier("porteavion1","A1","A6")); fleet.add(new AircraftCarrier("porteavion1","A1","A6"));
fleet.add(new AircraftCarrier("porteavion2","B1","B6")); fleet.add(new AircraftCarrier("porteavion2","B1","B6"));
fleet.add(new AircraftCarrier("porteavion3","C1","C6")); fleet.add(new AircraftCarrier("porteavion3","C1","C6"));
fleet.add(new AircraftCarrier("porteavion4","D1","D6")); fleet.add(new AircraftCarrier("porteavion4","D1","D6"));
} catch (BadCoordException | CoordsBadShipException e) {e.printStackTrace();} } catch (BadCoordException | CoordsBadShipException e) {e.printStackTrace();}
*/
while(pf.fc.isValider()){Thread.sleep(500);} while(pf.fc.isValider()){Thread.sleep(500);}
jaquie = new Player(pf.fc.getPseudo()); jaquie = new Player(pf.fc.getPseudo());
...@@ -57,23 +70,29 @@ public class Application { ...@@ -57,23 +70,29 @@ public class Application {
//TODO IHM : combobox avec cette liste //TODO IHM : combobox avec cette liste
while (done) {
if (pf.fc.getChoix() == 1) {
//rejoindre
try {
//TODO Init game ou rejoindre jeu = pf.fc.getJeu();
//new game Network.joinGame(url,pf.fc.getJeu(),jaquie,fleet);
try { } catch (UnirestException | UncompleteFleetException | BadCoordException e) { e.printStackTrace();}
Network.initNewGame(url,jaquie,fleet); done = true;
} //rejoindre game } else if (pf.fc.getChoix() == 2) {
catch (UnirestException | BadCoordException | UncompleteFleetException e) { //creer partie
e.printStackTrace(); try {
jeu = Network.initNewGame(url,jaquie,fleet);
}
catch (UnirestException | BadCoordException | UncompleteFleetException e) {e.printStackTrace();}
done = true;
} else if (pf.fc.getChoix() == 0) {
//pas encore choisi
} else {
//probleme
System.out.println("PROBLEME");
}
} }
/*
try {
Network.joinGame(url,LISTENER_GAME_CHOISI_DANS_LA_LISTE,jaquie,fleet);
} catch (UnirestException | UncompleteFleetException | BadCoordException e) {e.printStackTrace();}
*/
/* /*
...@@ -99,8 +118,11 @@ public class Application { ...@@ -99,8 +118,11 @@ public class Application {
break; break;
case 10: case 10:
System.out.println("10 c'est au joueur courant de jouer"); System.out.println("10 c'est au joueur courant de jouer");
while (FenetreJeux.getCoco() != null) while (FenetreJeux.getCoco() != null) {
Network.playOneTurn("http://172.26.82.18//api/v0", GAME, jaquie, FenetreJeux.getCoco()); try {
valtouche = Network.playOneTurn("http://172.26.82.18//api/v0", jeu, jaquie, FenetreJeux.getCoco());
} catch (UnirestException | BadCoordException e) { e.printStackTrace();}
}
break; break;
case -10: case -10:
System.out.println("-10 ce n'est pas au joueur courant de jouer"); System.out.println("-10 ce n'est pas au joueur courant de jouer");
......
...@@ -27,6 +27,7 @@ import java.util.function.BiPredicate; ...@@ -27,6 +27,7 @@ import java.util.function.BiPredicate;
public class FenetreConnexion extends JFrame { public class FenetreConnexion extends JFrame {
private boolean valider = false; private boolean valider = false;
private int choix = 0;
private Game jeu; private Game jeu;
...@@ -229,15 +230,16 @@ public class FenetreConnexion extends JFrame { ...@@ -229,15 +230,16 @@ public class FenetreConnexion extends JFrame {
rejoindre.addActionListener(new ActionListener() { rejoindre.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
jeu = (Game) pInitialise.getSelectedItem();
choix = 1;
//TODO ihm changer fenetre
} }
}); });
creerPartie.addActionListener(new ActionListener() { creerPartie.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
choix = 2;
} }
}); });
...@@ -303,11 +305,11 @@ public class FenetreConnexion extends JFrame { ...@@ -303,11 +305,11 @@ public class FenetreConnexion extends JFrame {
public String getPseudo(){ return pseudo.getText(); } public String getPseudo(){ return pseudo.getText(); }
public boolean isValider() { return valider;} public boolean isValider() { return valider;}
public Game getJeu() { return jeu;} public Game getJeu() { return jeu;}
public int getChoix() { return choix; }
// public Integer getGameID(){ return gameId; } // public Integer getGameID(){ return gameId; }
public NavyFleet getFlotte(){ return flotte;} public NavyFleet getFlotte(){ return flotte;}
public Boolean getCreerpartie() { return true; } public Boolean getCreerpartie() { return true; }
public Game getgamefromlist(){ return (Game) pInitialise.getSelectedItem();}
// Les setters // Les setters
// public void setGameID(Integer i){ gameId = i; } // public void setGameID(Integer i){ gameId = i; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment