1
2
3
4
5 package spellcast.game;
6
7 import java.io.Serializable;
8
9 import org.apache.commons.lang.builder.EqualsBuilder;
10 import org.apache.commons.lang.builder.HashCodeBuilder;
11 import org.apache.commons.lang.builder.ToStringBuilder;
12
13 /***
14 * A Turn contains a number that indicates what sequence of turns this turn is
15 * as well as a type to indicate the type of the turn. A Turn is a data object
16 * used by spellcast.
17 *
18 * @author Barrie Treloar
19 */
20 public class Turn implements Serializable {
21 public static final Turn AFTER_GAME = new Turn(-2, TurnType.AFTER_GAME);
22
23 public static final Turn BEFORE_GAME = new Turn(-1, TurnType.BEFORE_GAME);
24
25 private static final long serialVersionUID = 1L;
26
27 public Turn(final int theTurnNumber, final TurnType theTurnType) {
28 turnNumber = theTurnNumber;
29 turnType = theTurnType;
30 }
31
32 /***
33 * {@inheritDoc}
34 */
35 @Override
36 public boolean equals(final Object o) {
37 return EqualsBuilder.reflectionEquals(this, o);
38 }
39
40 /***
41 * Return the next turn given the turn type. NORMAL and HASTE turns
42 * increment the turn number but TIMESTOP turns are part of the current turn
43 * number.
44 */
45 public Turn getNextTurn(final TurnType theTurnType) {
46 int nextNumber = turnNumber;
47 if (theTurnType.isNormal() || theTurnType.isHaste()) {
48 nextNumber++;
49 }
50 return new Turn(turnNumber, theTurnType);
51 }
52
53 /***
54 * The value of the turn number.
55 *
56 * @return value of the turn number.
57 */
58 public int getNumber() {
59 return turnNumber;
60 }
61
62 /***
63 * The type of the turn.
64 *
65 * @return the type of the turn.
66 */
67 public TurnType getType() {
68 return turnType;
69 }
70
71 /***
72 * {@inheritDoc}
73 */
74 @Override
75 public int hashCode() {
76 return HashCodeBuilder.reflectionHashCode(this);
77 }
78
79 /***
80 * Indicates whether this turn is a Haste turn.
81 */
82 public boolean isHaste() {
83 return turnType.isHaste();
84 }
85
86 /***
87 * Indicates whether this turn is a Normal turn.
88 */
89 public boolean isNormal() {
90 return turnType.isNormal();
91 }
92
93 /***
94 * Indicates whether this turn is a TimeStop turn.
95 */
96 public boolean isTimeStop() {
97 return turnType.isTimeStop();
98 }
99
100 /***
101 * Set the value of the turn number.
102 *
103 * @param theTurnNumber
104 * Value to assign to turn number.
105 */
106 public void setNumber(final int theTurnNumber) {
107 turnNumber = theTurnNumber;
108 }
109
110 /***
111 * Set the value of the turn type.
112 *
113 * @param theTurnType
114 * Value to assign to the tur ntype.
115 */
116 public void setType(final TurnType theTurnType) {
117 turnType = theTurnType;
118 }
119
120 /***
121 * {@inheritDoc}
122 */
123 @Override
124 public String toString() {
125 return ToStringBuilder.reflectionToString(this);
126 }
127
128 private int turnNumber;
129
130 private TurnType turnType;
131
132 }