implemented dealCards function

This commit is contained in:
Johannes Schmelz 2024-05-12 17:42:43 +02:00
parent 020716053b
commit 4a8b342577
2 changed files with 31 additions and 2 deletions

View File

@ -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());
} }
/** /**