From cf85b69d8089aef5c09fac8b10af2696a4b06de6 Mon Sep 17 00:00:00 2001 From: Dejen Date: Mon, 11 Jul 2022 19:42:32 -0400 Subject: [PATCH 01/31] got simulation running --- .../zipcodewilmington/casino/games/blackjack/BlackjackGame.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java new file mode 100644 index 00000000..aafd3afd --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java @@ -0,0 +1,2 @@ +package com.github.zipcodewilmington.casino.games.blackjack;public class BlackjackGame { +} From bc3dadf9418d9d605aa88dfa4a1329e040df1cb1 Mon Sep 17 00:00:00 2001 From: Dejen Date: Mon, 11 Jul 2022 22:53:16 -0400 Subject: [PATCH 02/31] working bet and looping for now. retains amounts when looping --- .../casino/games/blackjack/BlackjackGame.java | 112 +++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java index aafd3afd..09814970 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java @@ -1,2 +1,112 @@ -package com.github.zipcodewilmington.casino.games.blackjack;public class BlackjackGame { +package com.github.zipcodewilmington.casino.games.blackjack; +import java.sql.SQLOutput; +import java.util.InputMismatchException; +import java.util.Scanner; +import java.util.Random; + + + +public class BlackjackGame { +int playerAmount = 0; +int dealerAmount = 0; + +int playerChips = 5; + +int playerBet = 0; + + public static void main(String[] args) { + BlackjackGame bj = new BlackjackGame(); + bj.playGame(); + } + + +void playGame() { + getDealerAmount(); + welcomeStatement(); + getPlayerBet(); + dealerRecap(); + +while (playerAmount < 21 && playerAmount <= dealerAmount){ + playerDraw(); + } + +if (playerAmount <= 21 && playerAmount > dealerAmount){ + playerWins(); +} else if (playerAmount > 21){ + dealerWins(); +} + +} + + + +private void welcomeStatement(){ + System.out.println("Welcome to the Bobby's Brutal Blackjack. Name's Bobby, nice to meet cha.\n" + + "Let's jack it up!.\n"); +} + +public int getDealerAmount(){ + Random random = new Random(); + int min = 19; + int max = 1; + int dealerNum = min + random.nextInt(max); + dealerAmount = dealerNum; + return dealerAmount; +} + + public void dealerRecap() { + System.out.println("It looks like the dealer has pulled a " + dealerAmount + ". See if you can beat that."); + } + + public int playerDraw() { + Random random = new Random(); + Scanner scan = new Scanner(System.in); + int min = 1; + System.out.println("OK kid, you got " + playerAmount + ". Draw a card and see if you can win."); + System.out.println("Hit enter to draw"); + scan.nextLine(); + int nextDraw = min + random.nextInt(9); + playerAmount += nextDraw; + return playerAmount; + + + } + + public void playerWins(){ + Scanner scan = new Scanner(System.in); + playerChips += playerBet; + System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + "! You now have " + playerChips + "!"); + playerAmount = 0; + scan.nextLine(); + playGame(); + } + + public void dealerWins(){ + Scanner scan = new Scanner(System.in); + playerChips-=playerBet; + System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " and now have " + playerChips + "."); + playerAmount = 0; + scan.nextLine(); + playGame(); + } + + + + public int getPlayerBet(){ + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'? 0 is also an option."); + playerBet = scan.nextInt(); + if (playerBet > playerChips){ + System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); + getPlayerBet(); + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + getPlayerBet(); + } + return playerBet; + } + + + } + From 459f91dd1e9b0dc89c2d60d8a74012a6e7ba5b46 Mon Sep 17 00:00:00 2001 From: Dejen Date: Mon, 11 Jul 2022 23:36:28 -0400 Subject: [PATCH 03/31] cleaned up a bit --- .../casino/games/blackjack/BlackjackGame.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java index 09814970..c923a6e1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java @@ -48,8 +48,8 @@ private void welcomeStatement(){ public int getDealerAmount(){ Random random = new Random(); - int min = 19; - int max = 1; + int min = 17; + int max = 3; int dealerNum = min + random.nextInt(max); dealerAmount = dealerNum; return dealerAmount; @@ -76,7 +76,7 @@ public int playerDraw() { public void playerWins(){ Scanner scan = new Scanner(System.in); playerChips += playerBet; - System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + "! You now have " + playerChips + "!"); + System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + " chips! You now have " + playerChips + " chips!"); playerAmount = 0; scan.nextLine(); playGame(); @@ -85,7 +85,7 @@ public void playerWins(){ public void dealerWins(){ Scanner scan = new Scanner(System.in); playerChips-=playerBet; - System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " and now have " + playerChips + "."); + System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " chips and now have " + playerChips + " chips."); playerAmount = 0; scan.nextLine(); playGame(); @@ -107,6 +107,16 @@ public int getPlayerBet(){ return playerBet; } +// int getNumb(String message) { +// +// Scanner scan = new Scanner(System.in); +// while (true) { +// System.out.print(message); +// try { +// return scan.nextInt(); +// } +// catch (InputMismatchException e) { +// System.out.println("\"" + scan.next() + "\" isn't a number!"); } From b09c7c557582727fb873867968c2cf8b1fa170e3 Mon Sep 17 00:00:00 2001 From: Dejen Date: Mon, 11 Jul 2022 23:48:59 -0400 Subject: [PATCH 04/31] changed loop point --- .../casino/games/blackjack/BlackjackGame.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java index c923a6e1..74a79d18 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackjackGame.java @@ -15,6 +15,7 @@ public class BlackjackGame { int playerBet = 0; public static void main(String[] args) { + System.out.println("Welcome to the Bobby's Brutal Blackjack. Name's Bobby, nice to meet cha."); BlackjackGame bj = new BlackjackGame(); bj.playGame(); } @@ -42,8 +43,7 @@ void playGame() { private void welcomeStatement(){ - System.out.println("Welcome to the Bobby's Brutal Blackjack. Name's Bobby, nice to meet cha.\n" + - "Let's jack it up!.\n"); + System.out.println("Let's jack it up!.\n"); } public int getDealerAmount(){ From b3236ebb2ec8c60778c101b6c359f2b33ecef8fd Mon Sep 17 00:00:00 2001 From: Dejen Date: Wed, 13 Jul 2022 11:41:59 -0400 Subject: [PATCH 05/31] pushing to new repo --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes src/main/java/com/.DS_Store | Bin 0 -> 6148 bytes src/main/java/com/github/.DS_Store | Bin 0 -> 6148 bytes .../com/github/zipcodewilmington/.DS_Store | Bin 0 -> 6148 bytes .../casino/blackjack/BlackJackGame.java | 147 ++++++++++++++++++ .../zipcodewilmington/BlackJackGameTest.java | 4 + 9 files changed, 151 insertions(+) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/com/.DS_Store create mode 100644 src/main/java/com/github/.DS_Store create mode 100644 src/main/java/com/github/zipcodewilmington/.DS_Store create mode 100644 src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java create mode 100644 src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a0883d30b0b72b95aa0d86c46ebe3d0932347ac2 GIT binary patch literal 6148 zcmeHKPjAyO6n}0DO*SF*0Mafz33^ z%`Q-=J~EQjp>s;;?UuEzunbrR{xt^p?C#K*LdtP!E9dt#mE$Ot5!yL8978)ll^};; zK{3wynDPy~uUFYci+pPO`xZ^pB%gP?-$kw7xN)=TIL@x~I(R1+!91K7c|V-JSm+%>x-}C+u%(7Hw=cr@* zCOxK8I-wywrGSR(tcbg?sIu3jDcHL}to(>H-LU3ys@5)@q2FT~&=X(>9`T09j}4DH zR&z$`zDDuC5wp)7jsaFI1C{~H zK$QWG4<3}!H&|*^p#zC}0stGRR)ReLF0hYh&^K6WL<>Y{SDzU2Iw0sHKGP$e*_c_Hn9x+RR(?m Dg~ZyX literal 0 HcmV?d00001 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0b0b5aec19f21de471d2fe3801eba3964c1baa60 GIT binary patch literal 6148 zcmeHKu};G<5Iwg65>-eYKvTl`r9U z;Ldg{+QJ9|bSIskeZI5f=g9T}fN1pE>i}f{uu%yM4i=vX^^?v>!B{LrL1P@o@+ypF zh;15><@Yl{duPEN1Q0kiv-oL0Fq7_4t@Ro#txeOPq|I~%pCTi@Is4jp@WWo`GUbsOI$@=;SS@V`{DXmA8i zSQ)S9!S5!qOs>&J{uX4=ffTYSKAy4fBOlmgVFs81X5ddUV9rLn^e4ZbKbjd}2ELO4 zIv-qALeF5XQ5_vvs1yK^o{>thuAcsgE*TI#gSkeupa>m`s6&NGF@(t+gbv4k&-mvW zbvOt$Gmc|s7A8XxCh-uiatGmQSmel|AVjd|H&Y3F$2uNzhXdGO~2W| zC7HW*W^r`ax~P|^B;=QC9EV^R^Zf literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..571cf1007794b0378b8d75af5035c209b1bfd332 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0CKRCug&qT5i}p`Jyu?@!UXAEMr6#6mG-gYiHiuHkSzpK}@pW`& zcT>>nNf0SBF#Bz0XEw~YVJE{Fpy z0MED~$^T~n&(2^E%x4qke>uNHSlfP=A`_YW1=(nz&-pbN#L*~iG~RfrY^lTCS&Vj3NSa-C4u26+DF5e9M=r?oSp>W-J za9g@F?kJ>@7$62dGl0DxNEPe<@z4FgbfSS6AO@C`0d91?t_!*8+PaV>)><3%1{4MT na)t8{n8;ELzF3NDpi;nY;{?#rm@5Pe2>l318fYK}{*-|aYiCrf literal 0 HcmV?d00001 diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..81e425f5e7d7b3c2ec176e8ddb22b5eab24b3106 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8CKMqDg&qT5i}p`Jyu?@!UXAEMr6x_$V49UCHHT8jSzpK}@pW`& zcO#VQ#e-m(f!S{}JF{WF4Lcde7(n=y+qW`H7AOc=fqTt{7!inde%Iqo5bK`a7z z!tF@@0|R(=RW@XTjnCqR^E-x>-47`;5$zS^>61R?x8Ny`(yY~b=ap)0ZGFQqjJk2_ zJ&4@P{A`-K{^S~;E`*4Ka_$G0(I_8STPGsP{3sbsWIz;-z~$yDNyFrS;o_RikX`QR}gC*nmB&*7VtvZ=9zSD5H* zp1nyDi{u_GrFZE?NDL4I#K7t@pl>{*zPc$=X2bw7@Jj~pey~9i9gT%Td3C@bTL8cs zn5Dp6{`>>lXaICH77D=v!c{1s3gx=R;JSCS5T0#oO(;SS3Oz1(E!sZ?@e*r2cr~I2mDs?;?}UZR9r{ z$0;~>{y&CckCt}c~|g2lKKT!p=9ySRO-;-nMCy^&4`yFCoKy$<89nl{xW z?v8b?Zzdeqb=$?#Y*wuwlx3~an3v`3s8%VqagBf53evJXzA0#TFXE8OX zw+=MA1whQ9TMLfqw~=zBMbBbt5NA+?NkufN!nPQ~q@!QjIL~5g(4>Q~&4;j07PdnX z`ssLosl!2d2H7$L%)l}O)cc_n>HI(Yx&PNeY?uLNU_BWSxt8B*Vr}+pU8$1JT8Vm( qNEF?Bb~mLZ75XGWW?=T4o1K}v`}WwqAtE)H=etB5B8s4ltr)`{!t<tp) zo=rl9U)iKAW>v3urCM9<2M-@bQM4U>Nx#}Utwz;+HW*Eh`RbFkWwx?M*-gv6If7#WGH+#LV?(e@| zF5~Fg^OtWw4!@Nb#{O{cLJHrqlg9y9@Ds*8xVlWIrnKf9(W^?U3WCCbFdz(U1_NPt zincf7apWn40byW+7~uUuLm88RjYqe2U~nw}uno5p*!+XYIXYkxuaRb8;?GnRA@d_xU&i!igI^HeeJ?YB_3rI284mz3~=uU>G1h~`1k(b1<4=` z2m}8o1FC(H9t`kq;cQ)dOFnBg^c2d%agE386d3L(Ml2u2J5VR^Yc_yMz{Vpy5cv^s MG{_(f{8I-000z%w-2eap literal 0 HcmV?d00001 diff --git a/src/main/java/com/github/zipcodewilmington/.DS_Store b/src/main/java/com/github/zipcodewilmington/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b68fbe6f40c61b0259ad6b3e73e56d95782e265f GIT binary patch literal 6148 zcmeHK&rjPh6n-wHOH@tjfk|ADEOD(^fo{^YODJ&Qz-5`(VW2Ld)s`)bt0tv~s#4D5 zkKxK+!oLIGvkhz3A#s|f%`bZX?C1CVLM`fB5u=Xp)a_PNNX?&lL;*(@J?YGwURaQhvHXQ4KWH5xw z>4zj6sA*44vO%t6LsQ}TzTa=H&t}`ZuiA2_+nu-N?9EQ6ExWs~=X2kCvH9}tyZ*QI zd!~NqQIo*_)biZoJzOGFnbSo$&Qg_qhMi-YwEvSE+M=&0T~M^J%bBGs=psvNbPPY{ zbB{*&QskNA0;phpq#d#GOFOGH(J?9I)gA?pd$C6poj3*@1CD_wGhoj|uleK%=ja%4 z4E!$)@cAI2jDf|{pguZ~=qCWM4zm{I`G<&Oq{YBuX%ICKVM2i>RM;nmFyXLE>lauo z4VrKg_VFQX&%(Y?gzg>fOYKe~Fz8apfMcM_z=|oh`2Ih9{QX}IawW%rW8j}+K-3Sy zgC3@2@7ATs@m(vSpP(%4R~mc>K}KK2@a3y`9jXO($r)f^u`~z^#Qg|p8eHNS_@fNm E0ey9Y)Bpeg literal 0 HcmV?d00001 diff --git a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java new file mode 100644 index 00000000..726d4cd9 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java @@ -0,0 +1,147 @@ +package com.github.zipcodewilmington.casino.blackjack; + +import java.sql.SQLOutput; +import java.util.InputMismatchException; +import java.util.Scanner; +import java.util.Random; + + + +public class BlackJackGame { + int playerAmount = 0; + int dealerAmount = 0; + + int playerChips = 500; + + int playerBet = 0; + + public static void main(String[] args) { + System.out.println("Welcome to the Bobby's Brutal Blackjack. Name's Bobby, nice to meet cha."); + BlackJackGame bj = new BlackJackGame(); + bj.playGame(); + } + + + void playGame() { + getDealerAmount(); + welcomeStatement(); + getPlayerBet(); + dealerRecap(); + + while (playerAmount < 21 && playerAmount <= dealerAmount){ + playerDraw(); + + } + + if (playerAmount <= 21 && playerAmount > dealerAmount){ + playerWins(); + } else if (playerAmount > 21){ + dealerWins(); + } + + } + + + + private void welcomeStatement(){ + System.out.println("Let's jack it up!\n"); + } + + public int getDealerAmount(){ + Random random = new Random(); + int min = 17; + int max = 3; + int dealerNum = min + random.nextInt(max); + dealerAmount = dealerNum; + return dealerAmount; + } + + public void dealerRecap() { + System.out.println("It looks like the dealer has pulled a " + dealerAmount + ". See if you can beat that."); + } + + public int playerDraw() { + Random random = new Random(); + Scanner scan = new Scanner(System.in); + int min = 1; + System.out.println("OK kid, you got " + playerAmount + ". Draw a card and see if you can win."); + System.out.println("Hit enter to draw"); + scan.nextLine(); + int nextDraw = min + random.nextInt(9); + if (nextDraw == 1 || nextDraw == 11){ + System.out.println("Lucky break, kid! Choose if you want this Ace to be a 1 or an 11."); + nextDraw = scan.nextInt(); + } + playerAmount += nextDraw; + System.out.println("Ya drew a " + nextDraw + "!"); + return playerAmount; + + + } + + public void playerWins(){ + Scanner scan = new Scanner(System.in); + playerChips += playerBet; + System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + " chips! You now have " + playerChips + " chips!"); + playerAmount = 0; + scan.nextLine(); + playGame(); + } + + public void dealerWins(){ + Scanner scan = new Scanner(System.in); + playerChips-=playerBet; + System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " chips and now have " + playerChips + " chips."); + playerAmount = 0; + scan.nextLine(); + playGame(); + } + + public void doubleDown(){ + playerBet = playerBet * 2; + System.out.println("OK kid, this next one is for all da marbles! Let's see what cha got!"); + playerDraw(); + if (playerAmount <= 21 && playerAmount > dealerAmount){ + playerWins(); + } else{ + dealerWins(); + } + } + + + public int getPlayerBet(){ + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); + playerBet = scan.nextInt(); + if (playerBet > playerChips){ + System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); + getPlayerBet(); + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + getPlayerBet(); + } +// do { +// try { +// playerBet = scan.nextInt(); +// } catch (InputMismatchException e){ +// System.out.println("That ain't a number I ever heard of."); +// getPlayerBet(); +// } +// } while (playerBet != String.valueOf (int)); + + return playerBet; + } + +// int getNumb(String message) { +// +// Scanner scan = new Scanner(System.in); +// while (true) { +// System.out.print(message); +// try { +// return scan.nextInt(); +// } +// catch (InputMismatchException e) { +// System.out.println("\"" + scan.next() + "\" isn't a number!"); + +} + diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java new file mode 100644 index 00000000..55877a86 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -0,0 +1,4 @@ +package com.github.zipcodewilmington; + +public class BlackJackGameTest { +} From 35839ed9b56a20331e5ade8d8a0489a65c8dc1c3 Mon Sep 17 00:00:00 2001 From: Dejen Date: Wed, 13 Jul 2022 14:06:12 -0400 Subject: [PATCH 06/31] adding BlackJack Tests --- .../zipcodewilmington/BlackJackGameTest.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 55877a86..0c879708 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -1,4 +1,63 @@ package com.github.zipcodewilmington; +import org.junit.Test; + +import java.util.Scanner; + +import static org.junit.Assert.*; + public class BlackJackGameTest { -} + @Test + public void getPlayerBetGood(){ + int playerChips = 50; + int bet = 45; + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); + int playerBet = bet; + if (playerBet > playerChips){ + System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + } +assert (playerBet == bet); + + } + + + @Test + public void getPlayerBetOver(){ + int playerChips = 50; + int bet = 55; + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); + int playerBet = bet; + if (playerBet > playerChips){ + System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); + playerBet = 0; + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + playerBet = 25; + } + assert (playerBet == 0); + + } + + @Test + public void getPlayerBetunder0(){ + int playerChips = 50; + int bet = -27; + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); + int playerBet = bet; + if (playerBet > playerChips){ + System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); + playerBet = 25; + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + playerBet = 0; + } + assert (playerBet == 0); + + } + +} \ No newline at end of file From 8951739ed2b28d38e68ea02525a6a576517c2a97 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 13 Jul 2022 14:21:53 -0400 Subject: [PATCH 07/31] casino class complete. working on slot test and game --- .../com/github/zipcodewilmington/Casino.java | 14 ++++++-- .../casino/games/slots/SlotsGameTest.java | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0..d64d34f8 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -32,8 +32,16 @@ public void run() { String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { play(new SlotsGame(), new SlotsPlayer()); - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); + } else if (gameSelectionInput.equals("CEE-LO")) { + play(new CeeloGame(), new CeeloPlayer()); + } else if (gameSelectionInput.equals("CHUCK A LUCK")) { + play(new ChuckALuckGame(), new ChuckALuckPlayer()); + } else if (gameSelectionInput.equals("CONNECT 4")) { + play(new Connect4Game(), new Connect4Player()); + } else if (gameSelectionInput.equals("BLACKJACK")) { + play(new BlackjackGame(), new BlackjackPlayer()); + }else if (gameSelectionInput.equals("WAR")) { + play(new WarGame(), new WarPlayer()); } else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; @@ -66,7 +74,7 @@ private String getGameSelectionInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Game Selection Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ]") + .append("\n\t[ SLOTS ], [ CEE-LO ], [ CHUCK A LUCK], [ CONNECT 4 ], [ BLACKJACK ], [ WAR ]") .toString()); } diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java new file mode 100644 index 00000000..e720576a --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java @@ -0,0 +1,36 @@ +package com.github.zipcodewilmington.casino.games.slots; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Random; + +import static org.junit.Assert.*; + +public class SlotsGameTest { + + @Test + public void randomNumber(){ + Random rand = new Random(1); + int expected = rand.nextInt(10); + int actual = 5; + Assert.assertEquals(expected, actual); + } + + @Test + public void randomNumber1(){ + Random rand = new Random(2); + int expected = rand.nextInt(10); + int actual = 8; + Assert.assertEquals(expected, actual); + } + + @Test + public void randomNumber2(){ + Random rand = new Random(3); + int expected = rand.nextInt(10); + int actual = 4; + Assert.assertEquals(expected, actual); + } + +} \ No newline at end of file From 8cfd89749a809ed1a0c1fb6e0bc5f152c9697534 Mon Sep 17 00:00:00 2001 From: Myah Date: Wed, 13 Jul 2022 20:12:43 -0400 Subject: [PATCH 08/31] token class created, board display works, position placement in progress --- .../casino/ArcadeAccount.java | 2 + .../casino/games/connectfour/Board.java | 7 ++ .../casino/games/connectfour/ConnectFour.java | 116 ++++++++++++++++++ .../games/connectfour/ConnectFourPlayer.java | 12 ++ .../casino/games/connectfour/Token.java | 28 +++++ .../games/connectfour/ConnectFourTest.java | 10 ++ 6 files changed, 175 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/ArcadeAccount.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java create mode 100644 src/test/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/ArcadeAccount.java b/src/main/java/com/github/zipcodewilmington/casino/ArcadeAccount.java new file mode 100644 index 00000000..c693fc6e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/ArcadeAccount.java @@ -0,0 +1,2 @@ +package com.github.zipcodewilmington.casino.games;public class ArcadeAccount { +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java new file mode 100644 index 00000000..99b8fa0b --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java @@ -0,0 +1,7 @@ +package com.github.zipcodewilmington.casino.games.connectfour; + +public class Board { + public Board(Character[][] matrix) { + } + + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java new file mode 100644 index 00000000..aeea2117 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -0,0 +1,116 @@ +package com.github.zipcodewilmington.casino.games.connectfour; + +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.io.Console; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + + +public class ConnectFour { + static ArrayList userPositions = new ArrayList(); + static ArrayList cpuPositions = new ArrayList(); + List userTokens = new ArrayList<>(); + List cpuTokens = new ArrayList<>(); + + public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums + static AnsiColor color; + + + static Scanner sc = new Scanner(System.in); + static ConnectFourPlayer cfPlayer = new ConnectFourPlayer(); + static Board gameBoard; + + static Token userToken = new Token(AnsiColor.RED); + static Token opponentToken = new Token(AnsiColor.BLACK); + + public static void main(String[] args) { + Character[][] board = { + {'-', '-', '-', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '-'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, + {'-', '-', '-', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '-'}, + }; + + gameBoard = new Board(board); + displayGameBoard(board); + placeUserPosition(board, cfPlayer.getPositionPlacement(), "user"); + + } + + + ConnectFour(ConnectFourPlayer player) { + this.cfPlayer = player; + } + + ConnectFour() { + } + + static void displayGameBoard(Character[][] board) { + //TODO number rows to better user's understanding + int rowNums = 1; + for (Character[] row : board) { + for (Character ch : row) { + System.out.print(ANSI_YELLOW+ch); + System.out.print("\t"); + } + System.out.println(""); + } + } + + static void placeUserPosition(Character[][] board, int position, String user) { + int pos; + char symbol = 'X'; + System.out.println("Enter a position to place your token: "); + cfPlayer.setPositionPlacement(sc.nextInt()); + pos = cfPlayer.getPositionPlacement(); + + switch (pos) { + //y then x + case 1: + board[6][1] = symbol; //column 1 + break; + case 2: + board[6][3] = symbol; //column2 + break; + case 3: + board[6][5] = symbol; //column3 + break; + case 4: + board[6][7] = symbol; //column4 + break; + case 5: + board[6][9] = symbol; //column5 + break; + case 6: + board[6][11] = symbol; //column6 + break; + case 7: + board[6][13] = symbol; //column7 + break; + default: + break; + } + System.out.println("\n\n"); + displayGameBoard(board); + + +/* + static void placePosition(Character[][] board, int position, String user) { + char symbol; + if (user.equals("user")) { + symbol = AnsiColor.RED; + } + } +*/ + + + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java new file mode 100644 index 00000000..a5c42054 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java @@ -0,0 +1,12 @@ +package com.github.zipcodewilmington.casino.games.connectfour; + +public class ConnectFourPlayer { + int positionPlacement; + + public int getPositionPlacement() { + return positionPlacement; + } + public void setPositionPlacement(int chosenPosition) { + this.positionPlacement = chosenPosition; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java new file mode 100644 index 00000000..aa8d0bf8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java @@ -0,0 +1,28 @@ +package com.github.zipcodewilmington.casino.games.connectfour; + +import com.github.zipcodewilmington.utils.AnsiColor; + +public class Token { + static Character symbol = 'O'; + private AnsiColor color; + public static final String ANSI_RED = "\u001B[31m"; + public static final String ANSI_BLACK = "\u001B[30m"; + +// Token() { +// this.symbol = 'O'; +// this.ansiColor = AnsiColor.YELLOW; +// } + Token() { + } + Token(AnsiColor color, Character ch) { + } + + Token(AnsiColor color) { + this.color = color; + } + + @Override + public String toString() { + return color+String.valueOf(symbol); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourTest.java new file mode 100644 index 00000000..78b88f62 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourTest.java @@ -0,0 +1,10 @@ +package com.github.zipcodewilmington.casino.games.connectfour; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ConnectFourTest { + +} \ No newline at end of file From e73f1696bbc7f9172181b8abdab18af4e96f3d5a Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 13 Jul 2022 20:25:00 -0400 Subject: [PATCH 09/31] dice class, accountmanager setup --- .../casino/CasinoAccount.java | 31 +++++++++++++ .../casino/CasinoAccountManager.java | 44 +++++++++++++----- .../zipcodewilmington/casino/games/Dice.java | 46 +++++++++++++++++++ 3 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Dice.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b..daca7a9c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -6,4 +6,35 @@ * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + + String userName; + String password; + Integer accountBalance; + + public CasinoAccount(String userName, String password) { + this.userName = userName; + this.password = password; + } + + public CasinoAccount(String userName, String password, Integer balance) { + this.userName = userName; + this.password = password; + this.accountBalance = balance; + } + public void updateAccountBalance(Integer amount) { + this.accountBalance += amount; + } + + public String getUserName() { + return userName; + } + + public String getPassword() { + return password; + } + + public Integer getAccountBalance() { + return accountBalance; + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a..9d5ca583 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,23 +1,37 @@ package com.github.zipcodewilmington.casino; +import java.util.*; + /** * Created by leon on 7/21/2020. * `ArcadeAccountManager` stores, manages, and retrieves `ArcadeAccount` objects * it is advised that every instruction in this class is logged */ public class CasinoAccountManager { + + private List accountList = new ArrayList<>(); /** * @param accountName name of account to be returned * @param accountPassword password of account to be returned * @return `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount getAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + for (CasinoAccount a : accountList) { + if (accountName.equals(a.getUserName()) && accountPassword.equals(a.getPassword())) { + return a; + } + } + +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + return null; } +// if (accountManager.getAccount(param1, parfam2) == null) {sysmt.out.pronta;ksdjhfa;ls} + /** * logs & creates a new `ArcadeAccount` * @@ -26,10 +40,14 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount createAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + CasinoAccount newAccount = new CasinoAccount(accountName, accountPassword); + return newAccount; + +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } /** @@ -38,9 +56,11 @@ public CasinoAccount createAccount(String accountName, String accountPassword) { * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` */ public void registerAccount(CasinoAccount casinoAccount) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + this.accountList.add(casinoAccount); +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java b/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java new file mode 100644 index 00000000..fe869156 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java @@ -0,0 +1,46 @@ +package com.github.zipcodewilmington.casino.games; + +import java.util.ArrayList; +import java.util.List; + +public class Dice { + static List bins; + private Integer numOfDice; + private Integer maxRoll = numOfDice * 6; + private Integer sum; + + public Dice(Integer dice) { + this.numOfDice = dice; + } + + public int tossAndSum(){ + + // Roll n amount of times and return the sum of the rolls. + + int result = 0; + for (int i = 0; i < numOfDice; i++) { + result += (6 * Math.random() + 1); + } + return result; + } + + // create an ArrayList populated with 0's. Number of elements depends on number of dice. + + public void initializeBins() { + bins = new ArrayList(); + for (int i = numOfDice; i < (maxRoll + numOfDice); i++){ + bins.add(0); + } + } + + //return bin for a specified value + + public Integer getBin(Integer number){ + return bins.get(number); + } + + public void incrementBin(int sum) { + bins.set(sum, getBin(sum)+1); + } + +} From b44daf1cf8f0c6afa1f643ef8b7dc08e5906d189 Mon Sep 17 00:00:00 2001 From: Dejen Date: Wed, 13 Jul 2022 20:53:06 -0400 Subject: [PATCH 10/31] aces and InputException --- .../casino/blackjack/BlackJackGame.java | 82 +++++++++---- .../zipcodewilmington/BlackJackGameTest.java | 111 ++++++++++-------- 2 files changed, 124 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java index 726d4cd9..00838a5f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java @@ -29,14 +29,23 @@ void playGame() { dealerRecap(); while (playerAmount < 21 && playerAmount <= dealerAmount){ - playerDraw(); + Scanner scan = new Scanner(System.in); + if ((playerBet * 2) < playerChips); + System.out.println("Kiddo, type 'dd' to double down, or hit enter to draw"); + String respond = scan.nextLine(); + System.out.println(respond); + if (respond == "dd"){ + doubleDown(); + }else{ + playerDraw(); + } } if (playerAmount <= 21 && playerAmount > dealerAmount){ - playerWins(); + playerWins(playerChips, playerBet); } else if (playerAmount > 21){ - dealerWins(); + dealerWins(playerChips, playerBet); } } @@ -67,19 +76,45 @@ public int playerDraw() { System.out.println("OK kid, you got " + playerAmount + ". Draw a card and see if you can win."); System.out.println("Hit enter to draw"); scan.nextLine(); - int nextDraw = min + random.nextInt(9); +// int nextDraw = min + random.nextInt(9); + int nextDraw = 11; if (nextDraw == 1 || nextDraw == 11){ - System.out.println("Lucky break, kid! Choose if you want this Ace to be a 1 or an 11."); - nextDraw = scan.nextInt(); + aces(); + } else{ + playerAmount += nextDraw; + System.out.println("Ya drew a " + nextDraw + "!"); } - playerAmount += nextDraw; - System.out.println("Ya drew a " + nextDraw + "!"); return playerAmount; + } - } + public void aces() { + int nextDraw = 0; + Scanner scan = new Scanner(System.in); + System.out.println("Choose if you want this Ace to be a 1 or an 11."); +// try {int nextDraw = scan.nextInt(); +// } catch (InputMismatchException e) { +// System.out.println("That ain't a number I ever heard of."); +// aces();} + try {nextDraw = scan.nextInt(); + } catch (InputMismatchException e) { + System.out.println("That ain't a number I ever heard of."); + aces(); + + } + if (nextDraw == 1 || nextDraw == 11) { + playerAmount += nextDraw; + System.out.println("Ya drew a " + nextDraw + "!"); + }else{ + System.out.println("Nice try."); + aces(); + } - public void playerWins(){ + } + + + + public void playerWins(int playerChips, int playerBet){ Scanner scan = new Scanner(System.in); playerChips += playerBet; System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + " chips! You now have " + playerChips + " chips!"); @@ -88,7 +123,7 @@ public void playerWins(){ playGame(); } - public void dealerWins(){ + public void dealerWins(int playerChips, int playerBet){ Scanner scan = new Scanner(System.in); playerChips-=playerBet; System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " chips and now have " + playerChips + " chips."); @@ -102,9 +137,9 @@ public void doubleDown(){ System.out.println("OK kid, this next one is for all da marbles! Let's see what cha got!"); playerDraw(); if (playerAmount <= 21 && playerAmount > dealerAmount){ - playerWins(); + playerWins(playerChips, playerBet); } else{ - dealerWins(); + dealerWins(playerChips, playerBet); } } @@ -112,7 +147,13 @@ public void doubleDown(){ public int getPlayerBet(){ Scanner scan = new Scanner(System.in); System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); + try { playerBet = scan.nextInt(); + } catch (InputMismatchException e) { + System.out.println("That ain't a number I ever heard of."); + getPlayerBet(); + + } if (playerBet > playerChips){ System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); getPlayerBet(); @@ -120,16 +161,12 @@ public int getPlayerBet(){ System.out.println("Hey, don't try it with the funny business!"); getPlayerBet(); } -// do { -// try { -// playerBet = scan.nextInt(); -// } catch (InputMismatchException e){ -// System.out.println("That ain't a number I ever heard of."); -// getPlayerBet(); -// } -// } while (playerBet != String.valueOf (int)); - return playerBet; + } + + + + } // int getNumb(String message) { @@ -143,5 +180,4 @@ public int getPlayerBet(){ // catch (InputMismatchException e) { // System.out.println("\"" + scan.next() + "\" isn't a number!"); -} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 0c879708..9f77f95d 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -2,62 +2,81 @@ import org.junit.Test; +import java.util.Random; import java.util.Scanner; import static org.junit.Assert.*; public class BlackJackGameTest { @Test - public void getPlayerBetGood(){ - int playerChips = 50; - int bet = 45; - Scanner scan = new Scanner(System.in); - System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); - int playerBet = bet; - if (playerBet > playerChips){ - System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); - }else if (playerBet < 0) { - System.out.println("Hey, don't try it with the funny business!"); - } -assert (playerBet == bet); - + public void getDealerAmount() { + Random random = new Random(); + int min = 17; + int max = 3; + int dealerNum = min + random.nextInt(max); + int dealerAmount = dealerNum; + assert (dealerAmount > 16 && dealerAmount <21); } - - @Test - public void getPlayerBetOver(){ - int playerChips = 50; - int bet = 55; - Scanner scan = new Scanner(System.in); - System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); - int playerBet = bet; - if (playerBet > playerChips){ - System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); - playerBet = 0; - }else if (playerBet < 0) { - System.out.println("Hey, don't try it with the funny business!"); - playerBet = 25; - } - assert (playerBet == 0); - + @Test public void dealerWinsTest() { + int playerChips = 700; + int playerBet = 50; + playerChips -= playerBet; + assert(playerChips == 650); } - @Test - public void getPlayerBetunder0(){ - int playerChips = 50; - int bet = -27; - Scanner scan = new Scanner(System.in); - System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); - int playerBet = bet; - if (playerBet > playerChips){ - System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); - playerBet = 25; - }else if (playerBet < 0) { - System.out.println("Hey, don't try it with the funny business!"); - playerBet = 0; - } - assert (playerBet == 0); - } + // @Test +// public void getPlayerBetGood(){ +// int playerChips = 50; +// int bet = 45; +// Scanner scan = new Scanner(System.in); +// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); +// int playerBet = bet; +// if (playerBet > playerChips){ +// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); +// }else if (playerBet < 0) { +// System.out.println("Hey, don't try it with the funny business!"); +// } +//assert (playerBet == bet); +// +// } +// +// +// @Test +// public void getPlayerBetOver(){ +// int playerChips = 50; +// int bet = 55; +// Scanner scan = new Scanner(System.in); +// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); +// int playerBet = bet; +// if (playerBet > playerChips){ +// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); +// playerBet = 0; +// }else if (playerBet < 0) { +// System.out.println("Hey, don't try it with the funny business!"); +// playerBet = 25; +// } +// assert (playerBet == 0); +// +// } +// +// @Test +// public void getPlayerBetUnder0(){ +// int playerChips = 50; +// int bet = -27; +// Scanner scan = new Scanner(System.in); +// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); +// int playerBet = bet; +// if (playerBet > playerChips){ +// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); +// playerBet = 25; +// }else if (playerBet < 0) { +// System.out.println("Hey, don't try it with the funny business!"); +// playerBet = 0; +// } +// assert (playerBet == 0); +// +// } } \ No newline at end of file From ce7e766cb9e4eae470a9c9bdd71f72225aaa90e7 Mon Sep 17 00:00:00 2001 From: Chris Kent Date: Wed, 13 Jul 2022 21:20:09 -0400 Subject: [PATCH 11/31] Added Card Class --- .../zipcodewilmington/casino/games/Card.java | 54 +++++++++++++++++++ .../casino/games/deckOfCards.java | 22 ++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Card.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java new file mode 100644 index 00000000..9267e679 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java @@ -0,0 +1,54 @@ +package com.github.zipcodewilmington.casino.games; + +import java.util.Arrays; +import java.util.List; + +public class Card { + private String faceName, suit; + + public String getFaceName() { + return faceName; + } + + public static List getValidFaceNames(){ + return Arrays.asList("2","3","4","5","6","7","8","9","10", + "jack","queen","king","ace"); + } + + public void setFaceName(String faceName) { + List validFaceNames = getValidFaceNames(); + faceName = faceName.toLowerCase(); + if (validFaceNames.contains(faceName)){ + this.faceName = faceName;} + else + throw new IllegalArgumentException("Valid face names are: " + validFaceNames); + } + + public String getSuit() { + return suit; + } + + public static List getValidSuits(){ + return Arrays.asList("hearts", "diamonds", "spades", "clubs"); + } + + public void setSuit(String suit) { + List validSuits = getValidSuits(); + suit = suit.toLowerCase(); + + if (validSuits.contains(suit)) { + this.suit = suit; + } + else + throw new IllegalArgumentException("valid suits are: " + validSuits); + } + + public String toString(){ + return String.format("%s of %s", faceName, suit); + } + + public Card(String faceName, String suit) { + setFaceName(faceName); + setSuit(suit); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java new file mode 100644 index 00000000..9bdbf452 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java @@ -0,0 +1,22 @@ +package com.github.zipcodewilmington; +import java.util.ArrayList; + +public class DeckOfCards { + private ArrayList deck; + + + + public DeckOfCards(ArrayList deck) { + this.deck = deck; + } + + + + public DeckOfCards(){ + List suits = + + List faceNames = + + deck = new ArrayList(); + } +} From 9e6a4f9b797abe0a4daf83a1b67e27384fc34f62 Mon Sep 17 00:00:00 2001 From: Myah Date: Wed, 13 Jul 2022 22:11:17 -0400 Subject: [PATCH 12/31] fixed board display --- .../casino/games/connectfour/ConnectFour.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index aeea2117..68d7ac4e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -29,14 +29,14 @@ public class ConnectFour { public static void main(String[] args) { Character[][] board = { - {'-', '-', '-', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '-'}, + {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'-', '-', '-', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '-'}, + {'|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|'}, }; gameBoard = new Board(board); @@ -58,7 +58,7 @@ static void displayGameBoard(Character[][] board) { int rowNums = 1; for (Character[] row : board) { for (Character ch : row) { - System.out.print(ANSI_YELLOW+ch); + System.out.print(ANSI_YELLOW + ch); System.out.print("\t"); } System.out.println(""); @@ -75,7 +75,7 @@ static void placeUserPosition(Character[][] board, int position, String user) { switch (pos) { //y then x case 1: - board[6][1] = symbol; //column 1 + board[6][1] = symbol; //column1 break; case 2: board[6][3] = symbol; //column2 From bf09e4679a44075649c2668373851c4c30550d55 Mon Sep 17 00:00:00 2001 From: Myah Date: Thu, 14 Jul 2022 16:19:26 -0400 Subject: [PATCH 13/31] using map to track whether there are empty/filled spaces for players to place their position --- .../casino/games/connectfour/Board.java | 36 ++++- .../casino/games/connectfour/ConnectFour.java | 151 ++++++++++-------- .../casino/games/connectfour/Token.java | 26 +-- 3 files changed, 130 insertions(+), 83 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java index 99b8fa0b..bbaafbde 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java @@ -1,7 +1,41 @@ package com.github.zipcodewilmington.casino.games.connectfour; public class Board { - public Board(Character[][] matrix) { + public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums + private static int length = 15; + private static int width = 7; + public static final Character[][] board = new Character[width][length]; + + public Board(Character[][] matrix) { + } + + //creates board, NOT displays + static void createGameBoard() { + for (int row = 0; row < board.length; row++) { + for (int col = 0; col < board[row].length; col++) { + if (col % 2 == 0) board[row][col] = '|'; + else { + board[row][col] = 'O'; + } + //top row, "lid" + if (row == 0) board[row][col] = '_'; + } } + } + + static void displayGameBoard() { + //TODO number rows to better user's understanding + int colNums = 0; + for (Character[] row : board) { +// System.out.print(rowNums++); + for (Character ch : row) { + System.out.print(ANSI_YELLOW + ch); + System.out.print("\t"); + } + System.out.println(""); + } } + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index 68d7ac4e..8c43c4b7 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -1,13 +1,8 @@ package com.github.zipcodewilmington.casino.games.connectfour; import com.github.zipcodewilmington.utils.AnsiColor; -import com.github.zipcodewilmington.utils.IOConsole; - -import java.io.Console; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Scanner; +import java.util.*; +import static com.github.zipcodewilmington.casino.games.connectfour.Board.*; public class ConnectFour { @@ -16,6 +11,8 @@ public class ConnectFour { List userTokens = new ArrayList<>(); List cpuTokens = new ArrayList<>(); + static Map indexTracker = new HashMap(); + public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums static AnsiColor color; @@ -27,22 +24,27 @@ public class ConnectFour { static Token userToken = new Token(AnsiColor.RED); static Token opponentToken = new Token(AnsiColor.BLACK); + static boolean winner = false; + public static void main(String[] args) { - Character[][] board = { - {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, - {'|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|'}, - }; +// Character[][] board = { +// {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, +// {'|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|', '-', '|'}, +// }; +// placeUserPosition(board, "user"); +// System.out.print(userToken); gameBoard = new Board(board); - displayGameBoard(board); - placeUserPosition(board, cfPlayer.getPositionPlacement(), "user"); + createGameBoard(); + displayGameBoard(); + placeUserPosition(board, "user"); } @@ -53,63 +55,70 @@ public static void main(String[] args) { ConnectFour() { } - static void displayGameBoard(Character[][] board) { - //TODO number rows to better user's understanding - int rowNums = 1; - for (Character[] row : board) { - for (Character ch : row) { - System.out.print(ANSI_YELLOW + ch); - System.out.print("\t"); + static void placeUserPosition(Character[][] board, String user) { + char symbol = 'X'; + boolean emptyPosition = true; + int roundCounter = 1; + + while (emptyPosition) { //replace w try, catch block + System.out.println("Round " +roundCounter +"\n"+ + "Enter a position to place your token: "); + cfPlayer.setPositionPlacement(sc.nextInt()); // setting player position based on user input + int pos = cfPlayer.getPositionPlacement(); //return player's position + + if(pos>8 || pos<1) { + System.out.print("ERROR: invalid number"); + } + else { + emptyPosition = false; } - System.out.println(""); - } - } - static void placeUserPosition(Character[][] board, int position, String user) { - int pos; - char symbol = 'X'; - System.out.println("Enter a position to place your token: "); - cfPlayer.setPositionPlacement(sc.nextInt()); - pos = cfPlayer.getPositionPlacement(); - - switch (pos) { - //y then x - case 1: - board[6][1] = symbol; //column1 - break; - case 2: - board[6][3] = symbol; //column2 - break; - case 3: - board[6][5] = symbol; //column3 - break; - case 4: - board[6][7] = symbol; //column4 - break; - case 5: - board[6][9] = symbol; //column5 - break; - case 6: - board[6][11] = symbol; //column6 - break; - case 7: - board[6][13] = symbol; //column7 - break; - default: - break; - } - System.out.println("\n\n"); - displayGameBoard(board); + switch (pos) { + //y then x + case 1: + board[6][1] = symbol;//column1 + userPositions.add(pos); + indexTracker.put(board, emptyPosition); + break; + case 2: + board[6][3] = symbol; //column2 + break; + case 3: + board[6][5] = symbol; //column3 + break; + case 4: + board[6][7] = symbol; //column4 + break; + case 5: + board[6][9] = symbol; //column5 + break; + case 6: + board[6][11] = symbol; //column6 + break; + case 7: + board[6][13] = symbol; //column7 + break; + default: + System.out.print("ERROR: invalid number"); + break; + } + roundCounter++; + System.out.println("\n\n"); + System.out.print(userPositions); + displayGameBoard(); -/* - static void placePosition(Character[][] board, int position, String user) { - char symbol; - if (user.equals("user")) { - symbol = AnsiColor.RED; } - } -*/ + +// while (winner==false) { +// +// if (position>7 || position<0) { +// System.out.print("ERROR: invalid number"); +// } +// else { +// board[6][position] = symbol; +// } +// } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java index aa8d0bf8..d1f5f2e1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java @@ -5,24 +5,28 @@ public class Token { static Character symbol = 'O'; private AnsiColor color; - public static final String ANSI_RED = "\u001B[31m"; - public static final String ANSI_BLACK = "\u001B[30m"; + private static final String ANSI_RED = "\u001B[31m"; + private static final String ANSI_BLACK = "\u001B[30m"; // Token() { // this.symbol = 'O'; // this.ansiColor = AnsiColor.YELLOW; // } - Token() { - } - Token(AnsiColor color, Character ch) { - } +// Token() { +// } +// Token(AnsiColor color, Character ch) { +// } - Token(AnsiColor color) { - this.color = color; + Token(Character ch) { + this.symbol = ch; + System.out.print(ANSI_RED+symbol); } - @Override - public String toString() { - return color+String.valueOf(symbol); + public Token(AnsiColor black) { } + +// @Override +// public String toString() { +// return color+String.valueOf(symbol); +// } } From eb44ee9f57368632a6cda221e53d6ffb40fd16af Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 14 Jul 2022 16:28:00 -0400 Subject: [PATCH 14/31] created player class, updated slots player and slotsgame --- .../casino/PlayerInterface.java | 4 +- .../casino/games/Player.java | 27 +++++++ .../casino/games/slots/SlotsGame.java | 77 ++++++++++++++++++- .../casino/games/slots/SlotsPlayer.java | 31 +++++++- 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Player.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index c50b5113..77cf314f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -10,12 +10,12 @@ public interface PlayerInterface { /** * @return the `ArcadeAccount` used to log into the `Arcade` system to play this game */ - CasinoAccount getArcadeAccount(); + CasinoAccount getCasinoAccount(); /** * Defines how a specific implementation of `PlayerInterface` plays their respective game. * @param specify any return type you would like here * @return whatever return value you would like */ - SomeReturnType play(); + // SomeReturnType play(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Player.java b/src/main/java/com/github/zipcodewilmington/casino/games/Player.java new file mode 100644 index 00000000..4e1dfd07 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Player.java @@ -0,0 +1,27 @@ +package com.github.zipcodewilmington.casino.games; + +import com.github.zipcodewilmington.casino.CasinoAccount; + +public class Player { + public String name; + public static int balance; + CasinoAccount casinoAccount; + + public Player(String name){ + this.name=name; + } + + public Player(){} + + public String getName(){ + return this.name; + } + + public static int getBalance(){ + return balance; + } + + public void setBalance(int balance){ + Player.balance = balance; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 8cb20c78..41cbf7b3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,7 +1,82 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Objects; +import java.util.Random; +import java.util.Scanner; + /** * Created by leon on 7/21/2020. */ -public class SlotsGame { +public class SlotsGame implements GameInterface { + + // public static void main(String[] args){ + + public static void playSlotsGame(){ + + final String RED_BRIGHT = "\033[0;91m"; // RED + final String TEXT_RESET = "\u001B[0m"; + + Random random = new Random(); + int num1; + int num2; + int num3; + Scanner scan = new Scanner(System.in); + String playerInput; + + + do { + System.out.println("Press 1 to play or Q to quit."); + playerInput = scan.nextLine(); + System.out.println("\n"); + + num1 = random.nextInt(10); + num2 = random.nextInt(10); + num3 = random.nextInt(10); + + if(Math.random() <= 0.20) { + System.out.println( RED_BRIGHT + "CHERRY | CHERRY | CHERRY" + TEXT_RESET + "\n" + + "Plus 2 tokens! \n"); + } else { + + System.out.println("$$$$$$$$$$$$$$$\n" + + " " + num1 + " || " + num2 + " || " + num3 + " \n" + + "$$$$$$$$$$$$$$$"); + + if (num1 == 7 && num2 == 7 && num3 == 7) { + //win jackpot + System.out.println("\n" + + "Jackpot!! Congratulations!! ;D \n" + + "Plus 1,000 tokens!"); + ; + + } else if (num1 == num2 && num1 == num3) { + //win tokens + System.out.println("\n" + + "Winner!! Plus 50 tokens! \n"); + } else { + System.out.println("\n" + + "Loser. Try again! \n"); + } + } + } while (Objects.equals(playerInput, "1")); + } + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + playSlotsGame(); + + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index f89ebd7f..1dc53ac0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -1,7 +1,36 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Player; + /** * Created by leon on 7/21/2020. */ -public class SlotsPlayer { +public class SlotsPlayer extends Player implements PlayerInterface { + Player player; + private int bet; + CasinoAccount casinoAccount; + + public SlotsPlayer(Player player, CasinoAccount casinoAccount){ + this.player = player; + this.casinoAccount = casinoAccount; + } + + public SlotsPlayer(){ + + } + + public Player getPlayer(){ + return this.player; + } + + public CasinoAccount getCasinoAccount(){ + return casinoAccount; + } + + // public void setCasinoAccount(){ + //} + + } \ No newline at end of file From e10a2e9f49b15d5e2c2e8e00ce40530a56985f50 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 14 Jul 2022 19:09:01 -0400 Subject: [PATCH 15/31] chuckaluck --- .../zipcodewilmington/casino/games/Dice.java | 10 +- .../casino/games/chuckaluck/ChuckALuck.java | 92 +++++++++++++++++++ .../games/chuckaluck/ChuckALuckPlayer.java | 4 + 3 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java b/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java index fe869156..e961e06d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Dice.java @@ -6,14 +6,14 @@ public class Dice { static List bins; private Integer numOfDice; - private Integer maxRoll = numOfDice * 6; - private Integer sum; + private Integer maxRoll; - public Dice(Integer dice) { - this.numOfDice = dice; + public Dice(Integer numOfDice) { + this.numOfDice = numOfDice; + this.maxRoll = numOfDice * 6; } - public int tossAndSum(){ + public Integer tossAndSum(){ // Roll n amount of times and return the sum of the rolls. diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java new file mode 100644 index 00000000..2ed829f8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java @@ -0,0 +1,92 @@ +package com.github.zipcodewilmington.casino.games.chuckaluck; + +import com.github.zipcodewilmington.casino.games.Dice; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Optional; + +public class ChuckALuck { + private Integer betType = 0; + private IOConsole console = new IOConsole(); + private int d1Value; + private int d2Value; + private int d3Value; + + + Dice d6 = new Dice(1); + + + String s = ("Betting Options \n\n" + + "Type of Bet: Condition: Odds:\n" + + "1. High Total of 3 dice > 10 1:1\n" + + "2. Low Total of 3 dice < 11 1:1\n" + + "3. Field Total of 3 dice < 8 or total is > 12 1:1\n" + + "4. Triples All 3 dice show same number 30:1"); + + public void printRules() { + System.out.println(s); + } + + public Integer askBetType() { + betType = console.getIntegerInput("\nPlace a bet: \n1. High\n2. Low\n3. Field\n4. Triples"); + return betType; + } + + public Integer tossDice1() { + d1Value = 1; + return d1Value; + } + public Integer tossDice2() { + this.d2Value = d6.tossAndSum(); + return d2Value; + } + public Integer tossDice3() { + this.d3Value = d6.tossAndSum(); + return d3Value; + } + + public void showRolls() { + System.out.println("\nDice: " + d1Value + " " + d2Value + " " + d3Value); + } + public Integer sumDice() { + return d1Value + d2Value + d3Value; + } + + + public boolean resultIsTriple() { + return tossDice1() == tossDice2() && tossDice1() == tossDice3(); + } + public boolean resultIsField() { + return sumDice() < 8 && sumDice() > 12; + } + public boolean isLow() { + return sumDice() < 11; + } + + public boolean win() { + Integer sum = sumDice(); + if (betType == 1 && sum > 10) { + return true; + } else return false; + } + + public void printWinOrLose() { + if (win()) { + System.out.println("You Win!"); + } else System.out.println("You lose."); + } + + public static void main(String[] args) { + ChuckALuck game = new ChuckALuck(); + game.printRules(); + while(true) { + game.askBetType(); + game.tossDice1(); + game.tossDice2(); + game.tossDice3(); + game.showRolls(); + game.printWinOrLose(); + System.out.println(game.sumDice()); + } + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java new file mode 100644 index 00000000..4f6e02d7 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java @@ -0,0 +1,4 @@ +package com.github.zipcodewilmington.casino.games.chuckaluck; + +public class ChuckALuckPlayer { +} From c50562b77efac8289fb2bae164925178ed120347 Mon Sep 17 00:00:00 2001 From: Myah Date: Thu, 14 Jul 2022 21:27:31 -0400 Subject: [PATCH 16/31] working on map & empty/filled positions --- .../casino/games/connectfour/ConnectFour.java | 13 +++++++--- .../casino/games/connectfour/Token.java | 25 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index 8c43c4b7..52187cd6 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -14,6 +14,7 @@ public class ConnectFour { static Map indexTracker = new HashMap(); public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums + private static final String ANSI_RED = "\u001B[31m"; static AnsiColor color; @@ -21,8 +22,8 @@ public class ConnectFour { static ConnectFourPlayer cfPlayer = new ConnectFourPlayer(); static Board gameBoard; - static Token userToken = new Token(AnsiColor.RED); - static Token opponentToken = new Token(AnsiColor.BLACK); + static Token userToken = new Token(); +// static Token opponentToken = new Token(AnsiColor.BLACK); static boolean winner = false; @@ -58,6 +59,8 @@ public static void main(String[] args) { static void placeUserPosition(Character[][] board, String user) { char symbol = 'X'; boolean emptyPosition = true; + boolean emptyColumn = true; + boolean emptyRow = true; int roundCounter = 1; while (emptyPosition) { //replace w try, catch block @@ -66,6 +69,9 @@ static void placeUserPosition(Character[][] board, String user) { cfPlayer.setPositionPlacement(sc.nextInt()); // setting player position based on user input int pos = cfPlayer.getPositionPlacement(); //return player's position + userToken.setSymbol(symbol); + Character tok = userToken.getSymbol(); + if(pos>8 || pos<1) { System.out.print("ERROR: invalid number"); } @@ -81,7 +87,7 @@ static void placeUserPosition(Character[][] board, String user) { indexTracker.put(board, emptyPosition); break; case 2: - board[6][3] = symbol; //column2 + board[6][3] = tok; //column2 break; case 3: board[6][5] = symbol; //column3 @@ -106,6 +112,7 @@ static void placeUserPosition(Character[][] board, String user) { System.out.println("\n\n"); System.out.print(userPositions); +// System.out.println(indexTracker.); displayGameBoard(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java index d1f5f2e1..c000306c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Token.java @@ -3,11 +3,24 @@ import com.github.zipcodewilmington.utils.AnsiColor; public class Token { - static Character symbol = 'O'; + private Character symbol; private AnsiColor color; private static final String ANSI_RED = "\u001B[31m"; private static final String ANSI_BLACK = "\u001B[30m"; + Token() { + + } + + public Character getSymbol() { + return this.symbol; + } + + public void setSymbol(Character symbol) { + this.symbol = symbol; + } + + // Token() { // this.symbol = 'O'; // this.ansiColor = AnsiColor.YELLOW; @@ -17,13 +30,11 @@ public class Token { // Token(AnsiColor color, Character ch) { // } - Token(Character ch) { - this.symbol = ch; - System.out.print(ANSI_RED+symbol); - } +// Token(Character ch) { +// this.symbol = ch; +// System.out.print(ANSI_RED+Character.toUpperCase(symbol)); +// } - public Token(AnsiColor black) { - } // @Override // public String toString() { From 50aef83fddb599700dbc70bbb506becab834f745 Mon Sep 17 00:00:00 2001 From: Myah Date: Fri, 15 Jul 2022 04:52:23 -0400 Subject: [PATCH 17/31] winner tracking implemented, position placement has bugs --- .../casino/games/connectfour/ConnectFour.java | 139 +++++++++++++++--- 1 file changed, 120 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index 52187cd6..5c39aac2 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -6,12 +6,12 @@ public class ConnectFour { - static ArrayList userPositions = new ArrayList(); - static ArrayList cpuPositions = new ArrayList(); - List userTokens = new ArrayList<>(); - List cpuTokens = new ArrayList<>(); +// static ArrayList userPositions = new ArrayList<>(); +// static ArrayList cpuPositions = new ArrayList<>(); +// List userTokens = new ArrayList<>(); +// List cpuTokens = new ArrayList<>(); - static Map indexTracker = new HashMap(); +// static Map indexTracker = new HashMap<>(); public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums private static final String ANSI_RED = "\u001B[31m"; @@ -23,9 +23,12 @@ public class ConnectFour { static Board gameBoard; static Token userToken = new Token(); + static int round = 1; + static Character player = 'R'; // static Token opponentToken = new Token(AnsiColor.BLACK); static boolean winner = false; + static boolean allowedPlacement; public static void main(String[] args) { // Character[][] board = { @@ -40,12 +43,52 @@ public static void main(String[] args) { // }; // placeUserPosition(board, "user"); // System.out.print(userToken); + int col; gameBoard = new Board(board); createGameBoard(); +// displayGameBoard(); +// placeUserPosition(board, "user"); + + + while (winner == false && round <= 42) { + + do { + displayGameBoard(); + System.out.print("Round #" + round+"\nPlayer " +player + + " , enter a number to choose column:"); + cfPlayer.setPositionPlacement(sc.nextInt()); + col = cfPlayer.getPositionPlacement(); + allowedPlacement = checkPlacement(col, board); + + } while (allowedPlacement == false); + for (int row = board.length - 1; row >=1; row--) { + if (board[row][col] == 'O') { + board[row][col] = player; //TODO + break; + } + } + winner = isWinner(player, board); + if (player =='R') { + player = 'B'; + } + else { + player ='R'; + } + round++; + } displayGameBoard(); - placeUserPosition(board, "user"); + + if (winner) { + if (player =='R') { + System.out.println("Black won!"); + } + else { + System.out.println("Red won!"); + } + System.out.println("No winners, tied game"); + } } @@ -56,35 +99,28 @@ public static void main(String[] args) { ConnectFour() { } +/* static void placeUserPosition(Character[][] board, String user) { char symbol = 'X'; - boolean emptyPosition = true; - boolean emptyColumn = true; - boolean emptyRow = true; + boolean allowedPlacement = true; int roundCounter = 1; - while (emptyPosition) { //replace w try, catch block + while (true) { //replace w try, catch block System.out.println("Round " +roundCounter +"\n"+ "Enter a position to place your token: "); cfPlayer.setPositionPlacement(sc.nextInt()); // setting player position based on user input int pos = cfPlayer.getPositionPlacement(); //return player's position + allowedPlacement = checkPlacement(pos, board); userToken.setSymbol(symbol); Character tok = userToken.getSymbol(); - if(pos>8 || pos<1) { - System.out.print("ERROR: invalid number"); - } - else { - emptyPosition = false; - } - switch (pos) { //y then x case 1: board[6][1] = symbol;//column1 userPositions.add(pos); - indexTracker.put(board, emptyPosition); +// indexTracker.put(board, emptyPosition); break; case 2: board[6][3] = tok; //column2 @@ -112,7 +148,7 @@ static void placeUserPosition(Character[][] board, String user) { System.out.println("\n\n"); System.out.print(userPositions); -// System.out.println(indexTracker.); + displayGameBoard(); } @@ -128,5 +164,70 @@ static void placeUserPosition(Character[][] board, String user) { // } + } +*/ + + + static boolean checkPlacement(int col, Character[][] board) { + boolean emptyPosition = true; + boolean emptyColumn = true; + boolean emptyRow = true; + + if (col < 1) { //TODO + System.out.print("ERROR: invalid number"); + return false; + } else if (board[1][col] != 'O') { //TODO + return false; + } + return true; + } + + + static boolean isWinner(Character player, Character[][] board) { + for (int row = 1; row < board.length; row++) { + for (int col = 1; col < board[1].length - 2; col++) { + if (board[row][col] == player && + board[row][col + 2] == player && + board[row][col + 4] == player && + board[row][col + 6] == player) { + return true; + } + } + } + + for (int row = 1; row < board.length - 3; row++) { + for (int col = 1; col < board[1].length; col++) { + if (board[row][col] == player && + board[row + 2][col] == player && + board[row + 4][col] == player && + board[row + 6][col] == player) { + return true; + } + } + } + + for (int row = 3; row < board.length; row++) { + for (int col = 1; col < board[1].length - 3; col++) { + if (board[row][col] == player && + board[row - 2][col + 2] == player && + board[row - 4][col + 4] == player && + board[row - 6][col + 6] == player) { + return true; + } + } + } + + for (int row = 1; row < board.length - 3; row++) { + for (int col = 1; col < board[1].length - 3; col++) { + if (board[row][col] == player && + board[row + 2][col + 2] == player && + board[row + 4][col + 4] == player && + board[row + 6][col + 6] == player) { + return true; + + } + } + } + return false; } } From a70afaa974280ef98ddadce63c083effb9b6dc17 Mon Sep 17 00:00:00 2001 From: Myah Date: Fri, 15 Jul 2022 07:41:52 -0400 Subject: [PATCH 18/31] position placement semi-fixed, index & winning condition bug --- .../casino/games/connectfour/Board.java | 5 +++++ .../casino/games/connectfour/ConnectFour.java | 20 +++++++------------ .../games/connectfour/ConnectFourPlayer.java | 10 +++++++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java index bbaafbde..b92a1b4c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/Board.java @@ -1,11 +1,15 @@ package com.github.zipcodewilmington.casino.games.connectfour; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + public class Board { public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums private static int length = 15; private static int width = 7; public static final Character[][] board = new Character[width][length]; + public Board(Character[][] matrix) { } @@ -35,6 +39,7 @@ static void displayGameBoard() { } System.out.println(""); } + System.out.println("\t1\t\t2\t\t3\t\t4\t\t5\t\t6\t\t7"); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index 5c39aac2..2871844c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -1,6 +1,8 @@ package com.github.zipcodewilmington.casino.games.connectfour; import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + import java.util.*; import static com.github.zipcodewilmington.casino.games.connectfour.Board.*; @@ -10,23 +12,22 @@ public class ConnectFour { // static ArrayList cpuPositions = new ArrayList<>(); // List userTokens = new ArrayList<>(); // List cpuTokens = new ArrayList<>(); - // static Map indexTracker = new HashMap<>(); public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums private static final String ANSI_RED = "\u001B[31m"; static AnsiColor color; - static Scanner sc = new Scanner(System.in); static ConnectFourPlayer cfPlayer = new ConnectFourPlayer(); static Board gameBoard; + static IOConsole con = new IOConsole(); static Token userToken = new Token(); static int round = 1; static Character player = 'R'; -// static Token opponentToken = new Token(AnsiColor.BLACK); + static int col; static boolean winner = false; static boolean allowedPlacement; @@ -43,22 +44,18 @@ public static void main(String[] args) { // }; // placeUserPosition(board, "user"); // System.out.print(userToken); - int col; - gameBoard = new Board(board); createGameBoard(); -// displayGameBoard(); -// placeUserPosition(board, "user"); while (winner == false && round <= 42) { do { displayGameBoard(); - System.out.print("Round #" + round+"\nPlayer " +player + + con.print("Round #" + round+"\nPlayer " +player + " , enter a number to choose column:"); cfPlayer.setPositionPlacement(sc.nextInt()); - col = cfPlayer.getPositionPlacement(); + col = cfPlayer.getPositionPlacement()*2-1; allowedPlacement = checkPlacement(col, board); } while (allowedPlacement == false); @@ -79,6 +76,7 @@ public static void main(String[] args) { round++; } displayGameBoard(); + System.out.println(""); if (winner) { if (player =='R') { @@ -169,10 +167,6 @@ static void placeUserPosition(Character[][] board, String user) { static boolean checkPlacement(int col, Character[][] board) { - boolean emptyPosition = true; - boolean emptyColumn = true; - boolean emptyRow = true; - if (col < 1) { //TODO System.out.print("ERROR: invalid number"); return false; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java index a5c42054..56935dcd 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java @@ -1,6 +1,9 @@ package com.github.zipcodewilmington.casino.games.connectfour; -public class ConnectFourPlayer { +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class ConnectFourPlayer implements PlayerInterface { int positionPlacement; public int getPositionPlacement() { @@ -9,4 +12,9 @@ public int getPositionPlacement() { public void setPositionPlacement(int chosenPosition) { this.positionPlacement = chosenPosition; } + + @Override + public CasinoAccount getCasinoAccount() { + return null; + } } From 6a02c7d568e6f55302760d446118e2ab09128507 Mon Sep 17 00:00:00 2001 From: Chris Kent Date: Fri, 15 Jul 2022 08:28:08 -0400 Subject: [PATCH 19/31] Added to DeckofCards Class --- .../casino/games/DeckOfCards.java | 34 +++++++++++++++++++ .../casino/games/deckOfCards.java | 22 ------------ 2 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java delete mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java new file mode 100644 index 00000000..c71f9fda --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java @@ -0,0 +1,34 @@ +package com.github.zipcodewilmington.casino.games; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DeckOfCards extends ArrayList { + private ArrayList deck; + + + + public DeckOfCards(ArrayList deck) { + this.deck = deck; + } + + public ArrayList shuffle(){ + Collections.shuffle(deck); + return deck; + } + + + public DeckOfCards(){ + List suits = Card.getValidSuits(); + + List faceNames = Card.getValidFaceNames(); + + deck = new ArrayList(); + + for (String suit: suits){ + for (String faceName: faceNames){ + deck.add(new Card(faceName, suit)); + } + } + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java deleted file mode 100644 index 9bdbf452..00000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/deckOfCards.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.zipcodewilmington; -import java.util.ArrayList; - -public class DeckOfCards { - private ArrayList deck; - - - - public DeckOfCards(ArrayList deck) { - this.deck = deck; - } - - - - public DeckOfCards(){ - List suits = - - List faceNames = - - deck = new ArrayList(); - } -} From aa4e65649459a8b047ab40fdedea507e34826c87 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 15 Jul 2022 08:43:00 -0400 Subject: [PATCH 20/31] more betting options --- .../casino/games/chuckaluck/ChuckALuck.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java index 2ed829f8..19970d5a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java @@ -33,7 +33,7 @@ public Integer askBetType() { } public Integer tossDice1() { - d1Value = 1; + d1Value = d6.tossAndSum(); return d1Value; } public Integer tossDice2() { @@ -53,21 +53,28 @@ public Integer sumDice() { } - public boolean resultIsTriple() { - return tossDice1() == tossDice2() && tossDice1() == tossDice3(); - } - public boolean resultIsField() { - return sumDice() < 8 && sumDice() > 12; - } - public boolean isLow() { - return sumDice() < 11; - } +// public boolean resultIsTriple() { +// return tossDice1() == tossDice2() && tossDice1() == tossDice3(); +// } +// public boolean resultIsField() { +// return sumDice() < 8 && sumDice() > 12; +// } +// public boolean isLow() { +// return sumDice() < 11; +// } public boolean win() { Integer sum = sumDice(); if (betType == 1 && sum > 10) { return true; - } else return false; + } else if (betType == 2 && sum < 11) { + return true; + } else if (betType == 3 && (sum < 8 && sum > 12)) { + return true; + } else if (betType == 4 && (tossDice1() == tossDice2() && tossDice1() == tossDice3())) { + return true; + } + else return false; } public void printWinOrLose() { From 8f5343db2f663b55a2f261176efdc019f9bd2c02 Mon Sep 17 00:00:00 2001 From: Dejen Date: Fri, 15 Jul 2022 09:06:29 -0400 Subject: [PATCH 21/31] doubleDown --- .../casino/blackjack/BlackJackGame.java | 176 +++++++++--------- .../casino/blackjack/BlackJackPlayer.java | 4 + .../zipcodewilmington/BlackJackGameTest.java | 82 -------- 3 files changed, 89 insertions(+), 173 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackPlayer.java delete mode 100644 src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java index 00838a5f..e6da3a21 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackGame.java @@ -1,6 +1,5 @@ package com.github.zipcodewilmington.casino.blackjack; -import java.sql.SQLOutput; import java.util.InputMismatchException; import java.util.Scanner; import java.util.Random; @@ -8,8 +7,8 @@ public class BlackJackGame { - int playerAmount = 0; - int dealerAmount = 0; + int playerHand = 0; + int dealerHand = 0; int playerChips = 500; @@ -23,29 +22,37 @@ public static void main(String[] args) { void playGame() { - getDealerAmount(); +Scanner scan = new Scanner(System.in); + welcomeStatement(); - getPlayerBet(); - dealerRecap(); - - while (playerAmount < 21 && playerAmount <= dealerAmount){ - Scanner scan = new Scanner(System.in); - if ((playerBet * 2) < playerChips); - System.out.println("Kiddo, type 'dd' to double down, or hit enter to draw"); - String respond = scan.nextLine(); - System.out.println(respond); - if (respond == "dd"){ - doubleDown(); + showPlayerBet(); + showDealerHand1(); + dealerRecap1(); + playerRecap(); + scan.nextLine(); + showPlayerDraw(); + showDealerHand2(); + dealerRecap2(); + while (playerHand < 21 && playerHand <= dealerHand) { + if ((playerChips - playerBet) > playerBet) { + System.out.println("Right now you got " + playerHand + ". Type 'dd' to double down, or hit enter to draw"); + String respond = scan.nextLine(); + if (respond.equals("dd")) { + doubleDown(); + } else { + showPlayerDraw(); + } }else{ - playerDraw(); + playerRecap(); + scan.nextLine(); + showPlayerDraw(); } - } - if (playerAmount <= 21 && playerAmount > dealerAmount){ - playerWins(playerChips, playerBet); - } else if (playerAmount > 21){ - dealerWins(playerChips, playerBet); + if (playerHand <= 21 && playerHand > dealerHand){ + playerWins(); + } else if (playerHand > 21){ + dealerWins(); } } @@ -56,78 +63,100 @@ private void welcomeStatement(){ System.out.println("Let's jack it up!\n"); } - public int getDealerAmount(){ + private int showDealerHand1(){ + dealerHand = 10; + return dealerHand; + } + + private int showDealerHand2(){ Random random = new Random(); - int min = 17; - int max = 3; - int dealerNum = min + random.nextInt(max); - dealerAmount = dealerNum; - return dealerAmount; + int min = 6; + int max = 4; + dealerHand += min + random.nextInt(max); + return dealerHand; } - public void dealerRecap() { - System.out.println("It looks like the dealer has pulled a " + dealerAmount + ". See if you can beat that."); + public void dealerRecap1() { + System.out.println("It looks like the dealer has pulled a " + dealerHand + "."); + } + public void dealerRecap2() { + System.out.println("It looks like the dealer has pulled a " + dealerHand + ". See if you can beat that."); } - public int playerDraw() { + public void playerRecap(){ + System.out.println("Right now you got " + playerHand + ". Hit enter to draw"); + } + + private int showPlayerBet(){ + Scanner scan = new Scanner(System.in); + System.out.println("How many chips are ya bettin'?"); + try { + playerBet = scan.nextInt(); + } catch (InputMismatchException e) { + System.out.println("That ain't a number I ever heard of."); + showPlayerBet(); + } + if (playerBet > playerChips){ + System.out.println("That bet is too big for your britches. Try a smaller amount."); + showPlayerBet(); + }else if (playerBet < 0) { + System.out.println("Hey, don't try it with the funny business!"); + showPlayerBet(); + } + return playerBet; + } + + + private int showPlayerDraw() { Random random = new Random(); Scanner scan = new Scanner(System.in); int min = 1; - System.out.println("OK kid, you got " + playerAmount + ". Draw a card and see if you can win."); - System.out.println("Hit enter to draw"); - scan.nextLine(); -// int nextDraw = min + random.nextInt(9); - int nextDraw = 11; + int nextDraw = min + random.nextInt(9); if (nextDraw == 1 || nextDraw == 11){ aces(); } else{ - playerAmount += nextDraw; + playerHand += nextDraw; System.out.println("Ya drew a " + nextDraw + "!"); } - return playerAmount; + return playerHand; } - public void aces() { + private int aces() { int nextDraw = 0; Scanner scan = new Scanner(System.in); - System.out.println("Choose if you want this Ace to be a 1 or an 11."); -// try {int nextDraw = scan.nextInt(); -// } catch (InputMismatchException e) { -// System.out.println("That ain't a number I ever heard of."); -// aces();} + System.out.println("Ooh, an Ace! Choose if you want this Ace to be a 1 or an 11."); try {nextDraw = scan.nextInt(); } catch (InputMismatchException e) { System.out.println("That ain't a number I ever heard of."); aces(); - } if (nextDraw == 1 || nextDraw == 11) { - playerAmount += nextDraw; + playerHand += nextDraw; System.out.println("Ya drew a " + nextDraw + "!"); }else{ System.out.println("Nice try."); aces(); } - + return playerHand; } - public void playerWins(int playerChips, int playerBet){ + public void playerWins(){ Scanner scan = new Scanner(System.in); playerChips += playerBet; - System.out.println("Wowzers, you got " + playerAmount + " and won " + playerBet + " chips! You now have " + playerChips + " chips!"); - playerAmount = 0; + System.out.println("Woah! You got " + playerHand + " and won " + playerBet + " chips! You now have " + playerChips + " chips! Hit enter to try again."); + playerHand = 0; scan.nextLine(); playGame(); } - public void dealerWins(int playerChips, int playerBet){ + public void dealerWins(){ Scanner scan = new Scanner(System.in); playerChips-=playerBet; - System.out.println(playerAmount + "! Welp, them's the breaks, kid. You lost " + playerBet + " chips and now have " + playerChips + " chips."); - playerAmount = 0; + System.out.println(playerHand + "! Welp, them's the breaks, kid. You lost " + playerBet + " chips and now have " + playerChips + " chips. Hit enter to play again."); + playerHand = 0; scan.nextLine(); playGame(); } @@ -135,49 +164,14 @@ public void dealerWins(int playerChips, int playerBet){ public void doubleDown(){ playerBet = playerBet * 2; System.out.println("OK kid, this next one is for all da marbles! Let's see what cha got!"); - playerDraw(); - if (playerAmount <= 21 && playerAmount > dealerAmount){ - playerWins(playerChips, playerBet); + showPlayerDraw(); + if (playerHand <= 21 && playerHand > dealerHand){ + playerWins(); } else{ - dealerWins(playerChips, playerBet); + dealerWins(); } } - - public int getPlayerBet(){ - Scanner scan = new Scanner(System.in); - System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); - try { - playerBet = scan.nextInt(); - } catch (InputMismatchException e) { - System.out.println("That ain't a number I ever heard of."); - getPlayerBet(); - - } - if (playerBet > playerChips){ - System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); - getPlayerBet(); - }else if (playerBet < 0) { - System.out.println("Hey, don't try it with the funny business!"); - getPlayerBet(); - } - return playerBet; - } - - - - } -// int getNumb(String message) { -// -// Scanner scan = new Scanner(System.in); -// while (true) { -// System.out.print(message); -// try { -// return scan.nextInt(); -// } -// catch (InputMismatchException e) { -// System.out.println("\"" + scan.next() + "\" isn't a number!"); - diff --git a/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackPlayer.java new file mode 100644 index 00000000..4d0bdc2e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/blackjack/BlackJackPlayer.java @@ -0,0 +1,4 @@ +package com.github.zipcodewilmington.casino.blackjack; + +public class BlackJackPlayer { +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java deleted file mode 100644 index 9f77f95d..00000000 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.github.zipcodewilmington; - -import org.junit.Test; - -import java.util.Random; -import java.util.Scanner; - -import static org.junit.Assert.*; - -public class BlackJackGameTest { - @Test - public void getDealerAmount() { - Random random = new Random(); - int min = 17; - int max = 3; - int dealerNum = min + random.nextInt(max); - int dealerAmount = dealerNum; - assert (dealerAmount > 16 && dealerAmount <21); - } - - @Test public void dealerWinsTest() { - int playerChips = 700; - int playerBet = 50; - playerChips -= playerBet; - assert(playerChips == 650); - } - - - // @Test -// public void getPlayerBetGood(){ -// int playerChips = 50; -// int bet = 45; -// Scanner scan = new Scanner(System.in); -// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); -// int playerBet = bet; -// if (playerBet > playerChips){ -// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); -// }else if (playerBet < 0) { -// System.out.println("Hey, don't try it with the funny business!"); -// } -//assert (playerBet == bet); -// -// } -// -// -// @Test -// public void getPlayerBetOver(){ -// int playerChips = 50; -// int bet = 55; -// Scanner scan = new Scanner(System.in); -// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); -// int playerBet = bet; -// if (playerBet > playerChips){ -// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); -// playerBet = 0; -// }else if (playerBet < 0) { -// System.out.println("Hey, don't try it with the funny business!"); -// playerBet = 25; -// } -// assert (playerBet == 0); -// -// } -// -// @Test -// public void getPlayerBetUnder0(){ -// int playerChips = 50; -// int bet = -27; -// Scanner scan = new Scanner(System.in); -// System.out.println("How many chips are ya bettin'? Bet 0 if ya want!"); -// int playerBet = bet; -// if (playerBet > playerChips){ -// System.out.println("Kid, that bet is too big for your britches. Try a smaller amount."); -// playerBet = 25; -// }else if (playerBet < 0) { -// System.out.println("Hey, don't try it with the funny business!"); -// playerBet = 0; -// } -// assert (playerBet == 0); -// -// } - -} \ No newline at end of file From 9e3ab4ed957d936bab6f9d1b13ef292a9e5db569 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 Jul 2022 10:32:45 -0400 Subject: [PATCH 22/31] worked on connect 4 player --- .../com/github/zipcodewilmington/Casino.java | 6 +- .../casino/games/connectfour/ConnectFour.java | 164 ++++++++++-------- .../games/connectfour/ConnectFourPlayer.java | 30 +++- 3 files changed, 120 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index e27eeea6..f29b4d1f 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,6 +4,8 @@ import com.github.zipcodewilmington.casino.CasinoAccountManager; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.connectfour.ConnectFour; +import com.github.zipcodewilmington.casino.games.connectfour.ConnectFourPlayer; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; @@ -39,8 +41,8 @@ public void run() { // play(new CeeloGame(), new CeeloPlayer()); // } else if (gameSelectionInput.equals("CHUCK A LUCK")) { // play(new ChuckALuckGame(), new ChuckALuckPlayer()); -// } else if (gameSelectionInput.equals("CONNECT 4")) { -// play(new Connect4Game(), new Connect4Player()); + } else if (gameSelectionInput.equals("CONNECT 4")) { + play(new ConnectFour(), new ConnectFourPlayer()); // } else if (gameSelectionInput.equals("BLACKJACK")) { // play(new BlackjackGame(), new BlackjackPlayer()); // }else if (gameSelectionInput.equals("WAR")) { diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java index 2871844c..6fe074ad 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFour.java @@ -1,5 +1,7 @@ package com.github.zipcodewilmington.casino.games.connectfour; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; @@ -7,31 +9,33 @@ import static com.github.zipcodewilmington.casino.games.connectfour.Board.*; -public class ConnectFour { +public class ConnectFour implements GameInterface { // static ArrayList userPositions = new ArrayList<>(); // static ArrayList cpuPositions = new ArrayList<>(); // List userTokens = new ArrayList<>(); // List cpuTokens = new ArrayList<>(); // static Map indexTracker = new HashMap<>(); - public static final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums - private static final String ANSI_RED = "\u001B[31m"; - static AnsiColor color; + public void playConnectFour() { - static Scanner sc = new Scanner(System.in); - static ConnectFourPlayer cfPlayer = new ConnectFourPlayer(); - static Board gameBoard; - static IOConsole con = new IOConsole(); + final String ANSI_YELLOW = "\u001B[33m"; //replace with AnsiColor enums + final String ANSI_RED = "\u001B[31m"; + AnsiColor color; - static Token userToken = new Token(); - static int round = 1; - static Character player = 'R'; + Scanner sc = new Scanner(System.in); + ConnectFourPlayer cfPlayer = new ConnectFourPlayer(); + Board gameBoard; + IOConsole con = new IOConsole(); - static int col; - static boolean winner = false; - static boolean allowedPlacement; + Token userToken = new Token(); + int round = 1; + Character player = 'R'; - public static void main(String[] args) { + int col; + boolean winner = false; + boolean allowedPlacement; + + //public static void main(String[] args) { // Character[][] board = { // {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'}, // {'|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|', 'O', '|'}, @@ -44,6 +48,7 @@ public static void main(String[] args) { // }; // placeUserPosition(board, "user"); // System.out.print(userToken); + gameBoard = new Board(board); createGameBoard(); @@ -52,14 +57,14 @@ public static void main(String[] args) { do { displayGameBoard(); - con.print("Round #" + round+"\nPlayer " +player + + con.print("Round #" + round + "\nPlayer " + player + " , enter a number to choose column:"); cfPlayer.setPositionPlacement(sc.nextInt()); - col = cfPlayer.getPositionPlacement()*2-1; + col = cfPlayer.getPositionPlacement() * 2 - 1; allowedPlacement = checkPlacement(col, board); } while (allowedPlacement == false); - for (int row = board.length - 1; row >=1; row--) { + for (int row = board.length - 1; row >= 1; row--) { if (board[row][col] == 'O') { board[row][col] = player; //TODO break; @@ -67,11 +72,10 @@ public static void main(String[] args) { } winner = isWinner(player, board); - if (player =='R') { + if (player == 'R') { player = 'B'; - } - else { - player ='R'; + } else { + player = 'R'; } round++; } @@ -79,23 +83,21 @@ public static void main(String[] args) { System.out.println(""); if (winner) { - if (player =='R') { + if (player == 'R') { System.out.println("Black won!"); - } - else { + } else { System.out.println("Red won!"); } System.out.println("No winners, tied game"); } - } - ConnectFour(ConnectFourPlayer player) { - this.cfPlayer = player; - } +// ConnectFour(ConnectFourPlayer player) { +// this.player = cfPlayer; +// } - ConnectFour() { - } +// ConnectFour() { +// } /* static void placeUserPosition(Character[][] board, String user) { @@ -164,64 +166,80 @@ static void placeUserPosition(Character[][] board, String user) { } */ + } - - static boolean checkPlacement(int col, Character[][] board) { - if (col < 1) { //TODO - System.out.print("ERROR: invalid number"); - return false; - } else if (board[1][col] != 'O') { //TODO - return false; + static boolean checkPlacement ( int col, Character[][] board){ + if (col < 1) { //TODO + System.out.print("ERROR: invalid number"); + return false; + } else if (board[1][col] != 'O') { //TODO + return false; + } + return true; } - return true; - } - static boolean isWinner(Character player, Character[][] board) { - for (int row = 1; row < board.length; row++) { - for (int col = 1; col < board[1].length - 2; col++) { - if (board[row][col] == player && - board[row][col + 2] == player && - board[row][col + 4] == player && - board[row][col + 6] == player) { - return true; + static boolean isWinner (Character player, Character[][]board){ + for (int row = 1; row < board.length; row++) { + for (int col = 1; col < board[1].length - 2; col++) { + if (board[row][col] == player && + board[row][col + 2] == player && + board[row][col + 4] == player && + board[row][col + 6] == player) { + return true; + } } } - } - for (int row = 1; row < board.length - 3; row++) { - for (int col = 1; col < board[1].length; col++) { - if (board[row][col] == player && - board[row + 2][col] == player && - board[row + 4][col] == player && - board[row + 6][col] == player) { - return true; + for (int row = 1; row < board.length - 3; row++) { + for (int col = 1; col < board[1].length; col++) { + if (board[row][col] == player && + board[row + 2][col] == player && + board[row + 4][col] == player && + board[row + 6][col] == player) { + return true; + } } } - } - for (int row = 3; row < board.length; row++) { - for (int col = 1; col < board[1].length - 3; col++) { - if (board[row][col] == player && - board[row - 2][col + 2] == player && - board[row - 4][col + 4] == player && - board[row - 6][col + 6] == player) { - return true; + for (int row = 3; row < board.length; row++) { + for (int col = 1; col < board[1].length - 3; col++) { + if (board[row][col] == player && + board[row - 2][col + 2] == player && + board[row - 4][col + 4] == player && + board[row - 6][col + 6] == player) { + return true; + } } } - } - for (int row = 1; row < board.length - 3; row++) { - for (int col = 1; col < board[1].length - 3; col++) { - if (board[row][col] == player && - board[row + 2][col + 2] == player && - board[row + 4][col + 4] == player && - board[row + 6][col + 6] == player) { - return true; + for (int row = 1; row < board.length - 3; row++) { + for (int col = 1; col < board[1].length - 3; col++) { + if (board[row][col] == player && + board[row + 2][col + 2] == player && + board[row + 4][col + 4] == player && + board[row + 6][col + 6] == player) { + return true; + } } } + return false; } - return false; + + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + playConnectFour(); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java index 56935dcd..afed7312 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/connectfour/ConnectFourPlayer.java @@ -2,9 +2,29 @@ import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Player; -public class ConnectFourPlayer implements PlayerInterface { +public class ConnectFourPlayer extends Player implements PlayerInterface { int positionPlacement; + Player player; + CasinoAccount casinoAccount; + + public ConnectFourPlayer(Player player, CasinoAccount casinoAccount){ + this.player = player; + this.casinoAccount = casinoAccount; + } + + public ConnectFourPlayer(){ + + } + + public Player getPlayer(){ + return this.player; + } + + public CasinoAccount getCasinoAccount(){ + return casinoAccount; + } public int getPositionPlacement() { return positionPlacement; @@ -13,8 +33,8 @@ public void setPositionPlacement(int chosenPosition) { this.positionPlacement = chosenPosition; } - @Override - public CasinoAccount getCasinoAccount() { - return null; - } +// @Override + //public CasinoAccount getCasinoAccount() { +// return null; +// } } From 6e7502560828405f16749d2708bb2d220b71d13c Mon Sep 17 00:00:00 2001 From: Chris Kent Date: Fri, 15 Jul 2022 12:39:47 -0400 Subject: [PATCH 23/31] Fixed DeckOfCards and started updating Card class --- .../zipcodewilmington/casino/games/Card.java | 2 ++ .../casino/games/DeckOfCards.java | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java index 9267e679..762b7268 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java @@ -5,6 +5,7 @@ public class Card { private String faceName, suit; + private int value; public String getFaceName() { return faceName; @@ -43,6 +44,7 @@ public void setSuit(String suit) { throw new IllegalArgumentException("valid suits are: " + validSuits); } + public String toString(){ return String.format("%s of %s", faceName, suit); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java index c71f9fda..e8495b6e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java @@ -1,9 +1,10 @@ package com.github.zipcodewilmington.casino.games; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class DeckOfCards extends ArrayList { +public class DeckOfCards { private ArrayList deck; @@ -12,18 +13,37 @@ public DeckOfCards(ArrayList deck) { this.deck = deck; } + public ArrayList getDeck() { + return deck; + } + + public void setDeck(ArrayList deck) { + this.deck = deck; + } + public ArrayList shuffle(){ - Collections.shuffle(deck); + Collections.shuffle(deck); return deck; } + public int size(){ + return deck.size(); + } + + public Card get(int i){ + return deck.get(i); + } + + public Card draw(){ + return deck.remove(0); + } public DeckOfCards(){ List suits = Card.getValidSuits(); List faceNames = Card.getValidFaceNames(); - deck = new ArrayList(); + deck = new ArrayList<>(); for (String suit: suits){ for (String faceName: faceNames){ From 1b3d122bb49027a583b8ada56baf3b06e0ea93b7 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 Jul 2022 14:00:48 -0400 Subject: [PATCH 24/31] updated casino class: no longer makes you log in after creating account, type numbers for selection --- .../com/github/zipcodewilmington/Casino.java | 70 +++++++++++-------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index f29b4d1f..6be31374 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -13,6 +13,8 @@ import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; +import java.util.Objects; + /** * Created by leon on 7/21/2020. */ @@ -27,44 +29,31 @@ public void run() { do { arcadeDashBoardInput = getArcadeDashboardInput(); - if ("select-game".equals(arcadeDashBoardInput)) { - String accountName = console.getStringInput("Enter your account name:"); - String accountPassword = console.getStringInput("Enter your account password:"); - CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); - boolean isValidLogin = casinoAccount != null; - if (isValidLogin) { - - String gameSelectionInput = getGameSelectionInput().toUpperCase(); - if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer()); -// } else if (gameSelectionInput.equals("CEE-LO")) { -// play(new CeeloGame(), new CeeloPlayer()); -// } else if (gameSelectionInput.equals("CHUCK A LUCK")) { -// play(new ChuckALuckGame(), new ChuckALuckPlayer()); - } else if (gameSelectionInput.equals("CONNECT 4")) { - play(new ConnectFour(), new ConnectFourPlayer()); -// } else if (gameSelectionInput.equals("BLACKJACK")) { -// play(new BlackjackGame(), new BlackjackPlayer()); -// }else if (gameSelectionInput.equals("WAR")) { -// play(new WarGame(), new WarPlayer()); - } else { - // TODO - implement better exception handling - String errorMessage = "[ %s ] is an invalid game selection"; - throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); - } - } else{ + if ("2".equals(arcadeDashBoardInput)) { //log-in + + String accountName = console.getStringInput("Enter your account name:"); + String accountPassword = console.getStringInput("Enter your account password:"); + CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); + boolean isValidLogin = casinoAccount != null; + if (isValidLogin) { + displayGameMenu(); + + + } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; - throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); + throw new RuntimeException(String.format(errorMessage, accountName, accountPassword)); } - } else if ("create-account".equals(arcadeDashBoardInput)) { + + } else if ("1".equals(arcadeDashBoardInput)) { //create-account console.println("Welcome to the account-creation screen."); String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); casinoAccountManager.registerAccount(newAccount); + displayGameMenu(); } } while(!"logout".equals(arcadeDashBoardInput)); @@ -73,12 +62,33 @@ public void run() { } } + private void displayGameMenu(){ + String gameSelectionInput = getGameSelectionInput().toUpperCase(); + if (gameSelectionInput.equals("1")) { //slots + play(new SlotsGame(), new SlotsPlayer()); +// } else if (gameSelectionInput.equals("2")) { //cee-lo +// play(new CeeloGame(), new CeeloPlayer()); +// } else if (gameSelectionInput.equals("3")) { //chuck a luck +// play(new ChuckALuckGame(), new ChuckALuckPlayer()); + } else if (gameSelectionInput.equals("4")) { //connect four + play(new ConnectFour(), new ConnectFourPlayer()); +// } else if (gameSelectionInput.equals("5")) { //blackjack +// play(new BlackjackGame(), new BlackjackPlayer()); +// }else if (gameSelectionInput.equals("6")) { //war +// play(new WarGame(), new WarPlayer()); + } else { + // TODO - implement better exception handling + String errorMessage = "[ %s ] is an invalid game selection"; + throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); + } + } + private String getArcadeDashboardInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Arcade Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ]") + .append("\n\t[ 1. create-account ], [ 2. log-in ]") .toString()); } @@ -86,7 +96,7 @@ private String getGameSelectionInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Game Selection Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ CEE-LO ], [ CHUCK A LUCK], [ CONNECT 4 ], [ BLACKJACK ], [ WAR ]") + .append("\n\t[ 1. SLOTS ], [ 2. CEE-LO ], [ 3. CHUCK A LUCK], [ 4. CONNECT 4 ], [ 5. BLACKJACK ], [ 6. WAR ]") .toString()); } From eba721a390aa00040ae92d5d83f2f13ea8d99abc Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 15 Jul 2022 16:00:15 -0400 Subject: [PATCH 25/31] chuckaluck game and player updates --- savedAccounts.txt | 1 + .../{ChuckALuck.java => ChuckALuckGame.java} | 28 ++++++++++++++----- .../games/chuckaluck/ChuckALuckPlayer.java | 28 ++++++++++++++++++- .../casino/CasinoAccountManagerTest.java | 4 +++ 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 savedAccounts.txt rename src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/{ChuckALuck.java => ChuckALuckGame.java} (85%) create mode 100644 src/test/java/com/github/zipcodewilmington/casino/CasinoAccountManagerTest.java diff --git a/savedAccounts.txt b/savedAccounts.txt new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/savedAccounts.txt @@ -0,0 +1 @@ +test diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java similarity index 85% rename from src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java rename to src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java index 19970d5a..10ff6be5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuck.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java @@ -1,21 +1,19 @@ package com.github.zipcodewilmington.casino.games.chuckaluck; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.casino.games.Dice; import com.github.zipcodewilmington.utils.IOConsole; -import java.util.Optional; - -public class ChuckALuck { +public class ChuckALuckGame implements GameInterface { private Integer betType = 0; private IOConsole console = new IOConsole(); private int d1Value; private int d2Value; private int d3Value; - Dice d6 = new Dice(1); - String s = ("Betting Options \n\n" + "Type of Bet: Condition: Odds:\n" + "1. High Total of 3 dice > 10 1:1\n" @@ -83,8 +81,8 @@ public void printWinOrLose() { } else System.out.println("You lose."); } - public static void main(String[] args) { - ChuckALuck game = new ChuckALuck(); + public static void playChuckALuckGame() { + ChuckALuckGame game = new ChuckALuckGame(); game.printRules(); while(true) { game.askBetType(); @@ -96,4 +94,20 @@ public static void main(String[] args) { System.out.println(game.sumDice()); } } + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + playChuckALuckGame(); + + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java index 4f6e02d7..a98d5e78 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java @@ -1,4 +1,30 @@ package com.github.zipcodewilmington.casino.games.chuckaluck; -public class ChuckALuckPlayer { +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Player; + +public class ChuckALuckPlayer extends Player implements PlayerInterface { + + Player player; + CasinoAccount casinoAccount; + + public ChuckALuckPlayer(Player player, CasinoAccount casinoAccount){ + this.player = player; + this.casinoAccount = casinoAccount; + } + + public ChuckALuckPlayer(){ + + } + + public Player getPlayer(){ + return this.player; + } + + @Override + public CasinoAccount getCasinoAccount() { + return casinoAccount; + } } diff --git a/src/test/java/com/github/zipcodewilmington/casino/CasinoAccountManagerTest.java b/src/test/java/com/github/zipcodewilmington/casino/CasinoAccountManagerTest.java new file mode 100644 index 00000000..a14fe7ec --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/CasinoAccountManagerTest.java @@ -0,0 +1,4 @@ +import static org.junit.Assert.*; +public class CasinoAccountManagerTest { + +} \ No newline at end of file From 8b6c772515d5b97be453ac1c10da627c32e39a0a Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 Jul 2022 16:14:44 -0400 Subject: [PATCH 26/31] added code to include chuckaluck in game options --- src/main/java/com/github/zipcodewilmington/Casino.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 6be31374..918255ab 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,6 +4,8 @@ import com.github.zipcodewilmington.casino.CasinoAccountManager; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.chuckaluck.ChuckALuckGame; +import com.github.zipcodewilmington.casino.games.chuckaluck.ChuckALuckPlayer; import com.github.zipcodewilmington.casino.games.connectfour.ConnectFour; import com.github.zipcodewilmington.casino.games.connectfour.ConnectFourPlayer; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; @@ -68,8 +70,8 @@ private void displayGameMenu(){ play(new SlotsGame(), new SlotsPlayer()); // } else if (gameSelectionInput.equals("2")) { //cee-lo // play(new CeeloGame(), new CeeloPlayer()); -// } else if (gameSelectionInput.equals("3")) { //chuck a luck -// play(new ChuckALuckGame(), new ChuckALuckPlayer()); + } else if (gameSelectionInput.equals("3")) { //chuck a luck + play(new ChuckALuckGame(), new ChuckALuckPlayer()); } else if (gameSelectionInput.equals("4")) { //connect four play(new ConnectFour(), new ConnectFourPlayer()); // } else if (gameSelectionInput.equals("5")) { //blackjack From 4e8e7a2bec0d41d542a1fc36fd119d165ae93908 Mon Sep 17 00:00:00 2001 From: Chris Kent Date: Fri, 15 Jul 2022 16:28:26 -0400 Subject: [PATCH 27/31] Updated Card and DeckOfCardsClass: started adding value element to Card and updated Draw method --- .../zipcodewilmington/casino/games/Card.java | 18 ++++++++++++- .../casino/games/DeckOfCards.java | 27 ++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java index 762b7268..3782e1cd 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java @@ -1,5 +1,8 @@ package com.github.zipcodewilmington.casino.games; +import com.sun.security.jgss.InquireSecContextPermission; + +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -44,13 +47,26 @@ public void setSuit(String suit) { throw new IllegalArgumentException("valid suits are: " + validSuits); } + public int getValue(){ + return value; + } + + public void setValue(int value){ + if(value > 0 && value < 15) { + this.value = value; + } + else{ + throw new IllegalArgumentException("Valid value is 1 to 14" ); + } + } public String toString(){ return String.format("%s of %s", faceName, suit); } - public Card(String faceName, String suit) { + public Card(String faceName, String suit, int value) { setFaceName(faceName); setSuit(suit); + setValue(value); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java index e8495b6e..7c6024f4 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java @@ -1,13 +1,17 @@ package com.github.zipcodewilmington.casino.games; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; public class DeckOfCards { private ArrayList deck; - - + private Card drawnCard; + private boolean blackJackTrueWarFalse; + private ArrayList deckSelector; + private ArrayList warValues = (ArrayList) Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); + private ArrayList blackJackValues = (ArrayList) Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11); public DeckOfCards(ArrayList deck) { this.deck = deck; @@ -35,20 +39,31 @@ public Card get(int i){ } public Card draw(){ - return deck.remove(0); + drawnCard = deck.get(0); + deck.remove(0); + return drawnCard; } - public DeckOfCards(){ - List suits = Card.getValidSuits(); + public DeckOfCards(boolean blackJackTrueWarFalse){ + if(blackJackTrueWarFalse == true){ + deckSelector.addAll(blackJackValues); + } + else{ + deckSelector.addAll(warValues); + } + List suits = Card.getValidSuits(); List faceNames = Card.getValidFaceNames(); deck = new ArrayList<>(); for (String suit: suits){ for (String faceName: faceNames){ - deck.add(new Card(faceName, suit)); + deck.add(new Card(faceName, suit, 1)); } +// for (int i = 0; i < deck.size();i++){ +// deck.set(i, ); +// } } } } From c74303a2853495c3ed688d25882f1a70ae570243 Mon Sep 17 00:00:00 2001 From: Chris Kent Date: Sat, 16 Jul 2022 12:40:40 -0400 Subject: [PATCH 28/31] Finished Card and DeckofCards Class --- .../zipcodewilmington/casino/games/Card.java | 21 +++++++++++----- .../casino/games/DeckOfCards.java | 25 ++++++------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java index 3782e1cd..141bbc7d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java @@ -23,7 +23,7 @@ public void setFaceName(String faceName) { List validFaceNames = getValidFaceNames(); faceName = faceName.toLowerCase(); if (validFaceNames.contains(faceName)){ - this.faceName = faceName;} + this.faceName = faceName;} else throw new IllegalArgumentException("Valid face names are: " + validFaceNames); } @@ -47,10 +47,23 @@ public void setSuit(String suit) { throw new IllegalArgumentException("valid suits are: " + validSuits); } + public String toString(){ + return String.format("%s of %s", faceName, suit); + } + public int getValue(){ return value; } + public static List getValidValues(){ + if (DeckOfCards.blackJackTrueWarFalse == true){ + return Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11); + } + else{ + return Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); + } + } + public void setValue(int value){ if(value > 0 && value < 15) { this.value = value; @@ -60,11 +73,7 @@ public void setValue(int value){ } } - public String toString(){ - return String.format("%s of %s", faceName, suit); - } - - public Card(String faceName, String suit, int value) { + public Card(String faceName, String suit, Integer value) { setFaceName(faceName); setSuit(suit); setValue(value); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java index 7c6024f4..f4f69ee9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/DeckOfCards.java @@ -8,10 +8,7 @@ public class DeckOfCards { private ArrayList deck; private Card drawnCard; - private boolean blackJackTrueWarFalse; - private ArrayList deckSelector; - private ArrayList warValues = (ArrayList) Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); - private ArrayList blackJackValues = (ArrayList) Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11); + public static boolean blackJackTrueWarFalse; public DeckOfCards(ArrayList deck) { this.deck = deck; @@ -44,26 +41,20 @@ public Card draw(){ return drawnCard; } - public DeckOfCards(boolean blackJackTrueWarFalse){ - if(blackJackTrueWarFalse == true){ - deckSelector.addAll(blackJackValues); - } - else{ - deckSelector.addAll(warValues); - } - + public DeckOfCards(){ List suits = Card.getValidSuits(); List faceNames = Card.getValidFaceNames(); + List values = Card.getValidValues(); deck = new ArrayList<>(); - + int i; for (String suit: suits){ + i = 0; for (String faceName: faceNames){ - deck.add(new Card(faceName, suit, 1)); + deck.add(new Card(faceName, suit, values.get(i))); +// System.out.println(deck.size()+". "+faceName+" of "+suit+" value:"+values.get(i)); + i++; } -// for (int i = 0; i < deck.size();i++){ -// deck.set(i, ); -// } } } } From 3f5b9de5dfa6c2899cbc440a90383ca04353d77b Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 16 Jul 2022 16:35:07 -0400 Subject: [PATCH 29/31] some art --- .../games/chuckaluck/ChuckALuckGame.java | 54 ++++++++++++++++--- .../games/chuckaluck/ChuckALuckPlayer.java | 6 --- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java index 10ff6be5..57710913 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java @@ -3,6 +3,8 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.casino.games.Dice; +import com.github.zipcodewilmington.casino.games.Player; +import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; public class ChuckALuckGame implements GameInterface { @@ -11,22 +13,55 @@ public class ChuckALuckGame implements GameInterface { private int d1Value; private int d2Value; private int d3Value; + private int bet; Dice d6 = new Dice(1); - String s = ("Betting Options \n\n" - + "Type of Bet: Condition: Odds:\n" - + "1. High Total of 3 dice > 10 1:1\n" - + "2. Low Total of 3 dice < 11 1:1\n" - + "3. Field Total of 3 dice < 8 or total is > 12 1:1\n" - + "4. Triples All 3 dice show same number 30:1"); + public void setBet () { + this.bet = console.getIntegerInput("Enter your bet: "); + } + + public String welcome() { + return + "\n\n\n"+ + "██████ ██ ██ ██ ██ ██████ ██ ██ █████ ██ ██ ██ ██████ ██ ██ ██\n" + + "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n" + + "██ ███████ ██ ██ ██ █████ ███████ ██ ██ ██ ██ █████ ██\n" + + "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ \n" + + "██████ ██ ██ ██████ ██████ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██"; + + } + + public String welcomeDice1() { + return + " ____\n" + + " /\\' .\\ _____\n" + + "/: \\___\\ / . /\\\n" + + "\\' / . / /____/..\\\n" + + " \\/___/ \\' '\\ /\n" + + " \\'__'\\/"; + } + + public String welcomeDice2() { + return + "\t ____\n" + + "\t /\\': \\\n" + + "\t/ \\___\\\n" + + "\t\\' / : /\n" + + "\t \\/___/\n"; + } public void printRules() { - System.out.println(s); + System.out.println("\nTry your luck against the roll of the dice!"); } public Integer askBetType() { - betType = console.getIntegerInput("\nPlace a bet: \n1. High\n2. Low\n3. Field\n4. Triples"); + betType =console.getIntegerInput("\nWhat do you want to bet on? \n\n" + + "Types of bets:\n\n" + + "1. High -- Total of 3 dice > 10\n" + + "2. Low -- Total of 3 dice < 11\n" + + "3. Field -- Total of 3 dice < 8 OR > 12\n" + + "4. Triples -- Feeling lucky? Win big if all three dice show the same number!"); return betType; } @@ -83,7 +118,10 @@ public void printWinOrLose() { public static void playChuckALuckGame() { ChuckALuckGame game = new ChuckALuckGame(); + System.out.println(game.welcome()); game.printRules(); + System.out.println(game.welcomeDice1()); + System.out.println(game.welcomeDice2()); while(true) { game.askBetType(); game.tossDice1(); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java index a98d5e78..062f635e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayer.java @@ -10,13 +10,7 @@ public class ChuckALuckPlayer extends Player implements PlayerInterface { Player player; CasinoAccount casinoAccount; - public ChuckALuckPlayer(Player player, CasinoAccount casinoAccount){ - this.player = player; - this.casinoAccount = casinoAccount; - } - public ChuckALuckPlayer(){ - } public Player getPlayer(){ From 78da79c977a989b9c49797cb287c4ddd1ccd80d1 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 16 Jul 2022 18:42:41 -0400 Subject: [PATCH 30/31] chuck a luck game almost done --- .../games/chuckaluck/ChuckALuckGame.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java index 57710913..11422aea 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java @@ -8,27 +8,33 @@ import com.github.zipcodewilmington.utils.IOConsole; public class ChuckALuckGame implements GameInterface { + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private static final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); private Integer betType = 0; private IOConsole console = new IOConsole(); private int d1Value; private int d2Value; private int d3Value; private int bet; + private int winnings; Dice d6 = new Dice(1); public void setBet () { - this.bet = console.getIntegerInput("Enter your bet: "); + this.bet = Yellow.getIntegerInput("ENTER YOUR WAGER: "); } - public String welcome() { - return - "\n\n\n"+ + public void welcome() { + Blue.println("\n\n\n"+ "██████ ██ ██ ██ ██ ██████ ██ ██ █████ ██ ██ ██ ██████ ██ ██ ██\n" + "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n" + "██ ███████ ██ ██ ██ █████ ███████ ██ ██ ██ ██ █████ ██\n" + "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ \n" + - "██████ ██ ██ ██████ ██████ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██"; + "██████ ██ ██ ██████ ██████ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██"); } @@ -52,16 +58,19 @@ public String welcomeDice2() { } public void printRules() { - System.out.println("\nTry your luck against the roll of the dice!"); + System.out.println("\nTRY YOUR LUCK AGAINST THE ROLLS OF THE DICE!"); } public Integer askBetType() { - betType =console.getIntegerInput("\nWhat do you want to bet on? \n\n" + - "Types of bets:\n\n" + - "1. High -- Total of 3 dice > 10\n" + - "2. Low -- Total of 3 dice < 11\n" + - "3. Field -- Total of 3 dice < 8 OR > 12\n" + - "4. Triples -- Feeling lucky? Win big if all three dice show the same number!"); + betType =Yellow.getIntegerInput("\nWHAT DO YOU WANT TO BET ON? \n\n" + + "1. HIGH\n" + + // -- TOTAL OF 3 DICE > 10 + "2. LOW\n" + + // -- TOTAL OF 3 DICE < 11 + "3. FIELD\n" + + // -- Total of 3 dice < 8 OR > 12 + "4. TRIPLES"); + // -- FEELING LUCKY?? WIN BIG IF ALL 3 DICE SHOW THE SAME NUMBER! return betType; } @@ -79,7 +88,7 @@ public Integer tossDice3() { } public void showRolls() { - System.out.println("\nDice: " + d1Value + " " + d2Value + " " + d3Value); + System.out.println("\nROLLS: " + d1Value + " " + d2Value + " " + d3Value); } public Integer sumDice() { return d1Value + d2Value + d3Value; @@ -96,7 +105,7 @@ public Integer sumDice() { // return sumDice() < 11; // } - public boolean win() { + public boolean winYN() { Integer sum = sumDice(); if (betType == 1 && sum > 10) { return true; @@ -111,25 +120,40 @@ public boolean win() { } public void printWinOrLose() { - if (win()) { - System.out.println("You Win!"); - } else System.out.println("You lose."); + if (winYN()) { + Green.println("*********************"); + Green.println("YOU WIN!!"); + Green.println("*********************\n"); + } else { + Red.println("*********************"); + Red.println("OH NO! YOU LOST."); + Red.println("*********************\n"); + } } public static void playChuckALuckGame() { ChuckALuckGame game = new ChuckALuckGame(); - System.out.println(game.welcome()); + game.welcome(); game.printRules(); System.out.println(game.welcomeDice1()); System.out.println(game.welcomeDice2()); - while(true) { + Boolean quit = false; + game.setBet(); + while(!quit) { game.askBetType(); game.tossDice1(); game.tossDice2(); game.tossDice3(); game.showRolls(); game.printWinOrLose(); - System.out.println(game.sumDice()); + System.out.println("Sum: " + game.sumDice()); + Integer input = Cyan.getIntegerInput("PLAY AGAIN?\n\n" + + "1.YES 2.NO 3.CHANGE BET"); + if (input == 2) { + quit = true; + } else if (input == 3) { + game.setBet(); + } } } From e06fe002b570f971574bf4d6510504b014e62c49 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 18 Jul 2022 19:39:47 -0400 Subject: [PATCH 31/31] chuckaluck latest --- .../games/chuckaluck/ChuckALuckGame.java | 73 +++++++++++-------- .../games/chuckaluck/ChuckALuckGameTest.java | 4 + .../chuckaluck/ChuckALuckPlayerTest.java | 4 + 3 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGameTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayerTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java index 11422aea..009c5988 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGame.java @@ -12,7 +12,7 @@ public class ChuckALuckGame implements GameInterface { private final IOConsole Green = new IOConsole(AnsiColor.GREEN); private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); - private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private static final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); private static final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); private Integer betType = 0; private IOConsole console = new IOConsole(); @@ -21,13 +21,53 @@ public class ChuckALuckGame implements GameInterface { private int d3Value; private int bet; private int winnings; - + private int balance = 500; Dice d6 = new Dice(1); + + public static void playChuckALuckGame() { + ChuckALuckGame game = new ChuckALuckGame(); + game.welcome(); + game.printRules(); + System.out.println(game.welcomeDice1()); + System.out.println(game.welcomeDice2()); + Boolean quit = false; + System.out.print("YOUR CURRENT BALANCE IS: " + game.balance + "\n"); + game.setBet(); + while(!quit) { + game.askBetType(); + game.tossDice1(); + game.tossDice2(); + game.tossDice3(); + game.showRolls(); + game.printWinOrLose(); + System.out.println("SUM: " + game.sumDice() + "\n"); + game.winYN(); + game.adjustBalance(); + System.out.println("YOUR NEW BALANCE IS: " + game.balance + "\n\n"); + Integer input = Purple.getIntegerInput("PLAY AGAIN?\n\n" + + "1.YES 2.NO 3.CHANGE BET"); + if (input == 2) { + quit = true; + } else if (input == 3) { + game.setBet(); + } + } + } public void setBet () { this.bet = Yellow.getIntegerInput("ENTER YOUR WAGER: "); } + + public Integer adjustBalance() { + if (winYN()) { + balance += bet*1.5; + } else if(winYN() && betType == 3) { + balance += bet*500; + } else balance -= bet; + return balance; + } + public void welcome() { Blue.println("\n\n\n"+ "██████ ██ ██ ██ ██ ██████ ██ ██ █████ ██ ██ ██ ██████ ██ ██ ██\n" + @@ -37,7 +77,6 @@ public void welcome() { "██████ ██ ██ ██████ ██████ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██"); } - public String welcomeDice1() { return " ____\n" + @@ -47,7 +86,6 @@ public String welcomeDice1() { " \\/___/ \\' '\\ /\n" + " \\'__'\\/"; } - public String welcomeDice2() { return "\t ____\n" + @@ -56,11 +94,9 @@ public String welcomeDice2() { "\t\\' / : /\n" + "\t \\/___/\n"; } - public void printRules() { System.out.println("\nTRY YOUR LUCK AGAINST THE ROLLS OF THE DICE!"); } - public Integer askBetType() { betType =Yellow.getIntegerInput("\nWHAT DO YOU WANT TO BET ON? \n\n" + "1. HIGH\n" + @@ -131,31 +167,6 @@ public void printWinOrLose() { } } - public static void playChuckALuckGame() { - ChuckALuckGame game = new ChuckALuckGame(); - game.welcome(); - game.printRules(); - System.out.println(game.welcomeDice1()); - System.out.println(game.welcomeDice2()); - Boolean quit = false; - game.setBet(); - while(!quit) { - game.askBetType(); - game.tossDice1(); - game.tossDice2(); - game.tossDice3(); - game.showRolls(); - game.printWinOrLose(); - System.out.println("Sum: " + game.sumDice()); - Integer input = Cyan.getIntegerInput("PLAY AGAIN?\n\n" + - "1.YES 2.NO 3.CHANGE BET"); - if (input == 2) { - quit = true; - } else if (input == 3) { - game.setBet(); - } - } - } @Override public void add(PlayerInterface player) { diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGameTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGameTest.java new file mode 100644 index 00000000..80f13aff --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckGameTest.java @@ -0,0 +1,4 @@ +import static org.junit.jupiter.api.Assertions.*; +class ChuckALuckGameTest { + +} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayerTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayerTest.java new file mode 100644 index 00000000..90e48d5e --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/chuckaluck/ChuckALuckPlayerTest.java @@ -0,0 +1,4 @@ +import static org.junit.Assert.*; +public class ChuckALuckPlayerTest { + +} \ No newline at end of file