ajout de commande serveur - clien
This commit is contained in:
@@ -20,7 +20,14 @@ public class Board {
|
|||||||
return playerCardsOnBoard;
|
return playerCardsOnBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card[] getAdvCardsOnBoard() {
|
public void setCard(int index, Card c)
|
||||||
return advCardsOnBoard;
|
{
|
||||||
|
playerCardsOnBoard[index]=c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnemyCard(int index, Card c)
|
||||||
|
{
|
||||||
|
advCardsOnBoard[index]=c;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CardRegistery {
|
public class CardRegistery {
|
||||||
public static List<Class> registry;
|
public static List<Class<? extends Card>> registry;
|
||||||
|
|
||||||
public CardRegistery()
|
public CardRegistery()
|
||||||
{
|
{
|
||||||
@@ -209,7 +209,9 @@ public class CardRegistery {
|
|||||||
return a != -1 ? a : 0;
|
return a != -1 ? a : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class get(int index) {
|
|
||||||
|
public static Class<? extends Card> get(int index) {
|
||||||
|
if(registry.size() <= index || index < 0) return null;
|
||||||
return registry.get(index);
|
return registry.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public final class Command {
|
|||||||
public static final String DRAW = "draw";
|
public static final String DRAW = "draw";
|
||||||
public static final String GET_DECK = "getDeck";
|
public static final String GET_DECK = "getDeck";
|
||||||
public static final String PUT_CARD = "putCard";
|
public static final String PUT_CARD = "putCard";
|
||||||
|
public static final String PUT_ENEMY_CARD = "enemycard";
|
||||||
public static final String SHUFFLE_DECK = "shuffleDeck";
|
public static final String SHUFFLE_DECK = "shuffleDeck";
|
||||||
public static final String SELECT_CARD = "selectCard";
|
public static final String SELECT_CARD = "selectCard";
|
||||||
public static final String ATTACK = "attack";
|
public static final String ATTACK = "attack";
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.io.IOException;
|
|||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class GameLogicThread extends Thread{
|
public class GameLogicThread extends Thread{
|
||||||
@@ -167,6 +168,22 @@ public class GameLogicThread extends Thread{
|
|||||||
clientOut.writeObject("pong");
|
clientOut.writeObject("pong");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Command.PUT_ENEMY_CARD:
|
||||||
|
int cardId = (int)clientIn.readObject();
|
||||||
|
int zone = (int)clientIn.readObject();
|
||||||
|
|
||||||
|
//on instancie la carte recu
|
||||||
|
Class<? extends Card> c = CardRegistery.get(cardId);
|
||||||
|
Constructor con = c.getConstructor(String.class, Context.class);
|
||||||
|
Card cardPlayed = (Card) con.newInstance("enemy"+zone,gameActivity);
|
||||||
|
|
||||||
|
//ajout de la carte au rendu
|
||||||
|
cardPlayed.getDrawableCard().setCoordinates(((DrawableCard.getCardWith()+1)*zone+DrawableCard.getCardWith()),10F);
|
||||||
|
renderer.addToDraw(cardPlayed.getDrawableCard());
|
||||||
|
|
||||||
|
//ajout la card au terain
|
||||||
|
board.setEnemyCard(zone,cardPlayed);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e("UNKOWN COMMAND",serveurCmd);
|
Log.e("UNKOWN COMMAND",serveurCmd);
|
||||||
}
|
}
|
||||||
@@ -214,9 +231,11 @@ public class GameLogicThread extends Thread{
|
|||||||
throw new UnrecognizedCard();
|
throw new UnrecognizedCard();
|
||||||
}
|
}
|
||||||
clientOut.writeObject(cardId);
|
clientOut.writeObject(cardId);
|
||||||
|
clientOut.writeObject(zone);
|
||||||
|
|
||||||
if(clientIn.readObject().equals(Command.OK))
|
if(clientIn.readObject().equals(Command.OK))
|
||||||
{
|
{
|
||||||
|
board.setCard(zone,card.getCard());
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user