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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
package jrummikub;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.UIManager;
import jrummikub.control.ITurnTimer;
import jrummikub.control.TurnTimer;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
import jrummikub.view.IView;
public class JRummikub {
/**
* @param args
*/
public static void main(String[] args) {
String nativeLF = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(nativeLF);
} catch (Exception e) {
}
final IView view = new jrummikub.view.impl.View();
view.setCurrentPlayerName("Player 1");
ITurnTimer testTimer = new TurnTimer(view);
testTimer.startTimer();
view.getTablePanel().setLeftPlayerName("Player 2");
view.getTablePanel().setTopPlayerName("Player 3");
view.getTablePanel().setRightPlayerName("Player 4");
view.getPlayerPanel().getSortByGroupsEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'Sort by groups' fired");
}
});
view.getPlayerPanel().getSortByRunsEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'Sort by runs' fired");
}
});
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'End turn' fired");
view.enableStartTurnPanel(true);
}
});
view.getStartTurnEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'Start turn' fired");
view.enableStartTurnPanel(false);
}
});
// stones on the board
Map<Stone, Position> stones = new HashMap<Stone, Position>();
stones.put(new Stone(1, StoneColor.ORANGE), new Position(0, 0));
stones.put(new Stone(10, StoneColor.BLUE), new Position(1, 0));
stones.put(new Stone(9, StoneColor.RED), new Position(0.5f, 1));
stones.put(new Stone(7, StoneColor.BLACK), new Position(1.75f, 1));
Stone stoneJoker = new Stone(StoneColor.RED);
stones.put(stoneJoker, new Position(2.5f, 0));
stones.put(new Stone(StoneColor.BLACK), new Position(3.5f, 0));
view.getPlayerPanel().getHandPanel().setStones(stones);
view.getPlayerPanel().getHandPanel().getClickEvent()
.add(new IListener1<Position>() {
@Override
public void handle(Position p) {
System.out.println("Hand clicked at " + p);
}
});
view.getPlayerPanel().getHandPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getHandPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getHandPanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand set-clicked at " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getClickEvent().add(new IListener1<Position>() {
@Override
public void handle(Position p) {
System.out.println("Table clicked at " + p);
}
});
view.getTablePanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table set-clicked at " + s
+ (collect ? ", collect" : ""));
view.enableWinPanel(true);
}
});
view.getTablePanel().getLeftConnectorClickEvent()
.add(new IListener1<StoneSet>() {
@Override
public void handle(StoneSet s) {
System.out.println("Left connector clicked on " + s);
}
});
view.getTablePanel().getRightConnectorClickEvent()
.add(new IListener1<StoneSet>() {
@Override
public void handle(StoneSet s) {
System.out.println("Right connector clicked on " + s);
}
});
view.getTablePanel().getStoneCollectionPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getStoneCollectionPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getStoneCollectionPanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection set-clicked at " + s
+ (collect ? ", collect" : ""));
}
});
// stoneSets on the table
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE)),
new Position(0.5f, 1));
List<Stone> stoneList = new ArrayList<Stone>();
stoneList.add(new Stone(7, StoneColor.BLACK));
Stone stone8 = new Stone(8, StoneColor.BLACK);
stoneList.add(stone8);
stoneList.add(new Stone(9, StoneColor.BLACK));
stoneList.add(new Stone(10, StoneColor.BLACK));
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
view.getTablePanel().setStoneSets(stoneSets);
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
}
}
|