@@ -55,6 +55,28 @@ public GameEngine(PlayerFactory playerFactory,
55
55
isTurnOrderReversed = false ;
56
56
}
57
57
58
+ public int getNumberOfPlayers () {
59
+ return numOfPlayers ;
60
+ }
61
+
62
+ public List <Player > getPlayers () {
63
+ return new ArrayList <>(players );
64
+ }
65
+
66
+ /**
67
+ * Getter for draw pile cards.
68
+ */
69
+ public Card [] getDrawPile () {
70
+ return drawPile .getCards ();
71
+ }
72
+
73
+ /**
74
+ * Getter for isTurnOrderReversed.
75
+ */
76
+ public boolean getIsTurnOrderReversed () {
77
+ return isTurnOrderReversed ;
78
+ }
79
+
58
80
/**
59
81
* Adds the starting deck of cards to the drawPile.
60
82
*/
@@ -113,26 +135,6 @@ public void setUpPlayers(int numberOfPlayers, String[] names) {
113
135
}
114
136
}
115
137
116
- public int getNumberOfPlayers () {
117
- return numOfPlayers ;
118
- }
119
-
120
- public List <Player > getPlayers () {
121
- return new ArrayList <>(players );
122
- }
123
-
124
- /**
125
- * Returns whether the game is over.
126
- *
127
- * @return whether the game is over.
128
- */
129
- public boolean isGameOver () {
130
- if (numOfPlayers > 1 ) {
131
- return false ;
132
- }
133
- return true ;
134
- }
135
-
136
138
/**
137
139
* Add defuse cards to both player hands and the draw pile.
138
140
*/
@@ -181,24 +183,29 @@ public void insertExplodingAndImplodingCards() {
181
183
}
182
184
183
185
/**
184
- * Getter for draw pile cards .
186
+ * Method for shuffling the draw pile.
185
187
*/
186
- public Card [] getDrawPile () {
187
- return drawPile .getCards ();
188
+ public void shuffleDrawPile () {
189
+ drawPile .shuffle ();
188
190
}
189
191
190
192
/**
191
- * Getter method for drawPile.peek().
193
+ * Returns whether the game is over.
194
+ *
195
+ * @return whether the game is over.
192
196
*/
193
- public Card [] peekDrawPile () {
194
- return drawPile .peek ();
197
+ public boolean isGameOver () {
198
+ if (numOfPlayers > 1 ) {
199
+ return false ;
200
+ }
201
+ return true ;
195
202
}
196
203
197
204
/**
198
- * Method for shuffling the draw pile .
205
+ * Getter method for drawPile.peek() .
199
206
*/
200
- public void shuffleDrawPile () {
201
- drawPile .shuffle ();
207
+ public Card [] peekDrawPile () {
208
+ return drawPile .peek ();
202
209
}
203
210
204
211
/**
@@ -208,13 +215,6 @@ public void reverseTurnOrder() {
208
215
isTurnOrderReversed = !isTurnOrderReversed ;
209
216
}
210
217
211
- /**
212
- * Getter for isTurnOrderReversed.
213
- */
214
- public boolean getIsTurnOrderReversed () {
215
- return isTurnOrderReversed ;
216
- }
217
-
218
218
/**
219
219
* Replace the top cards in the draw pile with the cards in toSet.
220
220
*
@@ -249,34 +249,7 @@ public Card popTopCard() {
249
249
}
250
250
251
251
/**
252
- * Checks if a player has a specified card.
253
- *
254
- * @param card card to check if a player has.
255
- * @param playerIndex index of the player in the players list.
256
- */
257
- public boolean playerHasCard (Card card , int playerIndex ) {
258
- Player targetPlayer = getPlayerByIndex (playerIndex );
259
- return targetPlayer .hasCard (card );
260
- }
261
-
262
- /**
263
- * Checks if a player a number of the specified card.
264
- *
265
- * @param card card to check if a player has.
266
- * @param playerIndex index of the player in the players list.
267
- * @param numCards the number of cards to check for.
268
- */
269
- public boolean playerHasAtLeastCards (Card card , int playerIndex , int numCards ) {
270
- Player player = getPlayerByIndex (playerIndex );
271
- if (numCards <= 0 ) {
272
- throw new IllegalArgumentException ("Number of cards must be greater than 0." );
273
- }
274
- return Arrays .stream (player .getHand ()).filter (c -> c == card )
275
- .count () >= numCards ;
276
- }
277
-
278
- /**
279
- * TODO: eliminates the player at that index.
252
+ * Eliminates the player at that index.
280
253
*/
281
254
public void eliminatePlayer (int playerIndex ) {
282
255
if (playerIndex < 0 || playerIndex >= numOfPlayers ) {
@@ -302,6 +275,17 @@ public void removeCardFromPlayer(Card card, int playerIndex) {
302
275
player .removeCardFromHand (card );
303
276
}
304
277
278
+ /**
279
+ * Checks if a player has a specified card.
280
+ *
281
+ * @param card card to check if a player has.
282
+ * @param playerIndex index of the player in the players list.
283
+ */
284
+ public boolean playerHasCard (Card card , int playerIndex ) {
285
+ Player targetPlayer = getPlayerByIndex (playerIndex );
286
+ return targetPlayer .hasCard (card );
287
+ }
288
+
305
289
/**
306
290
* Returns the player at the index in the list or errors if it doesn't exist.
307
291
*
@@ -325,60 +309,12 @@ public void discardCard(Card card) {
325
309
}
326
310
327
311
/**
328
- * TODO: add the specified card to a specified location in the card pile.
312
+ * Add the specified card to a specified location in the card pile.
329
313
*/
330
314
public void addCardToDrawPileAt (Card card , int index ) {
331
315
drawPile .addCardAt (card , index );
332
316
}
333
317
334
- /**
335
- * Returns the correct card based on the String name.
336
- *
337
- * @param cardName the String version of the card.
338
- * @return the Card.
339
- */
340
- public Card getCardByName (String cardName ) {
341
- switch (cardName ) {
342
- case "attack" :
343
- return Card .ATTACK ;
344
- case "skip" :
345
- return Card .SKIP ;
346
- case "targeted attack" :
347
- return Card .TARGETED_ATTACK ;
348
- case "shuffle" :
349
- return Card .SHUFFLE ;
350
- case "see the future" :
351
- return Card .SEE_THE_FUTURE ;
352
- case "reverse" :
353
- return Card .REVERSE ;
354
- case "draw from bottom" :
355
- return Card .DRAW_FROM_BOTTOM ;
356
- case "alter the future" :
357
- return Card .ALTER_THE_FUTURE ;
358
- case "nope" :
359
- return Card .NOPE ;
360
- case "taco cat" :
361
- return Card .TACO_CAT ;
362
- case "beard cat" :
363
- return Card .BEARD_CAT ;
364
- case "rainbow cat" :
365
- return Card .RAINBOW_CAT ;
366
- case "feral cat" :
367
- return Card .FERAL_CAT ;
368
- case "hairy potato cat" :
369
- return Card .HAIRY_POTATO_CAT ;
370
- case "exploding kitten" :
371
- return Card .EXPLODE ;
372
- case "imploding kitten" :
373
- return Card .IMPLODE ;
374
- case "defuse" :
375
- return Card .DEFUSE ;
376
- default :
377
- throw new IllegalArgumentException ("Could not parse input." );
378
- }
379
- }
380
-
381
-
382
318
/**
383
319
* Gets the index of the player in the GameEngine's Player List by their name.
384
320
*
@@ -394,7 +330,6 @@ public int getPlayerIndexByName(String name) {
394
330
throw new NoSuchElementException ("No player with that name could be found." );
395
331
}
396
332
397
-
398
333
/**
399
334
* Validates that the player has the given cards and that they can be played as a combo.
400
335
*
@@ -447,4 +382,67 @@ public Card[] validateComboCards(String[] cards, int currPlayerIndex) {
447
382
448
383
return returnCards ;
449
384
}
385
+
386
+ /**
387
+ * Checks if a player a number of the specified card.
388
+ *
389
+ * @param card card to check if a player has.
390
+ * @param playerIndex index of the player in the players list.
391
+ * @param numCards the number of cards to check for.
392
+ */
393
+ public boolean playerHasAtLeastCards (Card card , int playerIndex , int numCards ) {
394
+ Player player = getPlayerByIndex (playerIndex );
395
+ if (numCards <= 0 ) {
396
+ throw new IllegalArgumentException ("Number of cards must be greater than 0." );
397
+ }
398
+ return Arrays .stream (player .getHand ()).filter (c -> c == card )
399
+ .count () >= numCards ;
400
+ }
401
+
402
+ /**
403
+ * Returns the correct card based on the String name.
404
+ *
405
+ * @param cardName the String version of the card.
406
+ * @return the Card.
407
+ */
408
+ public Card getCardByName (String cardName ) {
409
+ switch (cardName ) {
410
+ case "attack" :
411
+ return Card .ATTACK ;
412
+ case "skip" :
413
+ return Card .SKIP ;
414
+ case "targeted attack" :
415
+ return Card .TARGETED_ATTACK ;
416
+ case "shuffle" :
417
+ return Card .SHUFFLE ;
418
+ case "see the future" :
419
+ return Card .SEE_THE_FUTURE ;
420
+ case "reverse" :
421
+ return Card .REVERSE ;
422
+ case "draw from bottom" :
423
+ return Card .DRAW_FROM_BOTTOM ;
424
+ case "alter the future" :
425
+ return Card .ALTER_THE_FUTURE ;
426
+ case "nope" :
427
+ return Card .NOPE ;
428
+ case "taco cat" :
429
+ return Card .TACO_CAT ;
430
+ case "beard cat" :
431
+ return Card .BEARD_CAT ;
432
+ case "rainbow cat" :
433
+ return Card .RAINBOW_CAT ;
434
+ case "feral cat" :
435
+ return Card .FERAL_CAT ;
436
+ case "hairy potato cat" :
437
+ return Card .HAIRY_POTATO_CAT ;
438
+ case "exploding kitten" :
439
+ return Card .EXPLODE ;
440
+ case "imploding kitten" :
441
+ return Card .IMPLODE ;
442
+ case "defuse" :
443
+ return Card .DEFUSE ;
444
+ default :
445
+ throw new IllegalArgumentException ("Could not parse input." );
446
+ }
447
+ }
450
448
}
0 commit comments