1
2
3
4
5
6
7 package net.curre.prefcount.gui.type;
8
9
10
11
12
13
14
15
16 public enum Place {
17
18
19 EAST(0, "pref.scoreboard.eastLetter", "pref.dialog.east"),
20
21
22 SOUTH(1, "pref.scoreboard.southLetter", "pref.dialog.south"),
23
24
25 WEST(2, "pref.scoreboard.westLetter", "pref.dialog.west"),
26
27
28 NORTH(3, "pref.scoreboard.northLetter", "pref.dialog.north");
29
30
31 public final String shortKey;
32
33
34 public final String longKey;
35
36
37 public final int index;
38
39
40 public static final Place[] THREE_PLAYERS = {EAST, SOUTH, WEST};
41
42
43 public static final Place[] FOUR_PLAYERS = {NORTH, EAST, SOUTH, WEST};
44
45
46
47
48
49
50
51
52 private Place(int index, String shortKey, String longKey) {
53 this.shortKey = shortKey;
54 this.index = index;
55 this.longKey = longKey;
56 }
57
58
59
60
61
62
63
64
65 public static Place[] getPlaces(int playerNum) {
66 if (playerNum == 3) {
67 return THREE_PLAYERS;
68 } else if (playerNum == 4) {
69 return FOUR_PLAYERS;
70 } else {
71 throw new IllegalArgumentException("Only 3 and 4 players supported!");
72 }
73 }
74
75
76
77
78
79
80
81 public static Place getPlaceForIndex(int index) {
82 switch (index) {
83 case 0:
84 return EAST;
85
86 case 1:
87 return SOUTH;
88
89 case 2:
90 return WEST;
91
92 case 3:
93 return NORTH;
94
95 default:
96 throw new IllegalArgumentException("Unable to determine place for index " + index + "!");
97 }
98 }
99
100
101
102
103
104
105
106
107 public static Place[] getOtherPlayersWhistPlaces(Place place, int numPlayers) {
108 Place[] places = new Place[numPlayers - 1];
109 switch (place) {
110 case EAST:
111 places[0] = SOUTH;
112 places[1] = WEST;
113 break;
114
115 case SOUTH:
116 places[0] = EAST;
117 places[1] = WEST;
118 break;
119
120 case WEST:
121 places[0] = EAST;
122 places[1] = SOUTH;
123 break;
124
125 case NORTH:
126 places[0] = EAST;
127 places[1] = SOUTH;
128 places[2] = WEST;
129 break;
130
131 default:
132 throw new IllegalArgumentException("Illegal place " + place + "!");
133 }
134 if (numPlayers == 4 && place != NORTH) {
135 places[2] = NORTH;
136 }
137
138 return places;
139 }
140
141 }