Commit a31ecb55 authored by Malo KERVESTIN's avatar Malo KERVESTIN
Browse files

fix bug suppression de l'offre d'echange

parent 82fd2d9f
package game;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import game.Card.Rarity;
......@@ -66,7 +67,7 @@ public class User extends Member {
do {
choice = scanner.nextInt();
chosePosition = deck.get(choice).getPlayer().getPosition();
} while (choice >= deck.size()|| chosePosition != position);
} while (choice >= deck.size() || chosePosition != position);
return deck.get(choice);
}
......@@ -128,18 +129,18 @@ public class User extends Member {
Rarity rarity = Rarity.valueOf(str_rarity.toUpperCase()); // convert String to enum
Pair<String, Rarity> mapValue = new Pair<String, Rarity>(namePlayer, rarity);
if (!Market.getInstance().getExchangeableCards().isEmpty()) {
Market.getInstance().getExchangeableCards().forEach((k, v) -> {
if (k.snd.getPlayer().getName().equals(namePlayer) && k.snd.getRarity().equals(rarity)) {
deck.add(k.snd);
k.fst.getDeck().remove(k.snd);
k.fst.addCard(chosenCard);
for (Pair<User, Card> mapKey : Market.getInstance().getExchangeableCards().keySet()) { // iterate on keys
if (mapKey.snd.getPlayer().getName().equals(namePlayer) && mapKey.snd.getRarity().equals(rarity)) {
deck.add(mapKey.snd);
mapKey.fst.getDeck().remove(mapKey.snd);
mapKey.fst.addCard(chosenCard);
deck.remove(chosenCard);
Market.getInstance().getExchangeableCards().remove(k); // bug
Market.getInstance().getExchangeableCards().remove(mapKey);
} else {
Market.getInstance().getExchangeableCards().put(new Pair<User, Card>(this, chosenCard), mapValue);
System.out.println("Your card is now on exchange");
}
});
}
} else {
Market.getInstance().getExchangeableCards().put(new Pair<User, Card>(this, chosenCard), mapValue);
System.out.println("Your card is now on exchange");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment