From f98d860b9713a44bea4deb5d92af299c7611f78c Mon Sep 17 00:00:00 2001 From: peet Date: Mon, 20 May 2024 14:28:49 +0200 Subject: [PATCH] added classes for PlayerSatetes --- bin/cards/maumau/model/FinishedState.class | Bin 0 -> 649 bytes bin/cards/maumau/model/PlayerHandler.class | Bin 1757 -> 3142 bytes bin/cards/maumau/model/PlayerState.class | Bin 0 -> 212 bytes .../maumau/model/WaitForMauMauState.class | Bin 0 -> 1469 bytes bin/cards/maumau/model/WaitForMauState.class | Bin 0 -> 1261 bytes .../maumau/model/WaitForNextTurnState.class | Bin 0 -> 1367 bytes src/cards/maumau/model/FinishedState.java | 18 +++ src/cards/maumau/model/PlayerHandler.java | 135 ++++++++---------- src/cards/maumau/model/PlayerState.java | 7 + .../maumau/model/WaitForMauMauState.java | 35 +++++ src/cards/maumau/model/WaitForMauState.java | 29 ++++ .../maumau/model/WaitForNextTurnState.java | 32 +++++ 12 files changed, 184 insertions(+), 72 deletions(-) create mode 100644 bin/cards/maumau/model/FinishedState.class create mode 100644 bin/cards/maumau/model/PlayerState.class create mode 100644 bin/cards/maumau/model/WaitForMauMauState.class create mode 100644 bin/cards/maumau/model/WaitForMauState.class create mode 100644 bin/cards/maumau/model/WaitForNextTurnState.class create mode 100644 src/cards/maumau/model/FinishedState.java create mode 100644 src/cards/maumau/model/PlayerState.java create mode 100644 src/cards/maumau/model/WaitForMauMauState.java create mode 100644 src/cards/maumau/model/WaitForMauState.java create mode 100644 src/cards/maumau/model/WaitForNextTurnState.java diff --git a/bin/cards/maumau/model/FinishedState.class b/bin/cards/maumau/model/FinishedState.class new file mode 100644 index 0000000000000000000000000000000000000000..21de8fb060ec57870472509f5d5895203edf3bab GIT binary patch literal 649 zcmah`%TB^T6g`&~idaQZ@j+tL6}qr1R~QpxLPA2+1j2qO6DcXhl-B5HxiWF#2l!FO z)0PbeCF$H(?>YC(ov-hYPXITlTgVBHT@?;z&P2uhoXK>keW&FG-fX0Y-AF~+f+^S< zt7ql-DtL762V?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iQFuhp);B+haX(0F@5PYi@yc!5T31b#ci0sRE(#T6YXFS{8H#4q4b50gaf#GxwfDKvZlN8X39#n}4X%C|8 zT6rUFm0Skfx2&8k-LgZNnRDUATCjd!$t4BsNc+IDa{_ISSuhK`rcd?@pVMw6o zEOEtgBEf7??}f|esI|A?pfq= zs#gDhiAILnZ1cUlU3P5F6I)kf37TS^(@^PpECg(M=|ytJR4+T6GhIK%`q5bYoLsDD z{BzhyLxuUGB4fMEX8i)JTJ*L?pfj&X*gPFXe@h8VdzHKh0a9hhG3}r?fl+o*VEbe-v=q|vbewN+MWwNP}AJjGwD><2oQ@Q`e>)SBg#xcI%5L94DqQp1YC zVBN|bWy_VBgAG{>qzrEzmYs~bW_e=!{RKB}R`rGnu16CuYBQp0M`%UWcJZ{Gb_ikm z+@dN!1Rb4>h56}1HzN^RS)zpaJCQiSg~WICzB)nwF$QQ3(i}d&tGLuqtLwNiL+!H+Y diff --git a/bin/cards/maumau/model/PlayerState.class b/bin/cards/maumau/model/PlayerState.class new file mode 100644 index 0000000000000000000000000000000000000000..4a0ce41bd19508ef5cf837f0e21f4e40d2732aac GIT binary patch literal 212 zcmX^0Z`VEs1_nn49(D#MMh3a$#G;g9{oKS-AkxpxPf5+u56DTZOf3p7Ni0caXJBDu z5Xed_OVrOv%uCnzPs&P7E@5Qg$V;s#2`MegV`N~_@YD=rWMBsB2O6j0gVR83kTN!i zO^gg&!TF^{$*FFcIjKM!kgU`L*~Z4m05lTlP6h^MpbJ+`nIU%PQs(6Bs2Hx6A{zJHTi!NVW}ejUk~Ti7RY(vs08CV7A939e+7T!9I!{ z$44TPRy};uw)wt5q(`gBBnIM=*p^h>k_{hVkuUU`F1aA(%PQ_*Q9yk~(lvLTE=xsP z#R~2T1nA&MNsTZYVc&t4WmHoIqiLlF@Bpg{9tsTpuTk*`84{yud?4XS$(#)PL`7Co zG~nc0(`sby7}izfc=!VXi62lC$?ph#<;jC#z6a?G_~@a~qn{Cg5yu*5agHbY z*-<$$oTtu-S#o1W6W@43ZW8LM)aY~!{gx%(6R zGxB~!#5q5fA7{J9O1@yYD>x{v&u(MXZu>Y(n;?b=W-*Bbrm)OQoW?Xq9zBFJ-@%!8 SapqZx7oK#Gn4j9E7XAUs`bW|L literal 0 HcmV?d00001 diff --git a/bin/cards/maumau/model/WaitForMauState.class b/bin/cards/maumau/model/WaitForMauState.class new file mode 100644 index 0000000000000000000000000000000000000000..e67812ce586d3577be083ada0eadb05032c169e4 GIT binary patch literal 1261 zcmah|+fEu$6kSIt12~9UQ316UwFPXYH+#c2X-G&-&^Fc3$L0VhI(8V$F!b_6eQ(mz zq!0aoepJ(Sm=TFl49w(Q_Fil4wfFq}_xlfkS9oDyOd#8kZnINt$u9rJR=cU};(KX% zmA1PpyZfH>l!1`I)Uo^|i?(zQi*M@3s^J+33oKud{nnOWmD|r0Fpi|tw3SPu>ZP%- z{g{$Kc-wL;@1?+c?&|P-O(0aJ;uyveHxb38z<4fSi-LMh7>EcYs+Obnx~;l$4`kg| z0yEWiL)tazT6!NGhP)%IBd~T6>p43pGvcT(-a*%OC?L0!uf?!{w1Jes%2h?0$Y7E3 z4wYB#x~_6O-!FlsT>c_<|GE^zGFA-S5J+80Vd5s{1foq>elF{_YF(=)*7RxI)@APn z!u8E96St8Qn5UMY#?$Mdd)ZNv`Z3hCfP#q)+@aTWDV_`MQaMK8hXojw8sK z8j(}-y?$Wgp>}bC%HOG$(%scUwoE+M6(!Fq;t-$CF-cAYG9yf;OH|ePxGPVBxd>BI zUsY_s-E|wPV(Af@JvS1Y`s1MaEP>B8J~Mjy_?d;cjv~hQ1a}pT@dv~TzhD+Nej@Rm zyD?1jJ;_`k%nXAW5h4I{el)IQmOJM4QCSC)yz?>Z0cN)F1Bo8yLp?0%Wu}Mzk$=42 zL;j3whAcpwnkI>zpz^69zU+W6i@Vq)k3bRk0=^FcUwXqwzW)u=dgbpP1w7+JHO-PI yi4^9CIMM@-G@jrov7b>9-Ai%#d_cCvLv5Hi(;j93usDPz23R7%5-9Z(xBmlk3>XOj literal 0 HcmV?d00001 diff --git a/bin/cards/maumau/model/WaitForNextTurnState.class b/bin/cards/maumau/model/WaitForNextTurnState.class new file mode 100644 index 0000000000000000000000000000000000000000..eef4723cae2aa3d0d1df1b66e9b24dc6b55fccc1 GIT binary patch literal 1367 zcmaiz?M@Rx6o%i^)-IH#1r($pf<>e)$ohqfMHEpYNr6U4P5d{M2`p~6WIJo*QoI5a z|Cwlw{_q04DC3#k6(km#{m9OoGw(d}p0mGx|M&@D8P5&G2-7v;?KZ8t@cFjtja}(j zuZ68v8{UR|ueN>9-BLnH0|`Rkfp{k@N4R^|=FWkvDFaEu)ix3pM;u8nSV=JUg}duW zkB}>$nfo%#DG`#3wri^;!c@LB1 zBfV|0<4D3lxlt2NRd}`@N0SM)Z#M~rcDuIogju`X$Rwu7uNA5(3}eJVmN3!jq$Wmj zg&FsxTJb$kx+*k{FqUtN5Qa-BT*ZWeaYFXYElgZPj_I_vt}h>$HG}H;%66=>-BhI> zT*nOqQ-t*Ch>2Svda@E#Nm~Gco zbGjB>K6ag-3;Yb|Cgxu@!Qb6T@wA5Q7H7U9^O;96^z%E-Yk?%MFnC25 zD*!`bHZI~4k9b|6%J3NESg83a(ySD}Ak)I-7RJ6~lJEgVJ##!;&|jl1+&r1R)xy1x z$o?OA$N^0j56E)CNqU(mjR|CsM;{li9}7IQ%xs%Xb3$7=rmdiaMW%erN(sak2Kjpl ovk~_^&uTB|#DXM;fRTU1=va*K1W!3myk$p;@eUHtg1uM%0IOCs0RR91 literal 0 HcmV?d00001 diff --git a/src/cards/maumau/model/FinishedState.java b/src/cards/maumau/model/FinishedState.java new file mode 100644 index 0000000..afdd3ba --- /dev/null +++ b/src/cards/maumau/model/FinishedState.java @@ -0,0 +1,18 @@ +package cards.maumau.model; + +public class FinishedState implements PlayerState { + @Override + public void nextTurn(int n) { + // Do nothing, the game is finished + } + + @Override + public void mau(Player p) { + // Do nothing, the game is finished + } + + @Override + public void maumau(Player p) { + // Do nothing, the game is finished + } +} diff --git a/src/cards/maumau/model/PlayerHandler.java b/src/cards/maumau/model/PlayerHandler.java index 8a145c7..70402af 100644 --- a/src/cards/maumau/model/PlayerHandler.java +++ b/src/cards/maumau/model/PlayerHandler.java @@ -4,103 +4,94 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -/** - * Handles players in a MauMau game. - */ -class PlayerHandler { +public class PlayerHandler { private final MauMau game; private final List players = new LinkedList<>(); private final List ranking = new ArrayList<>(); private Player remember; - /** - * Constructs a PlayerHandler for the specified MauMau game. - * - * @param game The MauMau game instance. - */ - PlayerHandler(MauMau game) { + private PlayerState waitForNextTurnState; + private PlayerState waitForMauState; + private PlayerState waitForMauMauState; + private PlayerState finishedState; + + private PlayerState currentState; + + public PlayerHandler(MauMau game) { this.game = game; + this.waitForNextTurnState = new WaitForNextTurnState(this); + this.waitForMauState = new WaitForMauState(this); + this.waitForMauMauState = new WaitForMauMauState(this); + this.finishedState = new FinishedState(); + + this.currentState = waitForNextTurnState; } - /** - * Initiates the next turn in the game. - * - * @param n The number of turns to proceed. - */ - void nextTurn(int n) { - //TODO implement + public void nextTurn(int n) { + currentState.nextTurn(n); } - /** - * Handles a player calling "Mau". - * - * @param p The player calling "Mau". - */ - void mau(Player p) { - //TODO implement + public void mau(Player p) { + currentState.mau(p); } - /** - * Handles a player calling "Mau-Mau". - * - * @param p The player calling "Mau-Mau". - */ - void maumau(Player p) { - //TODO implement + public void maumau(Player p) { + currentState.maumau(p); } - /** - * Returns the list of players participating in the game. - * - * @return The list of players. - */ - List getPlayers() { + public List getPlayers() { return players; } - /** - * Returns the ranking of players based on the order they finished the game. - * - * @return The ranking of players. - */ - List getRanking() { + public List getRanking() { return ranking; } - /** - * Adds a player to the game. - * - * @param player The player to add. - * @throws IllegalArgumentException if a player with the same name already exists. - */ - void addPlayer(Player player) { - //TODO implement + public void addPlayer(Player player) { + // Add player logic } - /** - * Moves to the next player's turn in the game. - * - * @param n The number of turns to proceed. - */ - private void localNextTurn(int n) { - //TODO implement + public void localNextTurn(int n) { + // Local next turn logic } - /** - * Finishes a player's participation in the game. - * - * @param p The player to finish. - */ - private void finishPlayer(Player p) { - //TODO implement + public void finishPlayer(Player p) { + // Finish player logic } - /** - * Returns the current player whose turn it is. - * - * @return The current player. - */ - Player getCurrentPlayer() { - return players.isEmpty() ? null : players.getFirst(); + public Player getCurrentPlayer() { + return players.isEmpty() ? null : players.get(0); + } + + public void setRemember(Player player) { + this.remember = player; + } + + public Player getRemember() { + return remember; + } + + public PlayerState getWaitForNextTurnState() { + return waitForNextTurnState; + } + + public PlayerState getWaitForMauState() { + return waitForMauState; + } + + public PlayerState getWaitForMauMauState() { + return waitForMauMauState; + } + + public PlayerState getFinishedState() { + return finishedState; + } + + public void setCurrentState(PlayerState state) { + this.currentState = state; + } + + public void finishGame() { + // Finish game logic } } diff --git a/src/cards/maumau/model/PlayerState.java b/src/cards/maumau/model/PlayerState.java new file mode 100644 index 0000000..713e99f --- /dev/null +++ b/src/cards/maumau/model/PlayerState.java @@ -0,0 +1,7 @@ +package cards.maumau.model; + +public interface PlayerState { + void nextTurn(int n); + void mau(Player p); + void maumau(Player p); +} diff --git a/src/cards/maumau/model/WaitForMauMauState.java b/src/cards/maumau/model/WaitForMauMauState.java new file mode 100644 index 0000000..52c48c9 --- /dev/null +++ b/src/cards/maumau/model/WaitForMauMauState.java @@ -0,0 +1,35 @@ +package cards.maumau.model; + +public class WaitForMauMauState implements PlayerState { + private final PlayerHandler handler; + + public WaitForMauMauState(PlayerHandler handler) { + this.handler = handler; + } + + @Override + public void nextTurn(int n) { + // Draw a card and proceed to next turn + handler.getCurrentPlayer().drawCards(1); + handler.localNextTurn(n); + handler.setCurrentState(handler.getWaitForNextTurnState()); + } + + @Override + public void mau(Player p) { + // Do nothing or handle invalid state transition + } + + @Override + public void maumau(Player p) { + if (p == handler.getRemember()) { + handler.finishPlayer(p); + if (handler.getPlayers().size() == 1) { + handler.finishGame(); + handler.setCurrentState(handler.getFinishedState()); + } else { + handler.setCurrentState(handler.getWaitForNextTurnState()); + } + } + } +} diff --git a/src/cards/maumau/model/WaitForMauState.java b/src/cards/maumau/model/WaitForMauState.java new file mode 100644 index 0000000..774645c --- /dev/null +++ b/src/cards/maumau/model/WaitForMauState.java @@ -0,0 +1,29 @@ +package cards.maumau.model; + +public class WaitForMauState implements PlayerState { + private final PlayerHandler handler; + + public WaitForMauState(PlayerHandler handler) { + this.handler = handler; + } + + @Override + public void nextTurn(int n) { + // Draw a card and proceed to next turn + handler.getCurrentPlayer().drawCards(1); + handler.localNextTurn(n); + handler.setCurrentState(handler.getWaitForNextTurnState()); + } + + @Override + public void mau(Player p) { + if (p == handler.getRemember()) { + handler.setCurrentState(handler.getWaitForMauMauState()); + } + } + + @Override + public void maumau(Player p) { + // Do nothing or handle invalid state transition + } +} diff --git a/src/cards/maumau/model/WaitForNextTurnState.java b/src/cards/maumau/model/WaitForNextTurnState.java new file mode 100644 index 0000000..ee44a6d --- /dev/null +++ b/src/cards/maumau/model/WaitForNextTurnState.java @@ -0,0 +1,32 @@ +package cards.maumau.model; + +public class WaitForNextTurnState implements PlayerState { + private final PlayerHandler handler; + + public WaitForNextTurnState(PlayerHandler handler) { + this.handler = handler; + } + + @Override + public void nextTurn(int n) { + // Logic for next turn + if (handler.getCurrentPlayer().getCards().isEmpty()) { + handler.setRemember(handler.getCurrentPlayer()); + handler.localNextTurn(n); + handler.setCurrentState(handler.getWaitForMauMauState()); + } else { + handler.localNextTurn(n); + handler.setCurrentState(handler.getWaitForMauState()); + } + } + + @Override + public void mau(Player p) { + // Do nothing or handle invalid state transition + } + + @Override + public void maumau(Player p) { + // Do nothing or handle invalid state transition + } +}