summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/turn/ITurnControl.java
blob: 62f9dfb6a9719fda58f5ecbff23baf2cef3eee9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package jrummikub.control.turn;

import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.model.GameSettings;
import jrummikub.model.IHand;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
import jrummikub.view.IView;

/**
 * Interface containing shared methods of human and computer turn control
 * 
 */
public interface ITurnControl {
	/**
	 * Start the turn
	 * 
	 * @param info
	 *            the current turn state
	 * 
	 * @param settings
	 *            the game settings
	 * @param view
	 *            view for user interaction.
	 */
	public void setup(TurnInfo info, GameSettings settings, IView view);

	/**
	 * Get the event that is emitted when the turn is over
	 * 
	 * @return end of turn event
	 */
	public IEvent2<IRoundState, InvalidTurnInfo> getEndOfTurnEvent();

	/**
	 * Emitted when the round is aborted and needs to be restarted
	 * 
	 * @return the event
	 */
	public IEvent getRedealEvent();

	/**
	 * Start the turn
	 */
	public void startTurn();

	/**
	 * Abort the turn
	 */
	public void abortTurn();

	/**
	 * Emitted in network when the table changes during player turn
	 * 
	 * @return the event
	 */
	public IEvent1<ITable> getTableUpdateEvent();

	/**
	 * The TurnInfo class encapsulates all information concerning the current
	 * turn
	 */
	public class TurnInfo {
		private IRoundState roundState;

		private ITable oldTable;
		private IHand oldHand;

		private ITable table;
		private IHand hand;

		private TurnMode turnMode;

		private boolean mayPause;

		/**
		 * Creates a new TurnInfo instance
		 * 
		 * @param roundState
		 *            current round state
		 * @param turnMode
		 *            the turn mode
		 * @param mayPause
		 *            player is allowed to paues
		 */
		public TurnInfo(IRoundState roundState, TurnMode turnMode,
				boolean mayPause) {
			this.roundState = roundState;

			oldTable = roundState.getTable();
			oldHand = roundState.getActivePlayer().getHand();

			this.table = (ITable) oldTable.clone();
			this.hand = (IHand) oldHand.clone();

			this.turnMode = turnMode;

			this.mayPause = mayPause;
		}

		/**
		 * Get the current round state
		 * 
		 * @return the current round state
		 */
		public IRoundState getRoundState() {
			return roundState;
		}

		/**
		 * Gets the table at the beginning of the turn
		 * 
		 * @return the table
		 */
		public ITable getOldTable() {
			return oldTable;
		}

		/**
		 * Gets the current player's hand at the beginning of the turn
		 * 
		 * @return the hand
		 */
		public IHand getOldHand() {
			return oldHand;
		}

		/**
		 * Gets the current table
		 * 
		 * @return the table
		 */
		public ITable getTable() {
			return table;
		}

		/**
		 * Gets the current player's hand
		 * 
		 * @return the hand
		 */
		public IHand getHand() {
			return hand;
		}

		/**
		 * Returns if the current player has laid out yet
		 * 
		 * @return if the player has laid out
		 */
		public boolean getLaidOut() {
			return roundState.getActivePlayer().getLaidOut();
		}

		/**
		 * Gets the current turn's mode
		 * 
		 * @return the turn mode
		 */
		public TurnMode getTurnMode() {
			return turnMode;
		}

		/**
		 * Return whether pausing is allowed during this turn
		 * 
		 * @return true if pause is allowed
		 */
		public boolean isMayPause() {
			return mayPause;
		}
	}
}