fix effet de carte mal atribué + changement le fight back ne nessecite plus la survie de la victime + patch but d'actualisation de carte + ajout de details aux logs
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.
@@ -9,6 +9,7 @@ public class ComsJoueur {
|
||||
private ObjectOutputStream serverOut;
|
||||
private ObjectInputStream serverIn;
|
||||
private Socket socket;
|
||||
private String name=null;
|
||||
|
||||
public ComsJoueur(Socket connection) throws IOException
|
||||
{
|
||||
@@ -27,7 +28,10 @@ public class ComsJoueur {
|
||||
public void send(String message) throws IOException
|
||||
{
|
||||
serverOut.writeObject(message);
|
||||
System.out.println("Sending "+message);
|
||||
if(name == null)
|
||||
System.out.println("Sending "+message);
|
||||
else
|
||||
System.out.println("Sending "+message+" to "+name);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +44,10 @@ public class ComsJoueur {
|
||||
{
|
||||
try {
|
||||
String message = (String) serverIn.readObject();
|
||||
if(name == null)
|
||||
System.out.println("Sending "+message);
|
||||
else
|
||||
System.out.println("Sending "+message+" to "+name);
|
||||
return message;
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("ERREUR une classe non trouvé a éte transimise , essayer de n'evoyer que des String");
|
||||
@@ -76,4 +84,8 @@ public class ComsJoueur {
|
||||
send(""+message);
|
||||
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name=name;
|
||||
}
|
||||
}
|
||||
|
||||
+78
-92
@@ -16,6 +16,8 @@ import game.deck.Deck;
|
||||
import game.deck.DeckRegistery;
|
||||
|
||||
public class Joueur {
|
||||
//utile pour les logs
|
||||
private String name;
|
||||
private ComsJoueur coms;
|
||||
private Deck deck;
|
||||
private Hand hand;
|
||||
@@ -26,15 +28,18 @@ public class Joueur {
|
||||
// la mana actuele du joueur
|
||||
private int mana;
|
||||
|
||||
public Joueur(ComsJoueur connectionJoueur) {
|
||||
public Joueur(ComsJoueur connectionJoueur,String name) {
|
||||
this.name=name;
|
||||
coms = connectionJoueur;
|
||||
pV = 20;
|
||||
this.board = new Board();
|
||||
}
|
||||
|
||||
/**
|
||||
* cette fonction permet d'obtenir le deck du joueur et de préparer la main
|
||||
* /!\\ l'appele de cette fonction doit être protegé par la verification de la tille du deck
|
||||
* cette fonction permet d'obtenir le deck du joueur et de préparer la main /!\\
|
||||
* l'appele de cette fonction doit être protegé par la verification de la tille
|
||||
* du deck
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void requestDataEarlyGameData() throws IOException {
|
||||
@@ -43,6 +48,7 @@ public class Joueur {
|
||||
deck = DeckRegistery.get(deckname);
|
||||
deck.shuffle();
|
||||
hand = new Hand(deck);
|
||||
coms.setName(name);
|
||||
coms.send(DeckSerializer.serializeDeck(deck));
|
||||
draw(5);
|
||||
coms.send(Command.SET_HP);
|
||||
@@ -53,8 +59,9 @@ public class Joueur {
|
||||
}
|
||||
|
||||
/**
|
||||
* cette fonction permet de pioche une quantité donné
|
||||
* /!\\ l'appele de cette fonction doit être protegé par la verification de la tille du deck
|
||||
* cette fonction permet de pioche une quantité donné /!\\ l'appele de cette
|
||||
* fonction doit être protegé par la verification de la tille du deck
|
||||
*
|
||||
* @param amount la quantié
|
||||
* @throws IOException
|
||||
*/
|
||||
@@ -126,7 +133,7 @@ public class Joueur {
|
||||
coms.getSocket().setSoTimeout(Integer.MAX_VALUE);
|
||||
if (command != null && !command.equals("time out")) {
|
||||
alive = 0;
|
||||
System.out.println("GOT COMMAND :" + command);
|
||||
System.out.println("\rGOT COMMAND :" + command);
|
||||
|
||||
switch (command) {
|
||||
|
||||
@@ -176,7 +183,7 @@ public class Joueur {
|
||||
int cardId = Integer.parseInt(info);
|
||||
|
||||
Class<? extends Card> cardClass = CardRegistery.get(cardId);
|
||||
System.out.println("searching :"+cardClass.getSimpleName());
|
||||
System.out.println("searching :" + cardClass.getSimpleName());
|
||||
|
||||
int zone = Integer.parseInt(coms.recieve());
|
||||
|
||||
@@ -239,13 +246,12 @@ public class Joueur {
|
||||
*/
|
||||
public void endPhase() {
|
||||
Iterator<Card> it = board.getIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Card c = it.next();
|
||||
if (c != null) {
|
||||
c.resetAttack();
|
||||
}
|
||||
}
|
||||
while (it.hasNext()) {
|
||||
Card c = it.next();
|
||||
if (c != null) {
|
||||
c.resetAttack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ComsJoueur getComs() {
|
||||
@@ -314,7 +320,7 @@ public class Joueur {
|
||||
String command = coms.recieve();
|
||||
coms.getSocket().setSoTimeout(Integer.MAX_VALUE);
|
||||
if (command != null && !command.equals("time out")) {
|
||||
System.out.println("GOT COMMAND :" + command);
|
||||
System.out.println("\rGOT COMMAND :" + command);
|
||||
|
||||
switch (command) {
|
||||
|
||||
@@ -336,23 +342,21 @@ public class Joueur {
|
||||
|
||||
Card attackingCard = board.getCardInZone(Integer.parseInt(carteAttaquante));
|
||||
|
||||
|
||||
if (attackingCard == null) {
|
||||
throw new RuntimeException("invalid attack");
|
||||
} else {
|
||||
if (carteCible.contains("100")) {
|
||||
if(!attackingCard.hasAlreadyAttacked())
|
||||
{
|
||||
if (!attackingCard.hasAlreadyAttacked()) {
|
||||
boolean isadvDead = handleAttackAgainstPlayer(attackingCard, adversaire);
|
||||
if(isadvDead)
|
||||
{
|
||||
if (isadvDead) {
|
||||
phaseActive = false;
|
||||
}
|
||||
attackingCard.hasAttacked();
|
||||
}
|
||||
} else {
|
||||
Card attackedCard = adversaire.getBoard().getCardInZone(Integer.parseInt(carteCible));
|
||||
if (!attackingCard.hasAlreadyAttacked() && !(attackedCard instanceof IInvisible) && !(attackingCard instanceof IPlayerFocused)) {
|
||||
if (!attackingCard.hasAlreadyAttacked() && !(attackedCard instanceof IInvisible)
|
||||
&& !(attackingCard instanceof IPlayerFocused)) {
|
||||
handleAttackAgainstCard(carteAttaquante, carteCible, adversaire);
|
||||
attackingCard.hasAttacked();
|
||||
}
|
||||
@@ -369,20 +373,17 @@ public class Joueur {
|
||||
}
|
||||
|
||||
private boolean handleAttackAgainstPlayer(Card attackingCard, Joueur adversaire) throws IOException {
|
||||
int damage = attackingCard.getAttack();
|
||||
if(attackingCard instanceof IAntiPlayer)
|
||||
{
|
||||
int damage = attackingCard.getAttack();
|
||||
if (attackingCard instanceof IAntiPlayer) {
|
||||
damage *= 2;
|
||||
}
|
||||
|
||||
if(attackingCard instanceof IShortRange)
|
||||
{
|
||||
if (attackingCard instanceof IShortRange) {
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
boolean result = adversaire.takeDamage(damage);
|
||||
if(!result)
|
||||
{
|
||||
if (!result) {
|
||||
adversaire.updateHp(this);
|
||||
return false;
|
||||
}
|
||||
@@ -397,61 +398,48 @@ public class Joueur {
|
||||
|
||||
}
|
||||
|
||||
private void handleAttackAgainstCard(String carteAttaquante, String carteCible, Joueur adversaire) throws IOException {
|
||||
private void handleAttackAgainstCard(String carteAttaquante, String carteCible, Joueur adversaire)
|
||||
throws IOException {
|
||||
Card attackedCard = adversaire.getBoard().getCardInZone(Integer.parseInt(carteCible));
|
||||
Card attackingCard = board.getCardInZone(Integer.parseInt(carteAttaquante));
|
||||
|
||||
|
||||
if (attackedCard == null) {
|
||||
throw new RuntimeException(
|
||||
"error invalid carteCible:" + carteCible + " carteAttaquante : " + attackingCard);
|
||||
}
|
||||
|
||||
boolean isDestroyed = attackedCard.takeDamage(attackingCard.getAttack());
|
||||
if(attackingCard instanceof ILifeSteal)
|
||||
{
|
||||
if (attackingCard instanceof ILifeSteal) {
|
||||
attackingCard.heal(attackingCard.getAttack());
|
||||
|
||||
updateCardHp(attackingCard, this);
|
||||
}
|
||||
|
||||
if (isDestroyed || attackingCard instanceof IToxic) {
|
||||
adversaire.destroyCard(carteCible,this);
|
||||
}else {
|
||||
adversaire.updateCardHp(attackedCard, this);
|
||||
adversaire.destroyCard(carteCible, this);
|
||||
}
|
||||
|
||||
//cette partie est le fightback C.A.D quand tu attaque une carte si elle survit elle te frape a son tour
|
||||
if(attackedCard.getAttack() > 0 && !(attackingCard instanceof ICanDoge))
|
||||
{
|
||||
isDestroyed = attackingCard.takeDamage(attackedCard.getAttack());
|
||||
if(isDestroyed)
|
||||
{
|
||||
// on suprime la carte du terrain
|
||||
board.setCard(Integer.parseInt(carteAttaquante), null);
|
||||
|
||||
// demande a l'adversaire de retirer la carte de son terrain
|
||||
adversaire.getComs().send(Command.DESTROY_ADV_CARD);
|
||||
adversaire.getComs().send(carteAttaquante);
|
||||
|
||||
// retire la carte au terrain adverse
|
||||
this.getComs().send(Command.DESTROY_CARD);
|
||||
this.getComs().send(carteAttaquante);
|
||||
|
||||
// appelle les effet de quand la carte est détruite
|
||||
// NOTE : non implémenter dans les cartes individuelles par manque de temps
|
||||
attackingCard.onCardDestroyed();
|
||||
}else {
|
||||
adversaire.updateCardHp(attackingCard, this);
|
||||
}
|
||||
adversaire.updateCardHp(attackedCard, this);
|
||||
|
||||
// cette partie est le fightback C.A.D quand tu attaque une carte si elle survit
|
||||
// elle te frape a son tour
|
||||
System.out.println(attackedCard.getAttack() + " " + !(attackingCard instanceof ICanDoge));
|
||||
if (attackedCard.getAttack() > 0 && !(attackingCard instanceof ICanDoge)) {
|
||||
System.out.println("Fight back started");
|
||||
isDestroyed = attackingCard.takeDamage(attackedCard.getAttack());
|
||||
if (isDestroyed || attackedCard instanceof IToxic) {
|
||||
System.out.println("destroying");
|
||||
this.destroyCard(carteAttaquante, adversaire);
|
||||
} else {
|
||||
System.out.println("the card took" + attackedCard.getAttack());
|
||||
updateCardHp(attackedCard, adversaire);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void destroyCard(String carteCible,Joueur adversaire) throws IOException
|
||||
{
|
||||
private void destroyCard(String carteCible, Joueur adversaire) throws IOException {
|
||||
Card attackedCard = getBoard().getCardInZone(Integer.parseInt(carteCible));
|
||||
|
||||
board.setCard(Integer.parseInt(carteCible), null);
|
||||
@@ -469,42 +457,46 @@ public class Joueur {
|
||||
attackedCard.onCardDestroyed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* met a jorus les hp d'une carte tout ce passe du poin de vue du joueur
|
||||
*
|
||||
* @param cardToUpDate
|
||||
* @param adversaire
|
||||
* @throws IOException
|
||||
*/
|
||||
private void updateCardHp(Card cardToUpDate,Joueur adversaire) throws IOException
|
||||
{
|
||||
int zone = board.getZoneOf(cardToUpDate);
|
||||
if(zone == -1)return;
|
||||
private void updateCardHp(Card cardToUpDate, Joueur adversaire) throws IOException {
|
||||
int zone = board.getZoneOf(cardToUpDate);
|
||||
if (zone == -1)
|
||||
return;
|
||||
adversaire.getComs().send(Command.SET_ADV_CARD_HP);
|
||||
adversaire.getComs().send(zone+"");
|
||||
adversaire.getComs().send(zone + "");
|
||||
adversaire.getComs().send(cardToUpDate.getHealth());
|
||||
|
||||
this.getComs().send(Command.SET_CARD_HP);
|
||||
this.getComs().send(zone+"");
|
||||
this.getComs().send(zone + "");
|
||||
this.getComs().send(cardToUpDate.getHealth());
|
||||
}
|
||||
|
||||
/**
|
||||
* met a jorus les dmg d'une carte tout ce passe du poin de vue du joueur
|
||||
*
|
||||
* @param cardToUpDate
|
||||
* @param adversaire
|
||||
* @throws IOException
|
||||
*/
|
||||
private void updateCardAtk(Card cardToUpDate,Joueur adversaire) throws IOException
|
||||
{
|
||||
int zone = board.getZoneOf(cardToUpDate);
|
||||
if(zone == -1)return;
|
||||
private void updateCardAtk(Card cardToUpDate, Joueur adversaire) throws IOException {
|
||||
int zone = board.getZoneOf(cardToUpDate);
|
||||
if (zone == -1)
|
||||
return;
|
||||
|
||||
System.out.println("updating card "+cardToUpDate+" of "+name);
|
||||
|
||||
adversaire.getComs().send(Command.SET_ADV_CARD_ATK);
|
||||
adversaire.getComs().send(zone+"");
|
||||
adversaire.getComs().send(zone + "");
|
||||
adversaire.getComs().send(cardToUpDate.getAttack());
|
||||
|
||||
this.getComs().send(Command.SET_CARD_ATK);
|
||||
this.getComs().send(zone+"");
|
||||
this.getComs().send(zone + "");
|
||||
this.getComs().send(cardToUpDate.getAttack());
|
||||
}
|
||||
|
||||
@@ -514,11 +506,11 @@ public class Joueur {
|
||||
|
||||
/**
|
||||
* inflige des degats au joueur
|
||||
*
|
||||
* @param amount
|
||||
* @return true si les pv du joueur on attein zero
|
||||
*/
|
||||
public boolean takeDamage(int amount)
|
||||
{
|
||||
public boolean takeDamage(int amount) {
|
||||
pV -= amount;
|
||||
pV = pV > 0 ? pV : 0;
|
||||
return pV == 0;
|
||||
@@ -528,18 +520,15 @@ public class Joueur {
|
||||
public void onTurnStart(Joueur adversaire) throws IOException {
|
||||
int index = 0;
|
||||
Iterator<Card> it = board.getIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
while (it.hasNext()) {
|
||||
Card c = it.next();
|
||||
if(c != null)
|
||||
{
|
||||
if (c != null) {
|
||||
c.onTurnStart();
|
||||
if(!(c.getHealth() == 0))
|
||||
{
|
||||
if (!(c.getHealth() == 0)) {
|
||||
updateCardHp(c, adversaire);
|
||||
updateCardAtk(c, adversaire);
|
||||
}else {
|
||||
destroyCard(index+"", adversaire);
|
||||
} else {
|
||||
destroyCard(index + "", adversaire);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -551,17 +540,14 @@ public class Joueur {
|
||||
public void refreshAllCard(Joueur adversaire) throws IOException {
|
||||
int index = 0;
|
||||
Iterator<Card> it = board.getIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
while (it.hasNext()) {
|
||||
Card c = it.next();
|
||||
if(c != null)
|
||||
{
|
||||
if(!(c.getHealth() == 0))
|
||||
{
|
||||
if (c != null) {
|
||||
if (!(c.getHealth() == 0)) {
|
||||
updateCardHp(c, adversaire);
|
||||
updateCardAtk(c, adversaire);
|
||||
}else {
|
||||
destroyCard(index+"", adversaire);
|
||||
} else {
|
||||
destroyCard(index + "", adversaire);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -12,11 +12,11 @@ public class Match extends Thread {
|
||||
// random j2/j1
|
||||
rand = new Random();
|
||||
if (rand.nextBoolean()) {
|
||||
joueur1 = new Joueur(joueur1Com);
|
||||
joueur2 = new Joueur(joueur2Com);
|
||||
joueur1 = new Joueur(joueur1Com,"j1");
|
||||
joueur2 = new Joueur(joueur2Com,"j2");
|
||||
} else {
|
||||
joueur1 = new Joueur(joueur2Com);
|
||||
joueur2 = new Joueur(joueur1Com);
|
||||
joueur1 = new Joueur(joueur2Com,"j1");
|
||||
joueur2 = new Joueur(joueur1Com,"j2");
|
||||
}
|
||||
|
||||
joueur1.requestDataEarlyGameData();
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class Card{
|
||||
}else {
|
||||
health -= amountOfHpToLose;
|
||||
}
|
||||
return health == 0;
|
||||
return health <= 0;
|
||||
}
|
||||
|
||||
public boolean hasAlreadyAttacked() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package game.cards.MoyenAge;
|
||||
|
||||
import game.cards.SpecialCard.HealthBufCard;
|
||||
import game.cards.SpecialCard.StrongifyBufCard;
|
||||
|
||||
public class Moyen_Age_Louis extends HealthBufCard{
|
||||
public class Moyen_Age_Louis extends StrongifyBufCard{
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class StrongifyBufCard extends BufCard{
|
||||
Card card = it.next();
|
||||
if(card != null)
|
||||
{
|
||||
card.heal(1);
|
||||
card.makeStronger(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user