Revision: 123
http://mud4j.svn.sourceforge.net/mud4j/?rev=123&view=rev
Author: mpurland
Date: 2007-06-02 18:19:38 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
Add implementation for effect behavior to add and undo effects correctly.
Modified Paths:
--------------
trunk/mud4j-core/src/java/net/sf/mud4j/effect/DefaultEffectBehavior.java
Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/DefaultEffectBehavior.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/effect/DefaultEffectBehavior.java 2007-06-03 01:08:51 UTC (rev 122)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/DefaultEffectBehavior.java 2007-06-03 01:19:38 UTC (rev 123)
@@ -16,6 +16,7 @@
package net.sf.mud4j.effect;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -26,7 +27,7 @@
*/
public class DefaultEffectBehavior implements EffectBehavior {
private List<Effect> effectsList = new CopyOnWriteArrayList<Effect>();
-
+
/**
* {@inheritDoc}
*/
@@ -38,20 +39,33 @@
* {@inheritDoc}
*/
public void addEffect(Effect effect) {
+ // Notify the effect to apply itself
+ effect.apply();
+
effectsList.add(effect);
}
/**
* {@inheritDoc}
*/
- public void clear() {
- effectsList.clear();
+ public void removeEffect(Effect effect) {
+ // Notify the effect to remove itself
+ effect.undo();
+
+ effectsList.remove(effect);
}
/**
* {@inheritDoc}
*/
- public void removeEffect(Effect effect) {
- effectsList.remove(effect);
+ public void clear() {
+ // Notify each effect that they are being cleared
+ Iterator<Effect> effectsListIterator = effectsList.iterator();
+
+ while (effectsListIterator.hasNext()) {
+ Effect effect = effectsListIterator.next();
+
+ removeEffect(effect);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|