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
177
178
179
180
181
182
183
184
185
186
|
package jrummikub.control.network;
import static org.junit.Assert.*;
import java.awt.Color;
import jrummikub.control.turn.AIControl;
import jrummikub.model.GameSettings;
import jrummikub.model.IPlayer;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
import jrummikub.model.Position;
import jrummikub.model.RoundState;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.view.MockView;
import org.junit.Before;
import org.junit.Test;
public class NetworkRoundControlTest {
private MockConnectionControl connectionControl;
private MockView view;
private RoundState testRoundState;
private NetworkRoundControl testRound;
private GameSettings gameSettings;
@Before
public void setup() {
AIControl.useBackgroundThread = false;
gameSettings = new GameSettings();
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW));
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
view = new MockView();
connectionControl = new MockConnectionControl();
}
@Test
public void testHostRound() {
connectionControl.nickname = gameSettings.getPlayerList().get(0).getName();
testRoundState = new RoundState(gameSettings, null);
testRound = new NetworkRoundControl(testRoundState, view,
connectionControl, true);
connectionControl.turnStarted = false;
connectionControl.turnEnded = false;
testRound.startRound();
assertEquals(4, testRoundState.getPlayerCount());
for (int i = 0; i < 4; ++i) {
IPlayer player = testRoundState.getNthPlayer(i);
assertSame(gameSettings.getPlayerList().get(i),
player.getPlayerSettings());
assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand()
.getSize());
}
for (int i = 0; i < 4; ++i) {
IPlayer player = testRoundState.getNthPlayer(i);
while (player.getHand().getSize() > 1) {
Stone stone = player.getHand().iterator().next().getFirst();
player.getHand().pickUp(stone);
}
}
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
view.playerPanel.endTurnEvent.emit();
assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState);
assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable());
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable());
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
}
@Test
public void testClientRound() {
connectionControl.nickname = gameSettings.getPlayerList().get(2).getName();
testRoundState = new RoundState(gameSettings, null);
for (int i = 0; i < 4; ++i) {
IPlayer player = testRoundState.getNthPlayer(i);
player.getHand().drop(new Stone(StoneColor.RED), new Position(0, 0));
}
testRound = new NetworkRoundControl(null, view, connectionControl, false);
connectionControl.turnStarted = false;
connectionControl.turnEnded = false;
testRound.startRound();
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable());
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable());
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
view.playerPanel.endTurnEvent.emit();
assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState);
assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded);
}
}
|