patch crash + phase 1
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -59,6 +59,10 @@ public class Serveur {
|
|||||||
if (PlayerTesteur.playerTest(joueur2Com)) {
|
if (PlayerTesteur.playerTest(joueur2Com)) {
|
||||||
new Match(joueur1Com,joueur2Com);
|
new Match(joueur1Com,joueur2Com);
|
||||||
System.out.println("match lancé");
|
System.out.println("match lancé");
|
||||||
|
joueur2EnAttente = null;
|
||||||
|
joueur2Com=null;
|
||||||
|
joueur1EnAttente = null;
|
||||||
|
joueur1Com=null;
|
||||||
} else {
|
} else {
|
||||||
// le joueur est cassé donc on le retire de la file d'attente
|
// le joueur est cassé donc on le retire de la file d'attente
|
||||||
System.out.println("j2 invalid");
|
System.out.println("j2 invalid");
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ public final class Command {
|
|||||||
public static final String WIN = "win";
|
public static final String WIN = "win";
|
||||||
public static final String LOSE = "lose";
|
public static final String LOSE = "lose";
|
||||||
public static final String PING = "ping";
|
public static final String PING = "ping";
|
||||||
public static final Object PONG = "pong";
|
public static final String PONG = "pong";
|
||||||
public static final Object NOK = "nok";
|
public static final String NOK = "nok";
|
||||||
public static final Object OK = "ok";
|
public static final String OK = "ok";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,24 +8,27 @@ import java.net.Socket;
|
|||||||
public class ComsJoueur {
|
public class ComsJoueur {
|
||||||
private ObjectOutputStream serverOut;
|
private ObjectOutputStream serverOut;
|
||||||
private ObjectInputStream serverIn;
|
private ObjectInputStream serverIn;
|
||||||
|
private Socket socket;
|
||||||
|
|
||||||
public ComsJoueur(Socket connection) throws IOException
|
public ComsJoueur(Socket connection) throws IOException
|
||||||
{
|
{
|
||||||
serverOut = new ObjectOutputStream(connection.getOutputStream());
|
serverOut = new ObjectOutputStream(connection.getOutputStream());
|
||||||
serverIn = new ObjectInputStream(connection.getInputStream());
|
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 {
|
try {
|
||||||
return serverIn.readObject();
|
return (String) serverIn.readObject();
|
||||||
} catch (ClassNotFoundException e) {
|
} 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 "";
|
return "";
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return "time out";
|
return "time out";
|
||||||
@@ -44,4 +47,13 @@ public class ComsJoueur {
|
|||||||
serverOut.close();
|
serverOut.close();
|
||||||
serverIn.close();
|
serverIn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Socket getSocket() {
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(int cardId) throws IOException {
|
||||||
|
send(""+cardId);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,29 @@ import game.deck.Deck;
|
|||||||
|
|
||||||
public class DeckSerializer {
|
public class DeckSerializer {
|
||||||
public static String serializeDeck(Deck d)
|
public static String serializeDeck(Deck d)
|
||||||
|
{
|
||||||
|
return forwardSerialisze(d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String reverseSerialisze(Deck d)
|
||||||
{
|
{
|
||||||
StringBuilder str = new StringBuilder(d.getCards().size()*2);
|
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();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-34
@@ -66,22 +66,24 @@ public class Joueur {
|
|||||||
|
|
||||||
//on affiche le debut de tour
|
//on affiche le debut de tour
|
||||||
coms.send(Command.YOURTURN);
|
coms.send(Command.YOURTURN);
|
||||||
|
System.out.println("NOW WE SHOULDN'T SEND COMMAND");
|
||||||
|
|
||||||
boolean phaseActive=true;
|
boolean phaseActive=true;
|
||||||
//debut de l'écoude des action client
|
//debut de l'écoude des action client
|
||||||
|
adversaire.getComs().getSocket().setSoTimeout(Integer.MAX_VALUE);
|
||||||
while(phaseActive)
|
while(phaseActive)
|
||||||
{
|
{
|
||||||
String command;
|
coms.getSocket().setSoTimeout(500);
|
||||||
command = (String) coms.recieve();
|
String command = (String) coms.recieve();
|
||||||
|
coms.getSocket().setSoTimeout(Integer.MAX_VALUE);
|
||||||
System.out.println("GOT COMMAND :"+command);
|
if(command != null && !command.equals("time out"))
|
||||||
if(command != null)
|
|
||||||
{
|
{
|
||||||
|
System.out.println("GOT COMMAND :"+command);
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
|
|
||||||
case Command.PING:
|
case Command.PING:
|
||||||
coms.send(Command.PONG);
|
coms.send(Command.PONG);
|
||||||
System.out.println("pong");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command.PASS_TURN:
|
case Command.PASS_TURN:
|
||||||
@@ -89,34 +91,32 @@ public class Joueur {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Command.PUT_CARD:
|
case Command.PUT_CARD:
|
||||||
|
System.out.println("entering put card");
|
||||||
putCard(adversaire,board);
|
putCard(adversaire,board);
|
||||||
break;
|
break;
|
||||||
case "time out":
|
|
||||||
System.exit(0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
coms.send(Command.POPUP);
|
System.err.println("unknown command "+command);
|
||||||
coms.send("vous ne pouvez pas faire sa a la premiére phase");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//on maintien l'adversaire actif en lui envoyant un ping
|
|
||||||
adversaire.ping();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putCard(Joueur adversaire, Board board) throws IOException {
|
private void putCard(Joueur adversaire, Board board) throws IOException {
|
||||||
Object info = coms.recieve();
|
//crash here
|
||||||
if(info instanceof String) {
|
String info = (String) coms.recieve();
|
||||||
System.err.println((String)info);
|
//si ce n'est pas un nombre
|
||||||
|
if(!info.matches("-?\\d+")) {
|
||||||
|
System.err.println(info);
|
||||||
}else {
|
}else {
|
||||||
int cardId = (int)info;
|
int cardId = Integer.parseInt(info);
|
||||||
|
|
||||||
Class<? extends Card> cardClass = CardRegistery.get(cardId);
|
Class<? extends Card> 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);
|
int handIndex = hand.contains(cardClass);
|
||||||
if(handIndex == -1)coms.send(Command.NOK);
|
if(handIndex == -1)coms.send(Command.NOK);
|
||||||
@@ -141,20 +141,6 @@ public class Joueur {
|
|||||||
coms.send(zone);
|
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() {
|
public void mainPhase2() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package game.deck;
|
|||||||
public class DeckRegistery {
|
public class DeckRegistery {
|
||||||
public static Deck get(String name)
|
public static Deck get(String name)
|
||||||
{
|
{
|
||||||
switch (name) {
|
switch (name.trim()) {
|
||||||
case "mythes":
|
case "mythes et legendes grecs":
|
||||||
return new Mythes();
|
return new Mythes();
|
||||||
case "moyenage":
|
case "moyen-age francais":
|
||||||
return new MoyeneAge();
|
return new MoyeneAge();
|
||||||
case "rennaissance":
|
case "renaissance":
|
||||||
return new Renaissance();
|
return new Renaissance();
|
||||||
default:
|
default:
|
||||||
|
System.out.println(name);
|
||||||
return new MoyeneAge();
|
return new MoyeneAge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user