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é
* @return -1 si elle n'est pas trouver
* @return null si elle n'est pas trouver
*/
public int contains(Class<? extends Card> c) {
int index = 0;
public Card contains(Class<? extends Card> c) {
for(Card ca : hand)
{
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() {
+12 -6
View File
@@ -80,7 +80,7 @@ public class Joueur {
while(phaseActive)
{
coms.getSocket().setSoTimeout(500);
String command = (String) coms.recieve();
String command = coms.recieve();
coms.getSocket().setSoTimeout(Integer.MAX_VALUE);
if(command != null && !command.equals("time out"))
{
@@ -124,14 +124,20 @@ public class Joueur {
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 {
if(board.isZoneAvaliable(zone))
{
Card card = hand.remove(handIndex);
board.setCard(zone, card);
hand.remove(handCard);
board.setCard(zone, handCard);
adversaire.enemyPlay(cardId,zone);
coms.send(Command.OK);
}else {