blob: c07144bc39312fd7daa4815742765b0c7074a492 (
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
|
package jrummikub.control.network;
import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.control.turn.AbstractTurnControl;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
/**
* Turn control for network games
*/
public class NetworkTurnControl extends AbstractTurnControl {
private IConnectionControl connectionControl;
/**
* Creates new network turn control
*
* @param connectionControl
* the current connection control
*/
public NetworkTurnControl(IConnectionControl connectionControl) {
this.connectionControl = connectionControl;
}
@Override
public void doStartTurn() {
connections.add(connectionControl.getTableUpdateEvent().add(
new IListener1<ITable>() {
@Override
public void handle(ITable table) {
view.getTablePanel().setStoneSets(table);
}
}));
connections.add(connectionControl.getTurnEndEvent().add(
new IListener2<IRoundState, InvalidTurnInfo>() {
@Override
public void handle(IRoundState state,
InvalidTurnInfo invalidTurnInfo) {
endOfTurn(state, invalidTurnInfo);
}
}));
connections.add(connectionControl.getRedealEvent().add(new IListener() {
@Override
public void handle() {
redeal();
}
}));
timer.startTimer();
}
private void endOfTurn(IRoundState roundState,
InvalidTurnInfo invalidTurnInfo) {
cleanUp();
endOfTurnEvent.emit(roundState, invalidTurnInfo);
}
private void redeal() {
cleanUp();
redealEvent.emit();
}
@Override
protected void timeOut() {
}
}
|