1 /**
2 * Copyright 2006 Matthew Purland (m.purland@gmail.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.mud4j.damage;
17
18 import java.util.List;
19
20 /**
21 * Abstract implementation for {@link DamageBehavior}.
22 *
23 * @todo Add damage observers
24 *
25 * @author Matthew Purland
26 */
27 public abstract class AbstractDamageBehavior implements DamageBehavior {
28 private List<DamageListener> damageListeners;
29 private boolean isDestroyed;
30
31 /**
32 * {@inheritDoc}
33 */
34 abstract public void damage();
35
36 /**
37 * {@inheritDoc}
38 */
39 public void destroy() {
40 isDestroyed = true;
41
42
43 for (DamageListener listener : damageListeners) {
44 DamageEvent event = new DamageEvent(this);
45 event.setDestroyed(isDestroyed);
46 listener.damageDestroyed(event);
47 }
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public boolean isDestroyed() {
54 return isDestroyed;
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public void removeDamageListener(DamageListener listener) {
61 damageListeners.remove(listener);
62 }
63
64 /**
65 * {@inheritDoc}
66 */
67 public void addDamageListener(DamageListener listener) {
68 damageListeners.add(listener);
69 }
70 }