1
2
3
4 package spellcast.beings;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import org.apache.log4j.Logger;
10
11 import spellcast.gestures.Gesture;
12 import spellcast.model.Id;
13 import spellcast.questions.IQuestion;
14 import util.Nullable;
15
16 /***
17 * A <code>Wizard</code> of Spellcast.
18 *
19 * @author Barrie Treloar
20 * @version $Revision: 1.1 $
21 */
22 public class Wizard extends Being implements Nullable, IWizard {
23 /***
24 * serialVersionUID.
25 */
26 private static final long serialVersionUID = 1L;
27
28 /*** Maximum hitpoints for a <code>Wizard</code>. */
29 private static final int MAX_HITPOINTS = 20;
30
31 /*** Logger. */
32 private static Logger logger = Logger.getLogger("beings");
33
34 /*** The left hand <code>Gestures</code>. */
35 private Gesture[] leftHandGestures = new Gesture[10];
36
37 /*** The right hand <code>Gestures</code>.*/
38 private Gesture[] rightHandGestures = new Gesture[10];
39
40 /*** Indicates whether the <code>Wizard</code> has surrendered. */
41 private boolean surrendered;
42
43 /*** The left hand <code>Gesture</code>. */
44 private Gesture leftHandGesture;
45
46 /*** The right hand <code>Gesture</code> */
47 private Gesture rightHandGesture;
48
49 /*** Indictes whether the <code>Wizard</code> has completed the current turns move and is ready. */
50 private boolean ready;
51
52 /*** The <code>IQuestion</code>s to ask the Wizard this turn.*/
53 private List<IQuestion> questions = new ArrayList<IQuestion>();
54
55 /***
56 * Provided for serialization, do not use as a constructor.
57 */
58 protected Wizard() {
59 }
60
61 /***
62 * Creates a new Wizard object.
63 *
64 * @param id DOCUMENT ME!
65 * @param name DOCUMENT ME!
66 * @param gender DOCUMENT ME!
67 */
68 public Wizard(Id id, String name, Gender gender) {
69 super(id, name, gender, MAX_HITPOINTS);
70 }
71
72 /***
73 * Create a view of the original wizard that the gestures of the original
74 * wizard are correctly hidden.
75 *
76 * @param original DOCUMENT ME!
77 */
78 public Wizard(Wizard original) {
79 this(original.getId(), original.getName(), original.getGender());
80 leftHandGestures = new Gesture[original.leftHandGestures.length];
81
82 for (int i = 0; i < leftHandGestures.length; i++) {
83 if (original.leftHandGestures[i] != null) {
84 if (original.leftHandGestures[i].isUnclear()) {
85 leftHandGestures[i] = Gesture.UNCLEAR;
86 } else {
87 leftHandGestures[i] = original.leftHandGestures[i];
88 }
89 }
90 }
91
92 rightHandGestures = new Gesture[original.rightHandGestures.length];
93
94 for (int i = 0; i < rightHandGestures.length; i++) {
95 if (original.rightHandGestures[i] != null) {
96 if (original.rightHandGestures[i].isUnclear()) {
97 rightHandGestures[i] = Gesture.UNCLEAR;
98 } else {
99 rightHandGestures[i] = original.rightHandGestures[i];
100 }
101 }
102 }
103
104 surrendered = original.surrendered;
105 leftHandGesture = Gesture.UNCLEAR;
106 rightHandGesture = Gesture.UNCLEAR;
107 ready = original.ready;
108 }
109
110 /***
111 * {@inheritDoc}
112 */
113 public final boolean isReady() {
114 return ready;
115 }
116
117 /***
118 * {@inheritDoc}
119 */
120 public final void setReady(boolean isReady) {
121 ready = isReady;
122 }
123
124 /***
125 * {@inheritDoc}
126 */
127 public final Gesture getLeftHandGesture() {
128 return leftHandGesture;
129 }
130
131 /***
132 * {@inheritDoc}
133 */
134 public final void setLeftHandGesture(Gesture theGesture) {
135 leftHandGesture = theGesture;
136 }
137
138 /***
139 * {@inheritDoc}
140 */
141 public final Gesture getRightHandGesture() {
142 return rightHandGesture;
143 }
144
145 /***
146 * {@inheritDoc}
147 */
148 public void setRightHandGesture(Gesture theGesture) {
149 rightHandGesture = theGesture;
150 }
151
152 /***
153 * {@inheritDoc}
154 */
155 public void addQuestion(IQuestion theQuestionToAsk) {
156 questions.add(theQuestionToAsk);
157 }
158
159 /***
160 * {@inheritDoc}
161 */
162 public final String toString() {
163 return getName() + " [" + getId() + "]";
164 }
165
166 /***
167 * Return a Null <code>Wizard</code>.
168 *
169 * @return an instance of the Null <code>Wizard</code>.
170 */
171 public static Wizard newNull() {
172 return new NullWizard();
173 }
174 }