From 4a8b342577a8e7a2163dd92f09f3062147c3cb20 Mon Sep 17 00:00:00 2001 From: peet Date: Sun, 12 May 2024 17:42:43 +0200 Subject: [PATCH] implemented dealCards function --- bin/cards/maumau/model/CardHandler.class | Bin 2181 -> 2835 bytes src/cards/maumau/model/CardHandler.java | 33 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bin/cards/maumau/model/CardHandler.class b/bin/cards/maumau/model/CardHandler.class index 24778c39a39112a6361cc9eeff82a831d1df4380..e79c97ed65419a2a81d91472cb8a19047d1a0331 100644 GIT binary patch delta 812 zcmYLGTTc@~7(KH)rFFYCAlWL4O{+$GNi7%^V*}9`9#DcN#41{arCocmv~|1O(Ru-W z^kIJii3vVRG&R-4%ae&u`WN)ke_&MnW|!#0&YbVeeCM3`cCE_}c7Fcz<{f~uc;bb` z5VAkY-F8~?ZysIYO=Wl?XVk4yt=jP7219pQpVLzny;?~9J5g{3lPac=WKar*b*Z8+ z8fL?f2&Pr!kZ0hH(vra-M`I&C++ye%t65>ATAM8t!#Ul|H^NpeoHz7JL_ros6+2O4 z(4w)?|9<0^S*jM&v5XMDt)hY%QY1fdam4PEHC`iS5r4pqprDF7DoivOcH~Wc{+zI) zG|`b*MghaDiazuUG_PU-i}rIKI_|Bz`58K`nx$8qrZL0F8}txHu~?bjnVU6D*M(u< zs4!LBGR=^*pGv#!PjW!priO@QIg$I3iq)52_;;x(;W|y7lXn(f06PE~9mLGUU!k{! zo1=*~bOx$IMLspyOJI+~JVW3uvJ<!iRALaTy1ZK@!)9&*Bs&F^p+k zAUr`_9wi!o8AqsN$W4tXVpREHUff$?3=9m849V;aOpFY2lMgZrPqt>_-l$i@qQ;(*S)80$l)}isui*n? z6ze+!No&n8Mh3=YZU#k$cpip?&9Q8cnJgF?1cByg12H2AZv+xd3~E4<4J_cxpblj7 zKqMJ77&L)A28L*cn8}q~TC$-GTnu4g6=FbL3=G_G72FK5lMiqyFvd-O$R#Qphhz#b OR1G6TB2WhtLlOWY03V6~ diff --git a/src/cards/maumau/model/CardHandler.java b/src/cards/maumau/model/CardHandler.java index c69a174..b0cfe80 100644 --- a/src/cards/maumau/model/CardHandler.java +++ b/src/cards/maumau/model/CardHandler.java @@ -71,9 +71,38 @@ class CardHandler { /** * Deals cards to all players. + * @throws Exception when there are not enough cards to satisfy starting conditions */ - void dealCards() { - //TODO implement + void dealCards() throws Exception { + + // get List of players + List 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()); } /**