From 4b574c50e80d2feca30867e2b78075311538a69e Mon Sep 17 00:00:00 2001 From: peet Date: Tue, 18 Jun 2024 21:25:33 +0000 Subject: [PATCH] aufgabe 5 state pattern --- bin/cards/maumau/model/ActionHandler.class | Bin 2348 -> 2585 bytes bin/cards/maumau/model/Normal.class | Bin 1671 -> 2186 bytes .../maumau/model/WaitForNextTurnState.class | Bin 1367 -> 1501 bytes src/cards/maumau/model/ActionHandler.java | 7 ++-- src/cards/maumau/model/Normal.java | 30 ++++++++++++++---- .../maumau/model/WaitForNextTurnState.java | 8 +++-- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/bin/cards/maumau/model/ActionHandler.class b/bin/cards/maumau/model/ActionHandler.class index 8be417896669853b525e658c7e8b0de74f00f1c0..836885c9843c3bc22c898eaa5921c2368b546717 100644 GIT binary patch literal 2585 zcmah}Uvm>x96dKl6O(LcDHH@kNm{B+szeklSS;31+Gtw9b~?ffZj-gynru4B#u<3@ zO`r71cb|PwhYq98_yPP-4Cmh6?ry{FWG3z1z56@op5LEy|9|z*e*jjnokC2Y&@g+= zex+j$_^WifO{-m5X}EURSvQ?#+v=r|5SZ9Ezc(vw)7h&$*xk1pu0UeX>{tSq>KcL# zbHLw{K&H{^_AO^?U=v~Zq4JI25)HSvC?IMAY00(anl1^ab%bk2--$C?o-jYYsEhZt zs}MqxcWlRYmq|Xai}vM~b||XK3S#^u27AJqeh{&*|wis%?zedlrm-n=Cs0( zHEPKddeuM6@*0FB5+lUipD5l+H5u-w#{c&@1*{DUm2Xmhq#f#M*>$g zrHwKhsNe$*#(__)9b=!D^VxUJo=TV_{Vivy-;&A6`8J(~)joP@bvf--8j9&2B`051 z9-*ZVmv%|*d6nlN&6jko3cQzNWHn;HQ$f5s zKu*ZIffU{n$gwxk&@7>g)$YJ?WzlH?dNkLw7!~fGww*@L>R3)>&+x_h)+_`kcB0oy zI2TNZ1(aoeqhL>1ovrSm*Rbx}YGjX%;5B(4p}-X4yvxQgDJPvzF`18AX;!t;Yigw@ zxSrwPI3|cY&8K}NhyZ5FFELq;A7ZNf7tS9dU;Y=|T);fPpYs?|LYZ&mR>}mQ7Vw^b?lNQKxk<^L54kgHH&4Xn2v;)T zO3Isq9KidyrsJ9&<|>e@cmkKKh~%OXe6FgmD_een*@eGxJ%(Yz63beS5M~2$S=_|O zif|EUeZmFO%OgZclT;hm6@{0J2qEaUDdibp3#2y)E5Htj{g zV?mo%abE*o8wMX}!L^`V$6T-$PKf7%XPn&UiotVK)CJPxQu7!1QX^#Q_n|C)&{fQm{%R9cjxf`}k~)XxNk1cT8B61SB z?z<0~NKAb22l%6m=gtnhOC8dr?9R;IbLQN8&rJC9_t$SCx<&WeDJ3XpnSQxmteFk` ziZ!onSBtl-!13G%rdzJsemi9Z9ojPAn8m8;ZWfog!gy917}o1VJdz^7q7I-5J0jE zj_U-AARpI7E4leKh$^81os_1-2KCSpLFw`QS_cUlFsOq%d34mEHp&X>S#n(aaig|w z`%ldEDx~)?Q&wQq*y z6?Aeuuj@zT+ipab64pH!#mf!Y2G$lD8>26H;gXdu$6qn8+aeaUk@Dut{0SKyRYv8OFIMEuos0E&<3$3!fzfZQ4RFt_*(ZyC2EBjDff(5xems`t!s+B+88u&sB zoS`d9G$+9t+6q5t@EZo9p~FsZB*1M^r)TM^20Ygc_O#&ns9bw|KNp)U^!;0Sbz3qF zNEar3&qtRvFVJ<3kp8btS-jH6^(QebW PZJVOd!Gi9{dfoj8r21~a diff --git a/bin/cards/maumau/model/Normal.class b/bin/cards/maumau/model/Normal.class index 3d4eb021eccfff36064766763bdf61f4188c51d0..b028978de4973d40504992bc86fb46bc12c9f660 100644 GIT binary patch literal 2186 zcmah}+fv(B6kP`!goS{Rk~V}uNJ@weA?_`qt`%Fr2d; zYpYQ`u-rX)P+>`zb2U>|3evTe94g~p$*v2GM`aCYV08&uEbdg~Gs_j2j4Uv)W>jT; z$DwB=X6Q)Fx+h(4MOImv{)FAvOQB#&$FwRfp;W8Ytt@B6mRhNm$Xq&Z;HH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M315Wmtzop$?nUviQ{XgbY}!KU--^ds&IxuDuRMJ|+!iuH z>w(RAVNxfpuSU#B1_OfEf z{K$4qIrqqM$l_{m!Mw^XNzwdNESbf8)ztIudS9!eFBHsv;=qW>5z`}@UpOVarJ5wa zF@HaapSdvN(w=HFj475hqO3}pCgY0W?R!ztGjw!kkftWPW-31;)#TdDRj!#2w%?dY uTPCnnCVyKJcAZ5<(N9}Sbkm3aqg&=?s#{6D4=3KTn(|u0?OW<=ar+Of@mXO2 diff --git a/bin/cards/maumau/model/WaitForNextTurnState.class b/bin/cards/maumau/model/WaitForNextTurnState.class index eef4723cae2aa3d0d1df1b66e9b24dc6b55fccc1..bc438b701d2545023d34736ad1d91b278fa4923a 100644 GIT binary patch delta 310 zcmYL?J4?f06o#KP$q!};G(e~wrX)0M=4&h<%nSKA0I?l@nNfRt|s))>=zk%aIZ#; zic>2;kx%dv2A-)%)`OZgO67%wnMaB#>`xd^|KGu70d3jV>6SW$t!@oB*u&w39!@E6 ziA$4SZt%FHC3IuvkpK#3CGRv5moGBT$5yK@dnPF>nA$UIrlsJ_ZE_eg+K&0R}Um zj3rRSkwKWjpFtGJVqg%1m;w|L0rG(6F<3L$FfcOM0@*AKOqQZRw%z1FRwYF#B=wAN c^^6Sm3=Tjwj0}z-RqFBtR5=07Wnyp!07L&BssI20 diff --git a/src/cards/maumau/model/ActionHandler.java b/src/cards/maumau/model/ActionHandler.java index 02ffb61..b71e657 100644 --- a/src/cards/maumau/model/ActionHandler.java +++ b/src/cards/maumau/model/ActionHandler.java @@ -1,5 +1,6 @@ package cards.maumau.model; + import cards.Card; import cards.Suit; @@ -11,8 +12,8 @@ class ActionHandler { private Suit chosenSuit; private int ctr7 = 0; - private GameState gameState; - private HandlerState handlerState; + private GameState gameState = GameState.GAME_INITIALIZED; + private HandlerState handlerState = new Initialized(this); /** * Constructs an ActionHandler for the specified MauMau game. @@ -37,7 +38,7 @@ class ActionHandler { * @param player The player to be added to the game. */ void addPlayer(Player player) { - //TODO implement + handlerState.addPlayer(player); } /** diff --git a/src/cards/maumau/model/Normal.java b/src/cards/maumau/model/Normal.java index ae9bc86..206b498 100644 --- a/src/cards/maumau/model/Normal.java +++ b/src/cards/maumau/model/Normal.java @@ -1,6 +1,7 @@ package cards.maumau.model; import cards.Card; +import cards.Rank; import cards.Suit; public class Normal implements HandlerState { @@ -12,15 +13,30 @@ public class Normal implements HandlerState { public void addPlayer(Player player){} public void startGame(){} - public void finishGame(){ - // Logic for finishing Game ???? - if (handler.getGame().getPlayerHandler().getPlayers().isEmpty()) { - handler.setHandlerState(new Finished(handler)); + public void finishGame(){} + public void cancelGame(){} + + public void chooseCard(Card c){ + if (handler.canPlay(c)) { + handler.getGame().getPlayerHandler().getCurrentPlayer().playCard(c); + if (c.rank() == Rank.SEVEN) { + handler.increment7Counter(); + handler.getGame().getPlayerHandler().nextTurn(1); + handler.setHandlerState(new SevenChosen(handler)); + } else if (c.rank() == Rank.JACK) { + handler.setHandlerState(new JackChosen(handler)); + } else if (c.rank() == Rank.EIGHT) { + handler.getGame().getPlayerHandler().nextTurn(2); + } else { + handler.getGame().getPlayerHandler().nextTurn(1); + } } } - public void cancelGame(){} - public void chooseCard(Card c){} + public void chooseSuit(Suit suit){} - public void skip(){} + public void skip(){ + handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(1); + handler.getGame().getPlayerHandler().nextTurn(1); + } public void no7(){} } diff --git a/src/cards/maumau/model/WaitForNextTurnState.java b/src/cards/maumau/model/WaitForNextTurnState.java index 97bc700..95d568d 100644 --- a/src/cards/maumau/model/WaitForNextTurnState.java +++ b/src/cards/maumau/model/WaitForNextTurnState.java @@ -1,6 +1,6 @@ package cards.maumau.model; -public class WaitForNextTurnState implements PlayerState { +public class WaitForNextTurnState implements PlayerState { private final PlayerHandler handler; public WaitForNextTurnState(PlayerHandler handler) { @@ -14,9 +14,13 @@ public class WaitForNextTurnState implements PlayerState { handler.setRemember(handler.getCurrentPlayer()); handler.localNextTurn(n); handler.setCurrentState(handler.getWaitForMauMauState()); - } else { + } else if (handler.getCurrentPlayer().getCards().size() == 1) { + handler.setRemember(handler.getCurrentPlayer()); handler.localNextTurn(n); handler.setCurrentState(handler.getWaitForMauState()); + } else { + handler.localNextTurn(n); + handler.setCurrentState(handler.getWaitForNextTurnState()); } }