diff --git a/bin/Serveur.class b/bin/Serveur.class index 559a1cd..2722342 100644 Binary files a/bin/Serveur.class and b/bin/Serveur.class differ diff --git a/bin/game/Command.class b/bin/game/Command.class index 2695c81..1a398c8 100644 Binary files a/bin/game/Command.class and b/bin/game/Command.class differ diff --git a/bin/game/ComsJoueur.class b/bin/game/ComsJoueur.class index 0b7f0a1..a06a8ac 100644 Binary files a/bin/game/ComsJoueur.class and b/bin/game/ComsJoueur.class differ diff --git a/bin/game/DeckSerializer.class b/bin/game/DeckSerializer.class index 67755f3..de5a988 100644 Binary files a/bin/game/DeckSerializer.class and b/bin/game/DeckSerializer.class differ diff --git a/bin/game/Joueur.class b/bin/game/Joueur.class index 5d1fb9a..d9c260a 100644 Binary files a/bin/game/Joueur.class and b/bin/game/Joueur.class differ diff --git a/bin/game/PlayerTesteur.class b/bin/game/PlayerTesteur.class index 3a671e8..7d18dab 100644 Binary files a/bin/game/PlayerTesteur.class and b/bin/game/PlayerTesteur.class differ diff --git a/bin/game/deck/DeckRegistery.class b/bin/game/deck/DeckRegistery.class index 88a3ce7..a884f08 100644 Binary files a/bin/game/deck/DeckRegistery.class and b/bin/game/deck/DeckRegistery.class differ diff --git a/src/Serveur.java b/src/Serveur.java index ae1f63f..4c50c1c 100644 --- a/src/Serveur.java +++ b/src/Serveur.java @@ -59,6 +59,10 @@ public class Serveur { if (PlayerTesteur.playerTest(joueur2Com)) { new Match(joueur1Com,joueur2Com); System.out.println("match lancé"); + joueur2EnAttente = null; + joueur2Com=null; + joueur1EnAttente = null; + joueur1Com=null; } else { // le joueur est cassé donc on le retire de la file d'attente System.out.println("j2 invalid"); diff --git a/src/game/Command.java b/src/game/Command.java index 11a8181..8caa0c2 100644 --- a/src/game/Command.java +++ b/src/game/Command.java @@ -18,8 +18,7 @@ public final class Command { public static final String WIN = "win"; public static final String LOSE = "lose"; public static final String PING = "ping"; - public static final Object PONG = "pong"; - public static final Object NOK = "nok"; - public static final Object OK = "ok"; - + public static final String PONG = "pong"; + public static final String NOK = "nok"; + public static final String OK = "ok"; } diff --git a/src/game/ComsJoueur.java b/src/game/ComsJoueur.java index 025e63f..edf522f 100644 --- a/src/game/ComsJoueur.java +++ b/src/game/ComsJoueur.java @@ -8,24 +8,27 @@ import java.net.Socket; public class ComsJoueur { private ObjectOutputStream serverOut; private ObjectInputStream serverIn; + private Socket socket; public ComsJoueur(Socket connection) throws IOException { serverOut = new ObjectOutputStream(connection.getOutputStream()); serverIn = new ObjectInputStream(connection.getInputStream()); + this.socket=connection; } - public void send(Object object) throws IOException + public void send(String message) throws IOException { - serverOut.writeObject(object); + serverOut.writeObject(message); + System.out.println("Sending "+message); } - public Object recieve() + public String recieve() { try { - return serverIn.readObject(); + return (String) serverIn.readObject(); } catch (ClassNotFoundException e) { - System.err.println("ERREUR une classe non trouvé a éte transimise , essayer de n'evoyer que des String au possible"); + System.err.println("ERREUR une classe non trouvé a éte transimise , essayer de n'evoyer que des String"); return ""; } catch (IOException e) { return "time out"; @@ -44,4 +47,13 @@ public class ComsJoueur { serverOut.close(); serverIn.close(); } + + public Socket getSocket() { + return socket; + } + + public void send(int cardId) throws IOException { + send(""+cardId); + + } } diff --git a/src/game/DeckSerializer.java b/src/game/DeckSerializer.java index ceb0cb0..fc17946 100644 --- a/src/game/DeckSerializer.java +++ b/src/game/DeckSerializer.java @@ -5,18 +5,29 @@ import game.deck.Deck; public class DeckSerializer { public static String serializeDeck(Deck d) + { + return forwardSerialisze(d); + + } + + private static String reverseSerialisze(Deck d) { StringBuilder str = new StringBuilder(d.getCards().size()*2); - for(Card c : d.getCards()) + Card[] cardArray = d.getCards().toArray(new Card[0]); + for(int i = cardArray.length -1 ; i >= 0 ; i--) { - str.append(c.toString()+","); + str.append(cardArray[i]+","); } return str.toString(); } - public static Deck deSerializeDeck(String g) + private static String forwardSerialisze(Deck d) { - return null; - + StringBuilder str = new StringBuilder(d.getCards().size()*2); + for(Card c : d.getCards()) + { + str.append(c+","); + } + return str.toString(); } } diff --git a/src/game/Joueur.java b/src/game/Joueur.java index 5a5dd44..0c08981 100644 --- a/src/game/Joueur.java +++ b/src/game/Joueur.java @@ -66,22 +66,24 @@ public class Joueur { //on affiche le debut de tour coms.send(Command.YOURTURN); + System.out.println("NOW WE SHOULDN'T SEND COMMAND"); boolean phaseActive=true; //debut de l'écoude des action client + adversaire.getComs().getSocket().setSoTimeout(Integer.MAX_VALUE); while(phaseActive) { - String command; - command = (String) coms.recieve(); - - System.out.println("GOT COMMAND :"+command); - if(command != null) + coms.getSocket().setSoTimeout(500); + String command = (String) coms.recieve(); + coms.getSocket().setSoTimeout(Integer.MAX_VALUE); + if(command != null && !command.equals("time out")) { + System.out.println("GOT COMMAND :"+command); + switch (command) { case Command.PING: coms.send(Command.PONG); - System.out.println("pong"); break; case Command.PASS_TURN: @@ -89,34 +91,32 @@ public class Joueur { break; case Command.PUT_CARD: + System.out.println("entering put card"); putCard(adversaire,board); break; - case "time out": - System.exit(0); - break; default: - coms.send(Command.POPUP); - coms.send("vous ne pouvez pas faire sa a la premiére phase"); - break; + System.err.println("unknown command "+command); } + } - - //on maintien l'adversaire actif en lui envoyant un ping - adversaire.ping(); } } private void putCard(Joueur adversaire, Board board) throws IOException { - Object info = coms.recieve(); - if(info instanceof String) { - System.err.println((String)info); + //crash here + String info = (String) coms.recieve(); + //si ce n'est pas un nombre + if(!info.matches("-?\\d+")) { + System.err.println(info); }else { - int cardId = (int)info; + int cardId = Integer.parseInt(info); Class cardClass = CardRegistery.get(cardId); + System.out.println(cardClass.getName()); - int zone = (int)coms.recieve(); + + int zone = Integer.parseInt(coms.recieve()); int handIndex = hand.contains(cardClass); if(handIndex == -1)coms.send(Command.NOK); @@ -141,20 +141,6 @@ public class Joueur { coms.send(zone); } - /** - * envoie ping au jour et retourne vrai si le joueur a repondu - * @return - */ - private boolean ping() { - try { - coms.send(Command.PING); - } catch (IOException e) { - return false; - } - return coms.recieve().equals(Command.PONG);//pong - - } - public void mainPhase2() { // TODO Auto-generated method stub diff --git a/src/game/deck/DeckRegistery.java b/src/game/deck/DeckRegistery.java index d958da4..fd53072 100644 --- a/src/game/deck/DeckRegistery.java +++ b/src/game/deck/DeckRegistery.java @@ -3,14 +3,15 @@ package game.deck; public class DeckRegistery { public static Deck get(String name) { - switch (name) { - case "mythes": + switch (name.trim()) { + case "mythes et legendes grecs": return new Mythes(); - case "moyenage": + case "moyen-age francais": return new MoyeneAge(); - case "rennaissance": + case "renaissance": return new Renaissance(); default: + System.out.println(name); return new MoyeneAge(); } }