/
Deadwood.java
460 lines (406 loc) · 14.4 KB
/
Deadwood.java
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import java.util.*;
import java.lang.Math;
public class Deadwood{
private Board currGame;
private Roll dice;
private int playerNum, playerID, cash;
private boolean canMove, canWork, canUpgrade, toggleDefault;
private LinkedList<Player> users;
private String userInput, mainInput, paymentMethod;
Deadwood(){
playerNum = 3;
currGame = new Board();
users = createPlayers(playerNum);//generate players
canMove = true;
canWork = false;
canUpgrade = false;
toggleDefault = false;
dice = new Roll();
userInput = new String();
mainInput = new String();
paymentMethod = "DOLLAR";
playerID = 0;
cash = 0;
}
public void setPaymentMethod(String paymentMethod){ this.paymentMethod = paymentMethod; }
public void getScenes(){ currGame.prepBoard(); }
public int getLastRoll(){ return dice.getRoll(); }
public void setPlayerNum(int playerNum){ this.playerNum = playerNum; }
public boolean moveToggle(){ return canMove;}
public boolean workToggle(){ return canWork;}
public boolean upgradeToggle(){ return canUpgrade;}
public boolean menuToggled(){ return toggleDefault; }
public void setUserInput(String userInput){ this.userInput = userInput; }
public String getUserInput(){ return userInput; }
public String getCurrentCommand(){ return userInput; }
public String getBaseCommand(){ return mainInput; }
public String getCurrencyType(){ return paymentMethod; }
public LinkedList<Player> allPlayers(){ return users; }
public Player currentPlayer(){ return users.get(playerID); }
public int getCash(){ return cash;}
public Wallet currentWallet(){ return currentPlayer().evalWalletContent(); }
public int currentLevel(){ return currentPlayer().getLevel(); }
public Location currentLocation(){ return currentPlayer().getLocation(); }
public boolean currentlyWorking(){ return currentPlayer().isWorking(); }
public int numberShotCounters(){ return currentLocation().getSet().getShotCounter();}
public LinkedList<Location> currentNeighbors(){ return currentLocation().getNeighbors(); }
public LinkedList<Work> currentJobs(){ return currentLocation().getJobs(); }
public Location meetNeighbor(int index){ return currentNeighbors().get(index); }//returns the job at current index
public Work selectedJob(int ID){ return currentJobs().get(ID); }
public boolean endofRound(){ return currGame.hasFinishedRound(); }
public boolean finishedFilming(){ return currentLocation().doneFilming(); }
public boolean endofGame(){ return currGame.hasFinishedGame(); }
private LinkedList<Player> evaluateWinner(){//evaluate winner(s)
LinkedList<Player> winner = new LinkedList<Player>();
Player p1 = users.get(0);
Wallet w1 = p1.evalWalletContent();
for(int i = 0; i < users.size(); i++){
Player p2 = users.get(i);
Wallet w2 = p2.evalWalletContent();
int p1Points = w1.calculatePoints(p1.getLevel());
int p2Points = w2.calculatePoints(p2.getLevel());
if(p2Points > p1Points){
winner.clear();
p1 = p2;
w1 = w2;
}if(p2Points == p1Points){
winner.add(p2);
}
}
winner.add(p1);
return winner;
}
private LinkedList<Player> createPlayers(int playerNum){//generates players
LinkedList<Player> friends = new LinkedList<Player>();
ColorTemplates picture = new ColorTemplates();
for(int i = 0; i < playerNum; i++){
Player temp = new Player();
temp.setID(i);
temp.setColors(picture.get(i));
temp.setPlayerName("Player " + (i+1));
temp.setLocation(currGame.getTrailer());
friends.add(temp);
}
//System.out.println("Created players");
return friends;
}
public void checkOnPlayer(){//detoggle options based on player's circumstances
if(currentlyWorking()){
canMove = false;
}
if(currentLocation().getID() != 8){
canUpgrade = false;
}else{
canUpgrade = true;
}
if(finishedFilming()){
canWork = false;
}else{
canWork = true;
}
}
public int validLocationID(int locID){//valid location
int i = 0;
while(i != currentNeighbors().size() && meetNeighbor(i).getID() != locID){
//System.out.println(meetNeighbor(i).getID());
i++;
}
if(i == currentNeighbors().size()){
return -1;
}else{
return i;
}
}
public boolean validWorkID(int jobID){//valid work
if(jobID >= 0 && jobID < currentJobs().size()){
//System.out.println("valid job in list");
if(currentPlayer().getLevel() >= selectedJob(jobID).getWorkLevel() && !selectedJob(jobID).getWorkStatus()){
//System.out.println("valid level for the posting");
return true;
}else{
//System.out.println("not able to be worked on");
return false;
}
}else{
return false;
}
}
private boolean sameLocation(Location check){// check if location is same as the current
if(currentLocation().getID() == check.getID()){
return true;
}else{
return false;
}
}
private void actorsLastHurrah(){
//System.out.println("FINISHED FILMING");
for(int j = 0; j < users.size(); j++){
Player applicant = users.get(j);
//System.out.println(applicant.getPlayerName() + " is on " + applicant.getLocation().getLocationName());
if(sameLocation(applicant.getLocation())){
//System.out.println("guess I'm on the lcoation");
if(currentLocation().hasMainActors()){//get bonus payout if there were celebrities
applicant.bonusPayout(dice.getBonusRoll(currentLocation().getSet().getScene().getBudget()));
}
applicant.removeWork();
//System.out.println("REMOVE FROM WORK");
}
}
}
private void evaluateConsequences(){//check to see if any outside factors happened
if(finishedFilming() && (currentLocation().getID() != 8 && currentLocation().getID() != 4)){
actorsLastHurrah();
}
if(endofRound()){//finished a round
if(!endofGame()){//get new scenes, return players to Trailer, decrement round
for(int i = 0; i > users.size(); i++){//return all players to Trailer
users.get(i).setLocation(currGame.getTrailer());
}
currGame.prepBoard();//get new scenes
currGame.nextRound();//decrement round
}else{//end game, figure out winner.
LinkedList<Player> winner = evaluateWinner();
}
}
}
private void exchangeCurrency(){//get currency current player is using
if(paymentMethod.equals("DOLLAR")){
cash = currentWallet().getDollars();
}else if(paymentMethod.equals("CREDIT")){
cash = currentWallet().getCredits();
}else{//error
cash = -1;
}
}
public int calculatePrice(int levelID){//get the cost of the level
if(paymentMethod.equals("DOLLAR")){
return (int) Math.pow(2, levelID);
}else if(paymentMethod.equals("CREDIT")){
return 5 * (levelID - 1);
}else{//error
return -1;
}
}
public boolean validLevel(int levelID){//valid upgradablelevel
int myPrice = 0;
if(levelID <= 6 && levelID > currentLevel()){//player at valid level
if(paymentMethod.equals("DOLLAR") || paymentMethod.equals("CREDIT")){
myPrice = calculatePrice(levelID);
if(canPay(myPrice, cash)){
return true;
}else{
return false;
}
}else{//error
return false;
}
}else{
return false;
}
}
private void paythePrice(){ currentPlayer().pay(cash, paymentMethod);}//decrement cash
private boolean canPay(int price, int amount){//determine if has enough cash to pay
if(price > amount){
return false;
}else{
return true;
}
}
private void getNextPlayer(){//next player
playerID = playerID + 1;
if(playerID == playerNum){
playerID = 0;
}
}
private void parseAction(){//parse the moves within moves
//System.out.println(currentPlayer().getPlayerName() + " is trying to " + userInput + " with " + mainInput);
switch(mainInput){
case "MOVE"://change current player location
try{
int LocID = Integer.parseInt(userInput);
//System.out.println("Guess the user inputted a Location ID of some kind...");
int neighborAddress = validLocationID(LocID);
if(neighborAddress != -1){//exists as a neighbor
currentPlayer().setLocation(meetNeighbor(neighborAddress));
checkOnPlayer();
canMove = false;
toggleDefault = false;
//System.out.println("Player now resides on: " + currentLocation().getLocationName());
}else{
//System.out.println("Not a valid Location identification");
}
}catch(Exception e){//error
//System.out.println("Not a valid input for moving");
}
break;
case "WORK"://set role, act, or rehearse
if(!currentlyWorking()){ // If NOT working, then you are unemployed
System.out.println("Looks like " + currentPlayer().getPlayerName() + " is unemployed...");
try{
int workID = (Integer.parseInt(userInput));
System.out.println("trying to obtain job number " + workID);
if(validWorkID(workID)){ // If the work ID is valid, then they work on this job!
selectedJob(workID).bufWork();
currentPlayer().setJob(selectedJob(workID));
System.out.println(currentPlayer().getPlayerName() + " is now working on " + currentPlayer().getJob().getJobTitle());
if(!canMove){ //remove player from work status if have moved already
System.out.println("Can't work at the moment, check back in later");
toggleDefault = false;
canWork = false;
break;
}
}
}catch(Exception e){ // a catch and not an else?
System.out.println("Can't work with that command...");
}
}
if(currentlyWorking()){
//System.out.println("Looks like the player " + currentPlayer().getPlayerName() + "has been doing something at the " + currentLocation().getLocationName() + "...");
//System.out.println("seems like the player is trying to " + userInput);
if(userInput.equals("REHEARSE")){
int rehearsals = currentPlayer().rehearse();
//System.out.println("you've rehearsed " + rehearsals + " times");
if(rehearsals != -1){
toggleDefault = false;
canWork = false;
}else{
//System.out.println("YOu can't rehaeESE anyMorea");
}
}else if(userInput.equals("ACT")){
dice.roll();
currentPlayer().act(dice.getRoll());
toggleDefault = false;
canWork = false;
}else{ //error
//System.out.println("guess the player is not really doing anything rn...");
}
canMove = false;
}
break;
case "UPGRADE"://change current player level
if(userInput.equals("CREDIT") || userInput.equals("DOLLAR")){
exchangeCurrency();
}else{ //selected a level
int level = Integer.parseInt(userInput);
if(validLevel(level)){
paythePrice();
currentPlayer().setActorLevel(level);
canUpgrade = false;
}
}
break;
default://not a recognized userInput
//System.out.println("Not a command recognized for " + mainInput);
}
}
public void switchCommand(){//main commands
if(!toggleDefault){
//System.out.println("");
switch(userInput){
case "RENAME":
break;
case "DISPLAY":
break;
case "WHO":
System.out.println("WHO YOU ARE --------");
System.out.println("USER NAME: " + currentPlayer().getPlayerName());
System.out.println("WHERE: " + currentLocation().getLocationName());
System.out.println("WORK TITLE: " + currentPlayer().getJob().getJobTitle());
System.out.println("Allowed to move -> " + canMove);
System.out.println("Allowed to work -> " + canWork);
System.out.println("Allowed to upgrade -> " + canUpgrade);
break;
case "WHERE":
for(int i = 0; i < users.size(); i++){
System.out.println(users.get(i).getPlayerName() + " on " + users.get(i).getLocation().getLocationName());
System.out.println("WORK STATUS: " + users.get(i).isWorking());
}
break;
case "END"://USER ENDS THEIR TURN, NEXT PLAYER STARTS
//System.out.println("User " + currentPlayer().getPlayerName() + " has ended their turn");
if(!canMove){
canMove = true;
}
evaluateConsequences();//check for outside happenings
getNextPlayer();
checkOnPlayer();
//System.out.println("User " + currentPlayer().getPlayerName() + " has started their turn");
break;
case "MOVE"://USER WANTS TO MOVE
//System.out.println("User " + currentPlayer().getPlayerName() + " wants to move it.");
if(canMove){
//System.out.println(currentPlayer().getPlayerName() + " is permitted to move.");
mainInput = userInput;
//System.out.println("Locations in your area (enter ID): ");
for(int m = 0; m < currentNeighbors().size(); m++){
//System.out.println(meetNeighbor(m).getID() + " " + meetNeighbor(m).getLocationName());
}
toggleDefault = true;
}else{
//System.out.println("User " + currentPlayer().getPlayerName() + " is not allowed to move.");
}
break;
case "UPGRADE":
if(canUpgrade){
mainInput = userInput;
toggleDefault = true;
}else{
//System.out.println(currentPlayer().getPlayerName() + " is not allowed to upgrade");
}
break;
case "WORK":
//System.out.println(currentLocation().getLocationName() + " currently has " + numberShotCounters() + "shots.");
if(canWork){
currentLocation().displayContent();
mainInput = userInput;
toggleDefault = true;
//System.out.println("player work status: " + currentPlayer().isWorking());
if(!currentPlayer().isWorking()){
//System.out.println("seems like you're not working, here's the jobs");
for(int w = 0; w < currentJobs().size(); w++){
System.out.print(w + ": ");
System.out.print(selectedJob(w).getJobTitle() + " ");
System.out.print(selectedJob(w).getWorkLevel() + " ");
System.out.print(selectedJob(w).getWorkType() + " ");
System.out.print(selectedJob(w).getWorkStatus());
System.out.println(" ");
}
}
}else{
//System.out.println("PLAYER IS NOT ALLOWED TO WORK");
}
break;
default:
//System.out.println("Not a command");
}
}else{
if(userInput.equals("NO")){
toggleDefault = false;
//System.out.println("going back to the default commands");
}else{
parseAction();
}
}
//System.out.println("");
}
public void run(){//int playerNum) throws invalidPlayerException{
/*if(playerNum != 2 && playerNum != 3){
throw new invalidPlayerException();
}*/
boolean playGame = true;
System.out.println("start run");
currGame.prepBoard();
checkOnPlayer();
while(playGame){
if(endofGame()){
if(userInput.equals("YES")){//refresh program
}
if(userInput.equals("NO")){//quit program
playGame = false;
}
}else{
switchCommand();
}
}
}
}