From 0db73af280f251b302062479307b68cbcc042768 Mon Sep 17 00:00:00 2001 From: FrederickPi1969 <pixinyudeyouxiang@gmail.com> Date: Tue, 2 Feb 2021 02:23:10 -0600 Subject: [PATCH] todo - change game state --- .idea/.gitignore | 3 + .idea/codeStyles/Project.xml | 7 + .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 7 + .../sp21-cs242-assignment1/Card.class | Bin 0 -> 295 bytes .../sp21-cs242-assignment1/CardManager.class | Bin 0 -> 3274 bytes .../sp21-cs242-assignment1/CardParser.class | Bin 0 -> 3257 bytes .../FunctionalCard.class | Bin 0 -> 271 bytes .../sp21-cs242-assignment1/Game.class | Bin 0 -> 2947 bytes .../sp21-cs242-assignment1/Main.class | Bin 0 -> 355 bytes .../sp21-cs242-assignment1/NormalCard.class | Bin 0 -> 348 bytes .../sp21-cs242-assignment1/Player.class | Bin 0 -> 4874 bytes .../sp21-cs242-assignment1/ReverseCard.class | Bin 0 -> 324 bytes .../RuleController.class | Bin 0 -> 2867 bytes .../sp21-cs242-assignment1/SkipCard.class | Bin 0 -> 318 bytes .../WildDrawFourCard.class | Bin 0 -> 334 bytes .../sp21-cs242-assignment1/WirdCard.class | Bin 0 -> 318 bytes sp21-cs242-assignment1.iml | 11 ++ src/Card.java | 51 +++++ src/CardManager.java | 82 +++++++++ src/CardParser.java | 116 ++++++++++++ src/Game.java | 100 ++++++++++ src/Main.java | 9 + src/Player.java | 174 ++++++++++++++++++ src/RuleController.java | 105 +++++++++++ 27 files changed, 684 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 out/production/sp21-cs242-assignment1/Card.class create mode 100644 out/production/sp21-cs242-assignment1/CardManager.class create mode 100644 out/production/sp21-cs242-assignment1/CardParser.class create mode 100644 out/production/sp21-cs242-assignment1/FunctionalCard.class create mode 100644 out/production/sp21-cs242-assignment1/Game.class create mode 100644 out/production/sp21-cs242-assignment1/Main.class create mode 100644 out/production/sp21-cs242-assignment1/NormalCard.class create mode 100644 out/production/sp21-cs242-assignment1/Player.class create mode 100644 out/production/sp21-cs242-assignment1/ReverseCard.class create mode 100644 out/production/sp21-cs242-assignment1/RuleController.class create mode 100644 out/production/sp21-cs242-assignment1/SkipCard.class create mode 100644 out/production/sp21-cs242-assignment1/WildDrawFourCard.class create mode 100644 out/production/sp21-cs242-assignment1/WirdCard.class create mode 100644 sp21-cs242-assignment1.iml create mode 100644 src/Card.java create mode 100644 src/CardManager.java create mode 100644 src/CardParser.java create mode 100644 src/Game.java create mode 100644 src/Main.java create mode 100644 src/Player.java create mode 100644 src/RuleController.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..c2621b8 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <ScalaCodeStyleSettings> + <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" /> + </ScalaCodeStyleSettings> + </code_scheme> +</component> \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..df5f35d --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ +<component name="ProjectCodeStyleConfiguration"> + <state> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> + </state> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2c90057 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6ac1a5f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/sp21-cs242-assignment1.iml" filepath="$PROJECT_DIR$/sp21-cs242-assignment1.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..5ebaaaf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/out/production/sp21-cs242-assignment1/Card.class b/out/production/sp21-cs242-assignment1/Card.class new file mode 100644 index 0000000000000000000000000000000000000000..06ab6b9ad0af4a07908a8de0da93e50ff6186042 GIT binary patch literal 295 zcmYLDK~BRk5S&e%goZ#%;RD=&19?CZ7b>Jm5gdwocU-Hu3bABT{>2H20}tR)h%q2> z@XXG5XLmop-ai1$a8e>cT0m9EkP9YT{i5qm_nZ2@-C8pU@+;T7;aZTMov#Y)3Dk`a zYe8mw=YwF{{D+o9aQ$Y+lwr?eE|5hG__Y;`8`s;r-BWABgKj%I)5aU!t#oiv|Cwrd zbkCg7#5EjMF8wYTd+TCi6wS-HP@SUS@!(S!p=2f4NA<(J4mtG!RZSLhcJT&zWs%^J V7{7rOV`BB&fC-MMco#9j@i&E8HQN9H literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/CardManager.class b/out/production/sp21-cs242-assignment1/CardManager.class new file mode 100644 index 0000000000000000000000000000000000000000..974ab506a519a9115a45ae055c217c3654e2407b GIT binary patch literal 3274 zcmbtXTX)>l75<LLL}QI6aqMIg$0aC<1NJnINw@@JCo~x+FlC$zb{q(_RGyJ-#Tsdl zG)@h)&^ACX(9%1leWDM%^nr45D6G}h=l%c||ABvymDTp!lEyPr3@`Coqa&TO&)(nu z_T?P^`#+!j6Tl??tfL1R4ZQ~Lz!ru6tJbPD;ac9(#QBA*b~RGiGUa$qbW$NRIySE% ztDu*xpmxCuLOal*A=8H(3=Me$Td_?cC(ARIXD!(Qw>M%z1*6j5HmP&Vb^`-qb3pVv zmg_uk#}bZf%kmBbJ7qcF2plhJt!UV#Fc_n3MvgmiDhRB#iW5dU3JH=u28Qtsg=|$& zQklZe$|f6#VK45|U>ewm{R-RLu9v;Yj=^iImfN(?FDev9%VUX_n4DCCItmyua1eKs zAFEcQt<es#gu}_PD>_CorlDxyn>a+FHlC92y5!mMy--05mz#@=0(mf16FVvXO^(fr zvBL%?a4#jD@JziCt;J!v(ubqCPs9BN9>9ZLQJh^1BfCy1zsXppL^%G$1tE1d3T&%B znZ-j2XLS9<?f>aGj!6wu22Ow}lLV^U9I?j{b-n*1i)b8gDfRPP22SC$LT|{lh@C7C zFk`0;oWWUzU3F{4F8N;7iY`0RGT*|;@*+~WvpZ0!QlaiK17&=hx|VFAqFXMFl;lLk zz>JvAlA(Etza;s20~f?_E>363#`1I)Pms6UC+&o;XECQRbvvrEm{&M3w`>QtY4PXz zrWAnb+KZ9tcxJS0n+;aOzAT<pI93a+YvP4z2Z0|PH_Kk58JS+QzF-Gty%|R40`-^; zKV)sL+SCx2gcRl#15XP-IZBI)3N6U|cMN<N&noP0=?)hIzdr4Rf+H!!-5aEL7jIlg zmVpISr3jh}lJN>VM$4_LYuAB<(w26`svPR9l6EDfIkarR!Bw^(7Un6}{TlHrIk>26 z@C^9Ub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B1(DxJCD1-SUMm!@BQ~2`s<2VZn-18H% z*~77b>wL@L6-r93Bx_O|$=WrprMa^8mRwZ}Y5BZL5gxUC3Lk4UD#rGu9yVGY&UE{B zNPJ5&cWb=iH1oB@s7}Y&%|yut;(aON?aXk&*%RZGVoGKNXHw0ta_%+!luv<khI%B0 z^R!MVaS4U(N|k>&fC?#{*+?M@Z<x*FXE9M3{G4(<_yu0)n5FVJ`1>t>&o7;Cf52OK H8$<sC6}<U6 literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/CardParser.class b/out/production/sp21-cs242-assignment1/CardParser.class new file mode 100644 index 0000000000000000000000000000000000000000..91bfe36bc32cfed6704cc7ea4288d3f3586384d5 GIT binary patch literal 3257 zcmaJ@YjYFV8GhDUX;<=sg#cqk)Ug{#Y++++(uB$c12Pv8*(R2Q<0cJRON+dCy{qo7 zOx^qa-lhp(GM#>dDKni;ha|;mlA+V~WAcacsq{I!Yk3`%j;*8fp7*@B=REH@`sBYK z{S&|xZfDSggaTPZ5-ADUoBD=6Vd-{rVt(bOQTHXJPMfyrpOKIl8NHT<inM}^hF)kA zGG*OuT-9CAaA`aD^6dEw3)ipmQ=YHRFG!Fo!eFn4KCxR{oL@Xw4Rtl4*ry>U6xm?= zg_-N+a|<)q=|;f;3HyRv+P-N`T-LqSS-q9Pek6q9Aq@k_OGwup%W-E+k>~#EWBaEv zDB!SyFKHOWliMDH>MFKxG)30RhHkZu`5O}YM=GPCkNA!$6~hu_+p!H1{wWPdaFk%Q z+KhQ>BxVo-Hud;Q+-tN+#WVEb8Vwbr5|T~VFl-ga7-)srs2C^in}%gMw^U3>Q0LAK z1^*cq{}m0BI4NOIO8~!QS`Bdu5)SUpzvjE9-6RAmzN+ClVUZ0i$^tVZFj8?!LN7gg zo9jcj=t)IM9OTZzjH};zRuq0(!wV2BXc{d1=`MwLDO15&y4&GYn3Ib05+KfIM#BYM zWPPUXUlZpLu&kouGADL>UF^A{;YC!r$9F<=2?s{vv7$m%%+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!)j!97X#t!z#Z((&6bk6d7-XEiyd|Uw)!QZE{5v<j(T8Q zT@&hFkxB05QmQzfPv%owSlWSU0S8#xbEL=fWbY}S&J>Q45)(K>0H(2kvv>{X3D69D zKGomBCA^6WZj&;9L=}I-9Nxn`*<Hg!EaKl-3LtKgTqiLK7am#Q6TonGyEA*QGb6N} zqxdvBiZuR1D~$&+fcMd+mjrYB3pQ|z$MKMK4gDR(pYbhfQxMFVh4P3=DhgCdQZTKc z5RB8nCFv23;u^;1`rzQ;BhKQAZ4(CPFN27JFEIg`A=1aj#y`TVfWWXP;JN5<zUo2U z#c)%no^+7A(5HipMeC%o8Pp@;+r%@x9qvUW8$XtNohS6h>{w!QZcLsm$z#dMQZn@r z)60qR+OnLNYs<-ek_Vel?WFJo0pPRFtIHs0;%aKL{Y-NIW{}opmI!u0*w142U8caF zR6OkO;rlE^BfKHZ`*1i&Ri=kS0k}!}N#F<ECrbSxeiSABBJD&$>_A=uip(Msf2AC@ ye+Y{k>o~0wUyF5I5<Qu-{NaWl)3gUa!B6?EGQ`jL`3-(YDZ|<C@dvz({Qm%ZsJx^A literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/FunctionalCard.class b/out/production/sp21-cs242-assignment1/FunctionalCard.class new file mode 100644 index 0000000000000000000000000000000000000000..a4e16eae874d691483e7e1c6a5672e770310e5f0 GIT binary patch literal 271 zcmY*T%MJlS5UgQX)^mM<BMy83aglJ@xU9JMt_dS+Hd(X&%Sqzk1ALU|!9^dcyQ?bI z{e0aY0Hz3hlu-5{o2Z~FAQzPH1gbM_w4Do-2g9w0nm~J5n8fPLQ2MpVMYdA{olqOK zE>5w^Hx#GL^ujEmbW6E*`;V0Npw9x`@IPkC0m*^PUajb)B1@J7{3t8(L@l*TtGjFC xBV9=L;qkMs9P+zhnWqVN;h514;`)(&MkfOS8jQ`afqM&(K$}%C*I_K7`v$)1Gywnr literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/Game.class b/out/production/s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u(k^xOemBP)t) zjODeB>RQ7{F}I?9y4KKN%+<BMr@#f~2QX7>NF}M}HCV-*ufHX~kl+x1V}fX8Fvnf< z5*4w)wk~26mngj}{3Y-*=J5&~au{H7OM0VR@l!25Hn7Egh@au-nvM{^pp}5okw-eS z`*8OhrFV}*k)Vkx|Bw(hZc9^7?{0B*n5*Pp_g&ne62reBl5!0#K-se30g%Ldd?)Zr Z{EF{1XMfHAzr{!TtAUU4DSnSf{tHy)s<Hq8 literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/Main.class b/out/production/sp21-cs242-assignment1/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..b12c256cfd7b300357d11523dd86ac945017b47a GIT binary patch literal 355 zcmZut!AiqG6r4?y#>8s174P0!1@i$BFNL1cdZ^^m(<Ux)OS*wI^}jp`9{hlQlsFp& zMO@e!-g`6i*xi4;y#q*b7Q;g?gg-!lzQD;wKFg$*rb_OLjVfD#{*5-ey%p$9rg?}1 z0e>O2A<dcxB{0miQOn)7Q1)IHH9MoMDP^5Yt6lxw^xH@M#I($rQ@XcZ$oXWQ{p?(| zR+}oF=A27gQ9u4?ED*1noh{W|yLFLEymleDK*;yF<3YF=5hGR!S&)OvSBRHx924Cb kyobcWmw<f4D#9^_>^SpPr=jkzG5BTV*Wt7ij))${pPJP@<p2Nx literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/NormalCard.class b/out/production/sp21-cs242-assignment1/NormalCard.class new file mode 100644 index 0000000000000000000000000000000000000000..c0d199f37e0e3d28ce2f7f992f7f3fd0890ee328 GIT binary patch literal 348 zcmZWkyH3ME5S+CgJ2r-Zc~lfB6CUvg7-*1?BAwD0xxYA8ICSwzhr@qSAyM!Fd=z5O zM53VC-I=@Dnf?0y_ykbkG=T>{LXcvBkPzHUyCQ@)s#V<`!Jka42tz`$Fm@yL?z!D= zmW?IQoNzV~&+=8~TDI%F?5t|n#e7=1U1rq~MnbjCq8B{MrDi4*rk1*rRyn*QgYHSa z5K{4HR1gNW(T0t({~nyFG+SFY56Uf#U9_1?f-xe#3g8Hck@OR<!X7gzqmsMNJ-&Dc wU5fMDHwGT|xn?W@uDD(!#0*2^IACV{E5Hbcj97{z{!9JjEIgi%8F@JQ0Wz~dPXGV_ literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/Player.class b/out/production/sp21-cs242-assignment1/Player.class new file mode 100644 index 0000000000000000000000000000000000000000..78a74895f68428c4acc365e4b6f881ba2a12fb13 GIT binary patch literal 4874 zcmbtY`&%646@I^EVVB(@tmI}w&`Hb%2!e?*MhI9WQP+}-f?z^vo$QV<VVT*^&W2#^ z-AixYYO6+VjkYyj(pIAqo3z&6TYIzj>(l?B{k6~IlbXKgn*kP0`-}NucILaBbKdv7 z=X@V|{jF240_eiuQ;4A|fw+Nc)F@;QT8FHTg5{2N>^X4I&IJlJ+a1>ldK9XfTZU?p zL~Q~o18EqX+gq@vZC@c-)Gyf`3M!kxB8A1;QaNx69lgG9P4_#cAcZ<qiHY+JG+?np zb<XnhC55H^=UCm9z*2?t=4S?Smh0MnEtcc_1XdVWiN*yX4@{Q=dr~3hxN|lguOsUg z%fUe4+ty@P3QN!=U@uTOzd3aKwk0h?DTZhoSS^e+6n$^981#*MUdisw1&-&6jf)Jd z#X16a?ZZL8<Jt;Knp;A9nm+n-+%fvwfaU~R476h7EE>Ha>jw5%$erbvY<@E4D56RW zE#&j!Sw8i|&civoD1itQ9R@DJCT7Pgi-9>rd+B}_bP|^;n0pJhRkF>TMq*kTig^ps znVU?{H#etn8MY>Hxq)rCV%8zKsj#GwD2m;J@O!RUHFaGEwxe6Y2z~5v?Y_ypLTz*Z zHP)ov)shu{uQc$UibaD{9v8{PRR;RB6t$;55lGg()^hVn>{Qr0JnrPiP0@`x<&_J0 zbJ{DL1!uxG1J4u{UO5ZYk+hq^I3at!Z<mUmn`cVGy>5B(fbF-pw~Nbb3|xyWGdN}k zS}cK`7spvQZy(meXUKJUuYrE-;y0HG{%mEw!*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@7by9AB0~2sG9>EhoiB@i>UzztHr7ErPwCfp#wFSh>u8%E#iFJN{}ZT_ ziI0X8BK-_SzH(0b?Gzx8=hNoQIOhtSb(q3~6#E3$!)0<k5?y36eGRII317~TUe&2v zMM^~IqP*S+Xc}9!sKwhRE&doSHAXu^QOD2H5&z#HNo7;iP!#nUq}8HY2Kn7N>}~u~ zG##swEW~uZ*65MjbTHCFWISY8$wi+d(yx4uN>G`N%>KuB3n3TJ;Pzo@RiTC#Y31EP zICr8RcU5F8GncUpUPDg%$l!ZAV>JZ)eP+K3KcFS?AC5f55hZ_kM*jc7oW;1J9H!z^ zk6=_%@j0e~zfpcp;U2K+w^VI!j7FZsMou@zZ>AJwsBuoZGx+=|d{HmIT`9IWG50Vx zAH!mKeI&Hp@ECvRL57mOn?c{hHg_+xdLMIgKgD_<Mfw19{~&Yz5CR<01W2D=&sO(C z4UOSPR7lp+h@ZiF^(Ho_>WT74_%Rm?*B$(lJXA}>&-0}+QAaBhRUKIikD8xw-Re2Q zhWRB%nr6G#mm@$&qu(bZV4?A4x+b1xj-O$u&$9D8N7){)aMlz#OX8<<PA;Mo`IkNo xk7w6cU&KM-N>vD}nu+`w$6|OLKj-fvzWstLeyg9q#~(SC;`g8M7yJz?{tM*Dk-Go@ literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/ReverseCard.class b/out/production/sp21-cs242-assignment1/ReverseCard.class new file mode 100644 index 0000000000000000000000000000000000000000..fc60d312aacd23517ab823ac46b779f96d1751e4 GIT binary patch literal 324 zcmZWjy-or_5dH=ZPL3acS}7<&6L|oP4GA<C3o-P=F@Yt=Ub5`*UREX+K7bEJoE1Vy z++t?FzuEaYe0>8L;Wj}9)fiC=HPi{6Nog~03d{MJ-I7p$HrDtTLbX4b$G9Ri-()Xt zCr3RR7fT^rr^d=_xm}2R=S8l}U0P(E&)J!PPh{lRW=CkJ7du9p&em*KGUctzJbO(i zv!ZmFOiWnS2wy#Ic+cn|)`P<fRZoV>It{f`U>-g}AAfS9HORm{np#^&gZ8!}pmPpC UDhj@T!R|$nPC>m^trgt-0u*{S^#A|> literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/RuleController.class b/out/production/sp21-cs242-assignment1/RuleController.class new file mode 100644 index 0000000000000000000000000000000000000000..34888e1961552e77bf1cf5ad04da7afffd917e93 GIT binary patch literal 2867 zcmZ`)T~ixX7=D&~>?SM?ga+IeZ0#orSQHDT0kITpi483liY>L;B`mP*lF-ejNUy!s z@xpP2j^6Z!n>wRb=#0)dUU=n?@Gp4pjMnFzT>>fTBy;wh_k6t1`@GM2&!7MO@*995 zJc^?MAr)aA5kwU<-!mVYy^dL2>b*99&nkEdqQiF4_C^$hy3(^6G<HnKi6M?g6}pZl z98hrJdd0EEN=45tIgaHjXf0G+*D89Wj#FB*7RE|WiPmI(_xx$kwTnwb;-F?7E#j1e zwVSS1R^}~NENInnu+D<%^_BUOgwm#?9j_7Ws_B-6e?32Dx(icsG!(}n99GexqZ6+y zi0@7*Xp}pIB{!}h)s;){$0+t6)$s<75o2}zxK%E=_Nr%>iV9A5?cbKZz26pRG$(YN z#3_<iShfoHM?KG-G`+%d{X_O2k)G4gr69IuI}78kxpp>=47yeH=y(%nYI5jvOj@i5 z71Jq;`1YLVXLu+*CqTWW<8AaQXpx}gxw&%QS~4AS)Rmud%yrA<S`B9vG+Z6kFrXk@ zEEO#cgVaQMeMLi-onmDrj$yp3VnoM#xIpjzW(C@k<q4(<q`fQPx#HPQ@2KmV>v_BE zF;y2area*j`?y3INxjsrq1&?k$dZE0iS-jYa`=E_9=|VzL69o)jBQtaxuRz+S#BIx za8<`O;Y+iN-mK|VERpUIy^NI>=p~W2i<U3N8FSvDC7CZ3OlQ_~Z7~jvVQ<-HT+R8~ zn=nN7>@ttF7X%9mnyOsp=F)RQv65N3-{F|HLLf&a#|@R$1=F)~i}DZ!3O6Ohf*Sor zU8`Ji7=CLV(J6=&{0kWN)>j#UTHsaX?c~Hm0gYa!J+p9s(p;6{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*vmlf)CKaeK9GHkm;^Ha3LxU<@sY(^wVEE6tg*)aibJ=a UW9k`Ff?{P)g2EhqCX=@QKO&tcdjJ3c literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/SkipCard.class b/out/production/sp21-cs242-assignment1/SkipCard.class new file mode 100644 index 0000000000000000000000000000000000000000..c02cd7f71a286e5ad19fc39853c9ed34c6c78034 GIT binary patch literal 318 zcmZWjJ8r^25Pbs<28VwEZOVKkasUtw5;PW#5&d9RVZp4Cv(CM!B2jRF94g8z5QM}Q zGxL74^YeQ+0_dX^pn#$euZjnh2=#GpVyjcb$%wNhp)}A&+aaO&{4)1ZCX}O%-kn8n zlr9ya5o)8R`F5eQ87~rH+F=@VGUrS?d?7u%(w~GN{9n+QXuM+cp(ealk!35<AWHKr zR%7k<RNOzkHGeUl;LEA*xhls(WSQQjlVe`LLHm;&NOdyM!K2jb*&w|p2&iAfZ-Sif QF4(;Z(j_R@inV~|A4Q=wTL1t6 literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/WildDrawFourCard.class b/out/production/sp21-cs242-assignment1/WildDrawFourCard.class new file mode 100644 index 0000000000000000000000000000000000000000..9e4b901ea9654b97769f1f8bc75fdb65fca62b70 GIT binary patch literal 334 zcmZWj%}&BV5dM}{iWL!g0uGq?ljsA~c)^rQ!v#{#L%WeRWt*&9eJ)QX9(({E$~Xgr z7~R7+JM;a_Y`#Cg03<k%(LxX*?BWP*g<jg&!kgMsH6~XowC{~I{y`zQyvieV6#5HO zm5+|z(z<awQ8=zkt#FnZtEbI+sok8G6;B3PT~L*iGt%#ep<kI7;r<3C98s*uKIsXq z^~{s!h<L_p3Y{9sJC=R7&-6+dBI48K3G(q^ntyj(l}xTbpx(E1%qTQ4!U<z{C*XR@ Z9nd?NZ@3fPKjXzOquLw!T9&rZ{{eBoI?Vt8 literal 0 HcmV?d00001 diff --git a/out/production/sp21-cs242-assignment1/WirdCard.class b/out/production/sp21-cs242-assignment1/WirdCard.class new file mode 100644 index 0000000000000000000000000000000000000000..4a01bfee7641af2b98a6d1d4dd195e295e5540e0 GIT binary patch literal 318 zcmZXOJ8r^25QhH&gNef<$qAA!fRr47hz1E7D-DR$gS`ri%v##4xffL=3J$=b5VO35 z#1`}V|8I77`^^?W56=-wD2E8@sGv${4hxewog2;uY*Rw@OB?O_gz|fP8lpz1{b-w> z#9)x8iqML+QQyUKrtE}gnM_{dJmGB0R{Q=u4BTA*5u*6ApeJZDXY;E@yi{YyPS9wa z7dBBt?e{$Re?AtxV!R@hQ~mQ%j)llleM%-j>HLG%M>&${WeD^rv3@d0Zb%0-uW(m7 S@4ExvZa_MNa;;cPcsc+`hBR#e literal 0 HcmV?d00001 diff --git a/sp21-cs242-assignment1.iml b/sp21-cs242-assignment1.iml new file mode 100644 index 0000000..9465dd8 --- /dev/null +++ b/sp21-cs242-assignment1.iml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/src/Card.java b/src/Card.java new file mode 100644 index 0000000..cc897fc --- /dev/null +++ b/src/Card.java @@ -0,0 +1,51 @@ +import java.util.*; + +public abstract class Card { + protected String color; + public int cardID; +} + + + + + + + + + + +abstract class FunctionalCard extends Card { + abstract void changeGameState(); + +} + +class SkipCard extends FunctionalCard { + void changeGameState() {}; +} + + +class ReverseCard extends FunctionalCard { + void changeGameState() {}; +} + + +class WirdCard extends FunctionalCard { + void changeGameState() {}; +} + +class WildDrawFourCard extends FunctionalCard { + void changeGameState() {}; +} + + + +class NormalCard extends Card { + protected int number; + public NormalCard(String color, int number) { + color = color; + number = number; + } + + + +} \ No newline at end of file diff --git a/src/CardManager.java b/src/CardManager.java new file mode 100644 index 0000000..ee016b5 --- /dev/null +++ b/src/CardManager.java @@ -0,0 +1,82 @@ +import java.lang.reflect.Array; +import java.util.*; + +public class CardManager { + private ArrayList<Integer> cardPile; + private ArrayList<Integer> discardPile; + private static CardParser parser; // only for debug purpose... + + public CardManager() { + parser = new CardParser(); + initializeCardPile(); + printCardPile(); + } + + private void initializeCardPile() { + cardPile = new ArrayList<Integer>(); + for (int i = 1; i <= 108; i++) { + cardPile.add(i); + } + Collections.shuffle(cardPile); + } + + + public void printCardPile() { + if (!cardPile.isEmpty()) { + System.out.println("\n\n==================================================================="); + System.out.println("Current Card Pile has " + cardPile.size() + " card left:"); + for (int i = 0; i < cardPile.size(); i++) { + System.out.println(parser.parseCardID(cardPile.get(i))); + } + System.out.println("===================================================================\n\n"); + } else { + System.out.println("============================================================"); + System.out.println("There are no card left in the pile!"); + } + } + + public int numCardLeft() { + return cardPile.size(); + } + + /** + * draw a certain number of cards from the card pile + * @param numToDraw total number to draw. Should be positive integer + * @return an arraylist of card drawn from the pile + */ + public ArrayList<Integer> drawCards(int numToDraw) { + if (numToDraw < 0) { + System.out.println("drawCard error: Input number must be a positive integer"); + return null; + } + + ArrayList<Integer> cardsDrawnFromDiscard = new ArrayList<Integer>(); + if (numCardLeft() < numToDraw) { + int numToDrawFromDiscard = numToDraw - cardPile.size(); + cardsDrawnFromDiscard = drawCardsfromDiscardPile(numToDrawFromDiscard); + } + + ArrayList<Integer> drawnCards = new ArrayList<Integer>(cardPile.subList(0, numToDraw)); + drawnCards.addAll(cardsDrawnFromDiscard); + cardPile.subList(0, numToDraw).clear(); // erase the drawn cards + return drawnCards; + } + + private ArrayList<Integer> drawCardsfromDiscardPile(int numToDraw) { + ArrayList<Integer> drawnCards = new ArrayList<Integer>(discardPile.subList(0, numToDraw)); + cardPile.subList(0, numToDraw).clear(); // erase the drawn cards + return drawnCards; + + } + + /** + * @parm ID of the card to be inserted + */ + public void insertOneCardToDiscardPile(int cardID) { + discardPile.add(0, cardID); + } + +} + + + diff --git a/src/CardParser.java b/src/CardParser.java new file mode 100644 index 0000000..b5d740b --- /dev/null +++ b/src/CardParser.java @@ -0,0 +1,116 @@ +import java.util.*; + +class CardParser { + public final int NUMBER_PER_COLOR = 25; + public final int TOTAL_COLORS = 4; + public final int COLORED_CARD_NUM = NUMBER_PER_COLOR * TOTAL_COLORS; + public HashMap<Integer, String> colorDict; + + public CardParser() { + colorDict = new HashMap<Integer, String>(); + colorDict.put(0, "none"); + colorDict.put(1, "red"); + colorDict.put(2, "green"); + colorDict.put(3, "blue"); + colorDict.put(4, "yellow"); + } + + + /** + * Given ID of the card, return its content as a string as "color function" - e.g. "green 1", "none wild" + * @param cardID a integer from 1 - 108, unique id for each card + * @return + */ + public String parseCardID(int cardID) { + if (cardID < 0) { + // invald cardID + return "NA NA NA"; + } + + if (cardID > COLORED_CARD_NUM) { + return parseWildCard(cardID); + } else { + return parseColoredCard(cardID); + } + } + + /** + * helper function for parse for cards without colors + */ + private String parseWildCard(int cardID) { + if (cardID > COLORED_CARD_NUM && cardID <= COLORED_CARD_NUM + 4) { + return "NA sym wild"; + + } else if (cardID > COLORED_CARD_NUM + 4 && cardID <= COLORED_CARD_NUM + 8) { + return "NA sym wildDraw4"; + } + return "NA NA NA"; + } + + /** + * helper function for parse for cards with colors + */ + private String parseColoredCard(int cardID) { + int colorID = (cardID - 1) / NUMBER_PER_COLOR + 1; + String color = colorDict.get(colorID); + Integer cardTypeID = cardID % NUMBER_PER_COLOR; + + String type; + String content = ""; + if (cardTypeID <= 18) { + // case 1 - 9 + type = "num"; + cardTypeID = cardTypeID <= 9 ? cardTypeID : (cardTypeID - 9); + content = cardTypeID.toString(); + + } else if (cardTypeID > 18 && cardTypeID <= 20) { + // case skip card + type = "sym"; + content = "skip"; + + } else if (cardTypeID > 20 && cardTypeID <= 22) { + // case reverse card + type = "sym"; + content = "reverse"; + + } else if (cardTypeID > 22 && cardTypeID <= 24 ) { + // case draw 2 + type = "sym"; + content = "draw2"; + + } else { + // case 0 + type = "num"; + content = "0"; + } + + return constructCardDescription(color, type, content); + } + + + private String constructCardDescription(String color, String type, String value) { + return color + " " + type + " " + value; + } + + /** + * Given the description of one card, parse its color type and content + * @return a string array (String[]) : {color, type, content} + */ + public String[] parseCardDescription(String description) { + String[] results = description.split(" ", 3); + String color = results[0]; + String type = results[1]; + String content = results[2]; + + String[] output = {color, type, content}; + return output; + } + + /** + * judge whether a card is a wild card - that is, whether user can decalre a color + * @param cardID id of card + */ + public boolean isWildCard(int cardID) { + return cardID > COLORED_CARD_NUM; + } +} \ No newline at end of file diff --git a/src/Game.java b/src/Game.java new file mode 100644 index 0000000..23d3a9b --- /dev/null +++ b/src/Game.java @@ -0,0 +1,100 @@ +import java.util.*; + + +/** + * The class for recording Game state + * Organize the interactions among all other classes + */ + +public class Game { + private static CardParser parser = new CardParser(); + private static final int INIT_DRAW = 7; // every player get 7 cards at beginning + + public RuleController ruler; + public CardManager gameCardManager; + public ArrayList<Player> players; + private int currentPlayerID; // playerID starts from 0 !!!!! + private boolean isClockWise = true; // if clockwise, next player will be the element in player list + + + /** + * Default constructor for Game object + * @param playerNum + */ + public Game(int playerNum) { + gameCardManager = new CardManager(); + ruler = new RuleController(); + decideFirstPlayerID(playerNum); + + System.out.println("Loading player information..."); + players = new ArrayList<Player>(); + + // playerID starts from 0 !!!!! + for (int i = 0; i < playerNum; i++) { + Player player = new Player(i); + player.drawCards(gameCardManager, INIT_DRAW); + players.add(player); + } + } + + + /** + * Randomly decide the start position of this game + * @param playerNum total number of players + */ + private void decideFirstPlayerID(int playerNum) { + Random rand = new Random(); + currentPlayerID = rand.nextInt(playerNum + 1); + } + + /** + * decide the ID of next player + * @return ID of next player + */ + private int decideNextPlayerID() { + if (isClockWise) { + return (currentPlayerID + 1) % players.size(); + } else { + return (currentPlayerID - 1 + players.size()) % players.size(); + } + } + + /** + * Run one round of UNO + * very import function ! + */ + private void runOneRound() { + System.out.println("Player " + currentPlayerID + 1 + ", It's your turn!"); + System.out.println("Please choose one card to play..."); + Player currentPlayer = players.get(currentPlayerID); + int chosenCardID = currentPlayer.playCardWithCmd(this); + currentPlayerID = decideNextPlayerID(); // update the player for next round + + } + + + + private void changeGameState(String color, String function) { + // change color + if (color.equals("none")) { +// currentAllowedColor = "all"; + } + + // handle function + if (function.equals("skip")) { + currentPlayerID = decideNextPlayerID(); + + } else if (function.equals("draw2")) { + Player nextPlayer = players.get(decideNextPlayerID()); + nextPlayer.drawCards(gameCardManager, 2); + + } else if (function.equals("wildDraw4")) { + + } else if (function.equals("reverse")) { + isClockWise = !isClockWise; // flip + } else if (function.equals("wild")) { + + } + } + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..0003900 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + + + } + + + +} \ No newline at end of file diff --git a/src/Player.java b/src/Player.java new file mode 100644 index 0000000..6a04fa1 --- /dev/null +++ b/src/Player.java @@ -0,0 +1,174 @@ +import java.lang.reflect.Array; +import java.util.*; + +public class Player { + private static CardParser parser = new CardParser(); + private ArrayList<Integer> cards; + public int playerID; + + + public Player(int ID) { + playerID = ID; + cards = new ArrayList<Integer>(); + } + + /** + * FOR CMD LINE DEBUGGING + * When it's this player's turn, the player must pick one card to play + * @return the ** cardID ** of the chosen card + */ + public int playCardWithCmd(Game gameController) { + // instruct player to take a move + Scanner inputScanner = new Scanner(System.in); + boolean receivedValidInput = false; + int action = -1; + while (!receivedValidInput) { + promptChooseAction(); + String input = inputScanner.nextLine(); + try { + action = Integer.parseInt(input); + if (action == 1 || action == 2) { + receivedValidInput = true; + } + + } catch (Exception e) { + System.out.println("Please choose action from 1 or 2"); + } + } + + if (action == 1) { + return actionOneCmd(gameController); + } else if (action == 2){ + return actionTwoCmd(gameController); + } + + return -1; // user did not play valid card + } + + private int actionOneCmd(Game gameController) { + + int cardID = -1; + while (true) { + printCardsInHand(); + System.out.println("Which card would you like to play? Please input the corresponding card number..."); + + int chosenCardIndex = -1; + + while (chosenCardIndex < 0) { + chosenCardIndex = getInputtedCardIndex(); + } + cardID = cards.get(chosenCardIndex); + if(gameController.ruler.isValidPlay(this, cardID, true)) { + // maintain list-cards and discardPile + cards.remove(chosenCardIndex); + gameController.gameCardManager.insertOneCardToDiscardPile(cardID); + break; + } + } + + if (parser.isWildCard(cardID)) { + // to implement + } + return cardID; + } + + private int actionTwoCmd (Game gameController) { + drawCards(gameController.gameCardManager, 1); // draw new card and add it to cards in hand + int chosenCardIndex = cards.size() - 1; + int cardID = cards.get(chosenCardIndex); + if(gameController.ruler.isValidPlay(this, cardID, true)) { + cards.remove(chosenCardIndex); + gameController.gameCardManager.insertOneCardToDiscardPile(cardID); + + if (parser.isWildCard(cardID)) { + // to implement + } + return cardID; + } else { + System.out.println("Sorry, the newly drawn card is not playable :("); + return -1; + } + } + + + /** + * helper function for playCardWithCommandLine + * parse the integer inputted by the player + * @return the ** INDEX ** of card in list cards that user chooses + */ + public int getInputtedCardIndex() { + Scanner inputScanner = new Scanner(System.in); + String input = inputScanner.nextLine(); + int decision; + try { + decision = Integer.parseInt(input) - 1; // -1 because we want the index in cards list + } catch (Exception e) { + System.out.println("Please input the number corresponding the card you choose!"); + return -1; + } + + if (decision < 0 || decision >= cards.size()) { + System.out.println("The card you chose does not exist!"); + return -1; + } + return decision; + } + + + /** + * FOR real playing scenarios with GUI + * When it's this player's turn, the player must pick one card to play + */ + public int playCardWithGUI() { + // not implemented yet. + return 0; + } + + /** + * + * @param dealer a cardManager object that is responsible to deal cards + * @param numToDraw number of cards to draw + */ + public void drawCards(CardManager dealer, int numToDraw) { + ArrayList<Integer> newCards = dealer.drawCards(numToDraw); // Initial draw + cards.addAll(newCards); + } + + /** + * print all cards that this user has + */ + public void printCardsInHand() { + if (!cards.isEmpty()) { + System.out.println("\n\n==================================================================="); + System.out.println("Currently have " + cards.size() + " cards:"); + for (int i = 0; i < cards.size(); i++) { + System.out.println("[" + (i + 1) +"] " + parser.parseCardID(cards.get(i))); + } + System.out.println("===================================================================\n\n"); + + } else { + System.out.println("============================================================"); + System.out.println("You got not cards in hands! Congrats, you are the winner!"); + } + } + + /** + * getter for cards (private attribute for tracking all cards owned by a player) + * @return + */ + public ArrayList<Integer> getCards() { + return cards; + } + + + /** + * prompt player to take action current round + */ + private void promptChooseAction() { + printCardsInHand(); + System.out.println("Please choose you action this round:"); + System.out.println("[1] Play a owned card"); + System.out.println("[2] Draw a card and play it if possible"); + } + +} \ No newline at end of file diff --git a/src/RuleController.java b/src/RuleController.java new file mode 100644 index 0000000..2447ccc --- /dev/null +++ b/src/RuleController.java @@ -0,0 +1,105 @@ +import java.util.ArrayList; + +public class RuleController { + private static CardParser parser = new CardParser(); + private String currentAllowedColor = "all"; + private String currentAllowedNumber = "all"; + private String currentAllowedSymbol = "all"; + + + /** + * Given a card played by the user, judge whether this play is valid + * that is, all cards must be played following the rule + * @return whether the play is valid + */ + public boolean isValidPlay(Player player, int cardID, boolean updateIfValid) { + + String cardDescription = parser.parseCardID(cardID); + String[] result = parser.parseCardDescription(cardDescription); + String color = result[0]; + String type = result[1]; + String content = result[2]; + boolean valid = false; + + if (checkAttrMatch(currentAllowedColor, color)) + valid = true; + if (checkAttrMatch(currentAllowedNumber, content) || checkAttrMatch(currentAllowedSymbol, content)) + valid = true; + if (content.equals("wildDraw4")) { + valid = checkDraw4IsLegal(player); + } + + if (valid && updateIfValid) { + currentAllowedColor = color.equals("NA") ? "none" : color; // wildcard played + if (type.equals("sym")) { + currentAllowedSymbol = content; + currentAllowedNumber = "none"; + } else if (type.equals("num")) { + currentAllowedNumber = content; + currentAllowedSymbol = "none"; + } + } + return false; + } + + private boolean checkAttrMatch(String legalString, String stringToCheck) { + return legalString.equals("all") || stringToCheck.equals(legalString); + } + + /** + * Check whether a player have currently allowed color when attempting to play wild draw 4 + */ + private boolean checkDraw4IsLegal(Player player) { + ArrayList<Integer> cards = player.getCards(); + for (int i = 0; i < cards.size(); i++) { + int cardID = cards.get(i); + String cardDescription = parser.parseCardID(cardID); + String color = parser.parseCardDescription(cardDescription)[0]; + if (color.equals(currentAllowedNumber)) return false; + } + return true; + } + + /** + * Getter and Setter for Allowed number + */ + + public String getAllowedNumber() { + return currentAllowedNumber; + } + + public void getAllowedNumber(String number) { + currentAllowedColor = number; + } + + /** + * Getter and Setter for Allowed Symbol + */ + + public String getCurrentAllowedSymbol() { + return currentAllowedSymbol; + } + + public void setAllowedSymbol(String symbol) { + currentAllowedSymbol = symbol; + } + + + /** + * Getter and Setter for Allowed Color + */ + + public String getAllowedColor() { + return currentAllowedColor; + } + + public void setAllowedColor(String color) { + currentAllowedColor = color; + } + +} + + + + + -- GitLab