implemented dealCards function
This commit is contained in:
parent
020716053b
commit
4a8b342577
Binary file not shown.
@ -71,9 +71,38 @@ class CardHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deals cards to all players.
|
* Deals cards to all players.
|
||||||
|
* @throws Exception when there are not enough cards to satisfy starting conditions
|
||||||
*/
|
*/
|
||||||
void dealCards() {
|
void dealCards() throws Exception {
|
||||||
//TODO implement
|
|
||||||
|
// get List of players
|
||||||
|
List<Player> players = game.getPlayers();
|
||||||
|
|
||||||
|
|
||||||
|
//checks if there are enough cards to be dealt
|
||||||
|
int totalCardsNeeded = players.size() * numCardsPerPlayer + 1;
|
||||||
|
|
||||||
|
if (totalCardsNeeded > drawPile.size() ){
|
||||||
|
throw new Exception("Not enough cards to deal!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < numCardsPerPlayer; i++) {
|
||||||
|
|
||||||
|
for (int j = 0; j < players.size(); j++) {
|
||||||
|
|
||||||
|
// get the current player
|
||||||
|
Player currPlayer = players.get(j);
|
||||||
|
|
||||||
|
//execute drawCards as currPlayer to draw 1 card
|
||||||
|
currPlayer.drawCards(1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the starting card on the discard Pile
|
||||||
|
discard(drawCard());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user