ババ抜きのゲームを作っています。
以下のコードはカードを配り終わった後、
2組になったカードを捨てるコードです。
しかし捨てたらループが
java.util.ConcurrentModificationException
エラーになります。
解決法を教えてください。
java
1package maingame; 2 3import java.util.Map.Entry; 4 5public class Judge { 6 public void judge(Player player) { 7 8 for (Entry<String, Integer> el : player.handCard.entrySet()) { 9 for (Entry<String, Integer> ele : player.handCard.entrySet()) { 10 if (el.getValue().equals(ele.getValue())) { 11 if (!(el.equals(ele))) { 12 player.handCard.remove(el.getKey()); 13 player.handCard.remove(ele.getKey()); 14 } 15 } 16 } 17 } 18 for (Entry<String, Integer> el : player.handCard.entrySet()) { 19 System.out.print("[" + el.getKey() + "]"); 20 } 21 22 } 23} 24
ちなみにカードは以下のように作っています。
java
1 2 Map<String, Integer> CardList = new HashMap<>(); 3 4 public void makeCard() { 5 CardList.put("JOKER", 0); 6 for (int j = 1; j <= 13; j++) { 7 CardList.put("s" + j, j); 8 CardList.put("c" + j, j); 9 CardList.put("h" + j, j); 10 CardList.put("d" + j, j); 11 } 12 13 }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。