fixed clear

This commit is contained in:
Johannes Schmelz 2024-10-05 13:13:48 +02:00
parent 4488911e82
commit 35f154aa0f

View File

@ -10,6 +10,7 @@ package pp.battleship.model;
import pp.battleship.notification.GameEvent;
import pp.battleship.notification.GameEventBroker;
import pp.battleship.notification.ItemAddedEvent;
import pp.battleship.notification.ItemRemovedEvent;
import java.util.ArrayList;
import java.util.Collections;
@ -104,7 +105,10 @@ public class ShipMap {
* Removes all items from the map and triggers corresponding removal events for each.
*/
public void clear() {
new ArrayList<>(items).forEach(this::remove);
for (Item item : items) {
items.remove(item);
notifyListeners(new ItemRemovedEvent(item, this));
}
}
/**