ajout de la gestion de la mana

This commit is contained in:
marc barbier
2020-12-17 10:36:04 +01:00
parent 18b64e929d
commit f86a8e1658
2 changed files with 26 additions and 15 deletions
+14 -9
View File
@@ -34,25 +34,30 @@ public class Hand {
} }
/** /**
* retourne l'index de la carte * retourne la carte si elle est contenu dans la main de la carte
* @param c la classe de la carte cherché * @param c la classe de la carte cherché
* @return -1 si elle n'est pas trouver * @return null si elle n'est pas trouver
*/ */
public int contains(Class<? extends Card> c) { public Card contains(Class<? extends Card> c) {
int index = 0;
for(Card ca : hand) for(Card ca : hand)
{ {
if(ca.getClass().equals(c)) if(ca.getClass().equals(c))
{ {
return index; return ca;
} }
index++;
} }
return -1; return null;
} }
public Card remove(int index) { /**
return hand.remove(index); * retire la carte
* @param c carte a retirer
* @return si la carte a été retirer
*/
public Boolean remove(Card c)
{
return hand.remove(c);
} }
public boolean isFull() { public boolean isFull() {
+11 -5
View File
@@ -80,7 +80,7 @@ public class Joueur {
while(phaseActive) while(phaseActive)
{ {
coms.getSocket().setSoTimeout(500); coms.getSocket().setSoTimeout(500);
String command = (String) coms.recieve(); String command = coms.recieve();
coms.getSocket().setSoTimeout(Integer.MAX_VALUE); coms.getSocket().setSoTimeout(Integer.MAX_VALUE);
if(command != null && !command.equals("time out")) if(command != null && !command.equals("time out"))
{ {
@@ -125,13 +125,19 @@ public class Joueur {
int zone = Integer.parseInt(coms.recieve()); int zone = Integer.parseInt(coms.recieve());
int handIndex = hand.contains(cardClass);
if(handIndex == -1)coms.send(Command.NOK); Card handCard = hand.contains(cardClass);
//si la carte n'est pas trouve ou si elle coute trop cher
if(handCard == null || mana < handCard.getCost()){
//on refuse le placement
coms.send(Command.NOK);
}
else { else {
if(board.isZoneAvaliable(zone)) if(board.isZoneAvaliable(zone))
{ {
Card card = hand.remove(handIndex); hand.remove(handCard);
board.setCard(zone, card); board.setCard(zone, handCard);
adversaire.enemyPlay(cardId,zone); adversaire.enemyPlay(cardId,zone);
coms.send(Command.OK); coms.send(Command.OK);
}else { }else {