Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuman.java
More file actions
301 lines (265 loc) · 8.57 KB
/
Copy pathHuman.java
File metadata and controls
301 lines (265 loc) · 8.57 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*************************************************************
* Human.java
* Secret Hitler
*
* MSc Computer Games Systems
* Nottingham Trent University
* Major Project
*
* Dario Hermann N0773470
* 2017/18
*************************************************************/
import java.util.ArrayList;
/**
* Class for the human players
*
*/
public class Human extends Player{
/**
* Human()
* Human.java constructor
*
* @param role Its role (Liberal, Fascist or Hitler)
* @param state Its player number
*/
public Human(String role, int state) {
super(role, state);
System.out.println("You're player " + state);
}
/**
* receiveRole()
* The human player receives the information of the Fascists, but can only see who the fascists are if he himself belongs to the Fascist party
*
* @param showRoles The player numbers of both fascists
*/
public void receiveRole(ArrayList<Integer> showRoles) {
if(role.equals("Liberal")) {
System.out.println("You are a Liberal");
} else if(role.equals("Hitler")) {
System.out.println("You are Hitler and the other Fascist is Player "+ showRoles.get(0));
} else {
System.out.println("You are a Fascist and Player " + showRoles.get(1) + " is Hitler");
}
}
/**
* int chooseChancellor()
* The action to choose a Chancellor
*
* @param president President's player number
* @param lastChancellor Last round's chancellor player number
* @param players A list of all the players still in the game
* @return The player number of the chosen Chancellor
*/
public int chooseChancellor(int president, int lastChancellor, ArrayList<Integer> players) {
int chosen;
chosen = sc.nextInt();
boolean canChoose = false;
if(players.contains(chosen)) {
canChoose = true;
}
while(!canChoose || (chosen == lastChancellor || chosen == president)){
if(chosen == president) {
System.out.println("You cannot choose yourself as the Chancellor");
}else if(chosen == lastChancellor) {
System.out.println("You cannot choose Player " + lastChancellor + " as the Chancellor because he was the Chancellor last round");
} else {
System.out.println("That player doesn't exist or is already dead");
}
System.out.println("Choose another player");
chosen = sc.nextInt();
if(players.contains(chosen)) {
canChoose = true;
}
}
return chosen;
}
/**
* String vote()
* Vote on the Presidential election (President + Chancellor)
*
* @param president President
* @param chancellor Chancellor
* @return "Y" for yes and "N" for No
*/
public String vote(int president, int chancellor) {
String v = sc.next();
v=v.toUpperCase();
while(!v.equals("Y") && !v.equals("N")) {
System.out.println("That is not a valid option, please choose \"Y\" for Ja!(Yes) or \"N\" for Nein!(No)");
v = sc.next();
v=v.toUpperCase();
}
return v;
}
/**
* int discardCard()
* The action to discard a card if the player is the president
*
* @param one first card
* @param two second card
* @param three third card
* @return the card the human player wants to discard
*/
public int discardCard(String one, String two, String three) {
System.out.println(one + "(1)\n"+ two + "(2)\n" + three + "(3)");
int discard = sc.nextInt();
while(discard > 3 || discard < 1) {
System.out.println("Please choose a valid option! 1/2/3");
discard = sc.nextInt();
}
return discard-1;
}
/**
* int discardCard()
* The action to discard a card if the player is the Chancellor
*
* @param one first card
* @param two second card
* @return the card the human player wants to discard or veto if the opportinity so presents
*/
public int discardCard(String one, String two, boolean veto) {
System.out.println(one + "(1)\n"+ two + "(2)");
if(veto) {
System.out.println("The Veto Power is On, if you don't like any of the policies and want to discard them both choose 3");
}
int discard = sc.nextInt();
while((!veto && discard == 3) || (discard > 3 || discard < 1)) {
System.out.print("Please choose a valid option! 1/2");
if(veto) {
System.out.print("/3");
}
System.out.println("");
discard = sc.nextInt();
}
return discard-1;
}
/**
* boolean voteVeto
* Voting if the human player accepts the veto proposed by the chancellor
*
* @param one first card
* @param two second card
* @return true if it agrees with the veto, false otherwise
*/
public boolean voteVeto(String one, String two) {
System.out.println("President, do you want to veto? The policies are " + one + " and " + two + " Y/N");
String vote = sc.next();
vote = vote.toUpperCase();
while(!vote.equals("Y") && !vote.equals("N")) {
System.out.println("Not a valid input, please input \"Y\" for Yes and \"N\" for No");
vote = sc.next();
vote = vote.toUpperCase();
}
if(vote.equals("Y")) {
return true;
} else {
return false;
}
}
/**
* checkTreeCards
* Checks the three cards on top of the draw pile
*
* @param one first card
* @param two second card
* @param three third card
*/
public void checkThreeCards(String one, String two, String three) {
System.out.println(one+"\n"+two+"\n"+three);
}
/**
* int killPlayer()
* The action to kill a player
*
* @param players The players still in the game
* @return The player the human player wants to kill
*/
public int killPlayer(ArrayList<Integer> players) { //MAIS TARDE MUDAR POR CAUSA DA CENA DO PLAYER 0
System.out.println("President, choose one player to kill");
int choice = sc.nextInt();
boolean canKill = false;
if(players.contains(choice) && choice != state) {
canKill = true;
}
while(!canKill) {
System.out.println("That player doesn't exist, was killed or is you!");
choice = sc.nextInt();
canKill = players.contains(choice);
}
return choice;
}
/**
* String tellCards
* Telling what cards the human player had in his "hand" (this method is for the president)
*
* @param one first card
* @param two second card
* @param three third card
* @param enacter the policy that was enacted
* @return What cards the player had in his "hand" (obviously one can lie about it)
*/
public String tellCards(int one, int two, int three, int enacted) {
String[] results = new String[4];
results[0] = "3 Liberals 0 Fascists";
results[1] = "2 Liberals 1 Fascist";
results[2] = "1 Liberal 2 Fascists";
results[3] = "0 Liberals 3 Fascists";
return results[sc.nextInt()];
}
/**
* String tellCards
* Telling what cards the human player had in his "hand" (this method is for the chancellor)
*
* @param one first card
* @param two second card
* @param enacter the policy that was enacted
* @return What cards the player had in his "hand" (obviously one can lie about it)
*/
public String tellCards(int one, int two, int enacted) {
String[] results = new String[3];
results[0] = "2 Liberals 0 Fascists";
results[1] = "1 Liberal 1 Fascists";
results[2] = "0 Liberals 2 Fascists";
return results[sc.nextInt()];
}
/**
* cardsTold()
* Cards Told by the president and chancellor (when the player is none of those two)
*
* @param president president player number
* @param chancellor chancellor player number
* @param presTold what the president told
* @param chancTold what the chancellor told
*/
public void cardsTold(int president, int chancellor, String presTold, String chancTold) {
System.out.println("The president, Player " + president + " told he had: " + presTold);
System.out.println("The chancellor, Player " + chancellor + " told he had: " + chancTold);
}
/**
* cardsTold()
* Cards Told by the president(when the player is the chancellor)
*
* @param president president player number
* @param presTold what the president told
* @param chancTold what the chancellor told
* @param cone first card
* @param ctwo second card
*/
public void cardsTold(int president, String presTold, String chancTold, int cone, int ctwo) {
System.out.println("The president, Player " + president + " told he had: " + presTold);
}
/**
* cardsTold()
* Cards Told by the chancellor(when the player is the president)
*
* @param chancellor chancellor player number
* @param presTold what the president told
* @param chancTold what the chancellor told
* @param cone first card
* @param ctwo second card
* @param cthree third card
*/
public void cardsTold(int chancellor, String presTold, String chancTold, int cone, int ctwo, int cthree) {
System.out.println("The chancellor, Player " + chancellor + " told he had: " + chancTold);
}
}
You can’t perform that action at this time.
