From 1d0e441582a3fbad5364ec7df1b4703e16c97785 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sat, 18 Nov 2017 16:22:44 -0500 Subject: [PATCH 01/30] stubs from UML --- 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/io/zipcoder/casino/Bank.java | 11 +++++++++ .../java/io/zipcoder/casino/BlackJack.java | 22 ++++++++++++++++++ .../io/zipcoder/casino/BlackJackPlayer.java | 10 ++++++++ src/main/java/io/zipcoder/casino/Card.java | 6 +++++ src/main/java/io/zipcoder/casino/Casino.java | 1 + src/main/java/io/zipcoder/casino/Craps.java | 15 ++++++++++++ .../java/io/zipcoder/casino/CrapsPlayer.java | 8 +++++++ src/main/java/io/zipcoder/casino/Deck.java | 8 +++++++ src/main/java/io/zipcoder/casino/Dice.java | 5 ++++ src/main/java/io/zipcoder/casino/Game.java | 17 ++++++++++++++ src/main/java/io/zipcoder/casino/GoFish.java | 12 ++++++++++ .../java/io/zipcoder/casino/GoFishPlayer.java | 5 ++++ src/main/java/io/zipcoder/casino/Hand.java | 5 ++++ .../java/io/zipcoder/casino/PlayForMoney.java | 7 ++++++ src/main/java/io/zipcoder/casino/Player.java | 18 ++++++++++++++ src/main/java/io/zipcoder/casino/Rank.java | 17 ++++++++++++++ src/main/java/io/zipcoder/casino/Suit.java | 4 ++++ src/test/.DS_Store | Bin 0 -> 6148 bytes 21 files changed, 171 insertions(+) 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/io/zipcoder/casino/Bank.java create mode 100644 src/main/java/io/zipcoder/casino/BlackJack.java create mode 100644 src/main/java/io/zipcoder/casino/BlackJackPlayer.java create mode 100644 src/main/java/io/zipcoder/casino/Card.java create mode 100644 src/main/java/io/zipcoder/casino/Craps.java create mode 100644 src/main/java/io/zipcoder/casino/CrapsPlayer.java create mode 100644 src/main/java/io/zipcoder/casino/Deck.java create mode 100644 src/main/java/io/zipcoder/casino/Dice.java create mode 100644 src/main/java/io/zipcoder/casino/Game.java create mode 100644 src/main/java/io/zipcoder/casino/GoFish.java create mode 100644 src/main/java/io/zipcoder/casino/GoFishPlayer.java create mode 100644 src/main/java/io/zipcoder/casino/Hand.java create mode 100644 src/main/java/io/zipcoder/casino/PlayForMoney.java create mode 100644 src/main/java/io/zipcoder/casino/Player.java create mode 100644 src/main/java/io/zipcoder/casino/Rank.java create mode 100644 src/main/java/io/zipcoder/casino/Suit.java create mode 100644 src/test/.DS_Store diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9604c915d7b8d2e3c47081ab1bfbca343bb98a7e GIT binary patch literal 6148 zcmeHKJ5EC}5S)cqM50Ma=__ypD+(vb1^9#lDUc$ee--EAXqo*KiJqR6h6ZM(_1Nnj zTb|3 z&ZCzgHV+Vc;h4w>&5}w?s#S|&NoTxOUN0OIlMaiUc~0GI)uCA2&UlM-SWna_1*E{G z0=Kzbdi{T-&-DM7B(0=?6!=pL*s$KLSA0^{*2&|%);9VR-E)5EZkz{&LzH7;lw&Tu f9N$M$<~5&lzZZ^)L1#SZMEwl7E;1?b+X|cjR1+BX literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b7618decc8fbb22e6bd7aff7d056a6f0b9fdfac5 GIT binary patch literal 6148 zcmeH~Jr2S!425lAKw|00n1usyg9yP1xB!AKNJt$JdydZY4+Di6Rp?o=zu1k{_6lA49C} z?O@4$HQ9pEE}FxK=AG517??)8Xh8zg>R_M(RA8jQJo3)Y{{#Hn{6A`8N(HFEpDCb= z{c*p;OXb=6@p@K2W!2UV4*GV4x1Rtcb`-DSZn$1-0oG&-q5|WOfXl!@1%9f)6A?5J AH2?qr literal 0 HcmV?d00001 diff --git a/src/main/java/io/zipcoder/casino/Bank.java b/src/main/java/io/zipcoder/casino/Bank.java new file mode 100644 index 00000000..2132f635 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Bank.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino; + +public class Bank { + private Double balance; + + public void withdraw() { + } + + public void deposit() { + } +} diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java new file mode 100644 index 00000000..363f17b7 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -0,0 +1,22 @@ +package io.zipcoder.casino; + +public class BlackJack extends Game implements PlayForMoney { + private Bank house; + private Deck gameDeck; + + public void scoreHand() { + } + + public void addPlayers() { + } + + public void bet() { + + } + + public void resolveBets() { + } + + public void dealNewHand() { + } +} diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java new file mode 100644 index 00000000..954bb47d --- /dev/null +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -0,0 +1,10 @@ +package io.zipcoder.casino; + +public class BlackJackPlayer extends Player { + public void hit() { + } + + public void stay() { + } + +} diff --git a/src/main/java/io/zipcoder/casino/Card.java b/src/main/java/io/zipcoder/casino/Card.java new file mode 100644 index 00000000..32fe300f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Card.java @@ -0,0 +1,6 @@ +package io.zipcoder.casino; + +public class Card { + private Suit suit; + private Rank rank; +} diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 74dfdd8c..38cb97e0 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -2,4 +2,5 @@ public class Casino { + private Game[] games; } diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java new file mode 100644 index 00000000..85a4f461 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -0,0 +1,15 @@ +package io.zipcoder.casino; + +public class Craps extends Game implements PlayForMoney { + private Bank house; + + + public void bet() { + + } + + public void resolveBets() { + + } + +} diff --git a/src/main/java/io/zipcoder/casino/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/CrapsPlayer.java new file mode 100644 index 00000000..a500b349 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CrapsPlayer.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino; + +public class CrapsPlayer extends Player { + private Dice[] dice; + + public void rollDice() { + } +} diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java new file mode 100644 index 00000000..a1da1628 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino; + +public class Deck { + private Card cards; + + public void shuffle() { + } +} diff --git a/src/main/java/io/zipcoder/casino/Dice.java b/src/main/java/io/zipcoder/casino/Dice.java new file mode 100644 index 00000000..36e09020 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Dice.java @@ -0,0 +1,5 @@ +package io.zipcoder.casino; + +public class Dice { + private int value; +} diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java new file mode 100644 index 00000000..5effbf76 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -0,0 +1,17 @@ +package io.zipcoder.casino; + +public class Game { + private int round; + private Player currentPlayer; + private Player[] players; + + public void startRound() { + } + + public Player setActivePlayer() { + return null; + } + + public void endRound() { + } +} diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java new file mode 100644 index 00000000..2b12b038 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -0,0 +1,12 @@ +package io.zipcoder.casino; + +public class GoFish extends Game { + private Integer[] score; + private Deck gameDeck; + + public void requestCard() { + } + + public void giveCardToPlayer() { + } +} diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java new file mode 100644 index 00000000..6d508fd3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -0,0 +1,5 @@ +package io.zipcoder.casino; + +public class GoFishPlayer extends Player { + private int score; +} diff --git a/src/main/java/io/zipcoder/casino/Hand.java b/src/main/java/io/zipcoder/casino/Hand.java new file mode 100644 index 00000000..cb06c8f3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Hand.java @@ -0,0 +1,5 @@ +package io.zipcoder.casino; + +public class Hand { + private Card[] cards; +} diff --git a/src/main/java/io/zipcoder/casino/PlayForMoney.java b/src/main/java/io/zipcoder/casino/PlayForMoney.java new file mode 100644 index 00000000..cfa71eae --- /dev/null +++ b/src/main/java/io/zipcoder/casino/PlayForMoney.java @@ -0,0 +1,7 @@ +package io.zipcoder.casino; + +public interface PlayForMoney { + void bet(); + + void resolveBets(); +} diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java new file mode 100644 index 00000000..1e234629 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -0,0 +1,18 @@ +package io.zipcoder.casino; + +public class Player { + private double bank; + private Hand playerHand; + + public Card drawCard() { + return null; + } + + public void checkHand() { + } + + public boolean isWinner() { + return false; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Rank.java b/src/main/java/io/zipcoder/casino/Rank.java new file mode 100644 index 00000000..2911a120 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Rank.java @@ -0,0 +1,17 @@ +package io.zipcoder.casino; + +public enum Rank {ACE(11), TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10); + + private final int value; + + + Rank(int val) { + this.value = val; + } + + + public int getValue() { + return value; + } +} + diff --git a/src/main/java/io/zipcoder/casino/Suit.java b/src/main/java/io/zipcoder/casino/Suit.java new file mode 100644 index 00000000..5962ae17 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Suit.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public enum Suit {SPADES,CLUBS,HEARTS,DIAMONDS; +} diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 From 429d13c41619a964cf8f0f3c3b10083f97b0ca1d Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sat, 18 Nov 2017 16:23:36 -0500 Subject: [PATCH 02/30] stubs from UML and UML --- src/main/java/io/zipcoder/casino/Casino.uml | 158 ++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/main/java/io/zipcoder/casino/Casino.uml diff --git a/src/main/java/io/zipcoder/casino/Casino.uml b/src/main/java/io/zipcoder/casino/Casino.uml new file mode 100644 index 00000000..034d423a --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Casino.uml @@ -0,0 +1,158 @@ + + + JAVA + io.zipcoder.casino.Casino + + io.zipcoder.casino.Casino + io.zipcoder.casino.Game + io.zipcoder.casino.Hand + io.zipcoder.casino.Card + io.zipcoder.casino.PlayForMoney + io.zipcoder.casino.CrapsPlayer + io.zipcoder.casino.Deck + io.zipcoder.casino.Dice + io.zipcoder.casino.BlackJackPlayer + io.zipcoder.casino.Suit + io.zipcoder.casino.Craps + io.zipcoder.casino.Player + io.zipcoder.casino.BlackJack + io.zipcoder.casino.Rank + io.zipcoder.casino.GoFish + io.zipcoder.casino.GoFishPlayer + io.zipcoder.casino.Bank + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fields + Methods + + All + private + + From 54049520782103a97b21f9e9fe7b7abfc94f4a37 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 19 Nov 2017 09:24:27 -0500 Subject: [PATCH 03/30] pass line logic working --- src/main/java/io/zipcoder/casino/Bank.java | 18 +++- src/main/java/io/zipcoder/casino/BetType.java | 4 + .../java/io/zipcoder/casino/BlackJack.java | 52 +++++----- .../io/zipcoder/casino/BlackJackPlayer.java | 2 + src/main/java/io/zipcoder/casino/Console.java | 96 +++++++++++++++++++ src/main/java/io/zipcoder/casino/Craps.java | 47 ++++++++- .../java/io/zipcoder/casino/CrapsPlayer.java | 27 +++++- src/main/java/io/zipcoder/casino/Deck.java | 21 ++-- src/main/java/io/zipcoder/casino/Dice.java | 8 ++ src/main/java/io/zipcoder/casino/Game.java | 13 ++- src/main/java/io/zipcoder/casino/GoFish.java | 24 ++--- .../java/io/zipcoder/casino/GoFishPlayer.java | 1 + src/main/java/io/zipcoder/casino/Main.java | 10 ++ .../java/io/zipcoder/casino/PlayForMoney.java | 2 +- src/main/java/io/zipcoder/casino/Player.java | 10 +- .../io/zipcoder/casino/CrapsPlayerTest.java | 22 +++++ .../java/io/zipcoder/casino/CrapsTest.java | 60 ++++++++++++ 17 files changed, 363 insertions(+), 54 deletions(-) create mode 100644 src/main/java/io/zipcoder/casino/BetType.java create mode 100644 src/main/java/io/zipcoder/casino/Console.java create mode 100644 src/main/java/io/zipcoder/casino/Main.java create mode 100644 src/test/java/io/zipcoder/casino/CrapsPlayerTest.java create mode 100644 src/test/java/io/zipcoder/casino/CrapsTest.java diff --git a/src/main/java/io/zipcoder/casino/Bank.java b/src/main/java/io/zipcoder/casino/Bank.java index 2132f635..9a07f94b 100644 --- a/src/main/java/io/zipcoder/casino/Bank.java +++ b/src/main/java/io/zipcoder/casino/Bank.java @@ -3,9 +3,23 @@ public class Bank { private Double balance; - public void withdraw() { + public double withdraw(double amount) { + if(sufficientFunds(amount)) { + balance -= amount; + return amount; + + }return 0; + } + + public void deposit(double amount) { + balance += amount; + } + + public Double getBalance() { + return balance; } - public void deposit() { + public boolean sufficientFunds(double amount){ + return amount <= this.balance; } } diff --git a/src/main/java/io/zipcoder/casino/BetType.java b/src/main/java/io/zipcoder/casino/BetType.java new file mode 100644 index 00000000..4fc88d5e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/BetType.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public enum BetType {PASS, DONTPASS, COME, DONTCOME, ODDS, PLACEWIN, PLACELOSE,BUY +} diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index 363f17b7..e63ede9d 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -1,22 +1,30 @@ -package io.zipcoder.casino; - -public class BlackJack extends Game implements PlayForMoney { - private Bank house; - private Deck gameDeck; - - public void scoreHand() { - } - - public void addPlayers() { - } - - public void bet() { - - } - - public void resolveBets() { - } - - public void dealNewHand() { - } -} +//package io.zipcoder.casino; +// +//public class BlackJack extends Game implements PlayForMoney { +// private Bank house; +// private Deck gameDeck; +// +// public void scoreHand() { +// } +// +// public void addPlayers() { +// } +// +// public void bet() { +// +// } +// +// public void bet(double betAmount) { +// +// } +// +// public void bet(BetType betType, double betAmount) { +// +// } +// +// public void resolveBets() { +// } +// +// public void dealNewHand() { +// } +//} diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index 954bb47d..53435f8b 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -1,6 +1,8 @@ package io.zipcoder.casino; public class BlackJackPlayer extends Player { + private Card[] hand; + public void hit() { } diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java new file mode 100644 index 00000000..575741b2 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -0,0 +1,96 @@ +package io.zipcoder.casino; + +import java.util.Scanner; +import java.util.WeakHashMap; + +public class Console { + + public void casinoMenu() { + + } + + public void playCraps() { + + Craps gameOn = new Craps(); + + System.out.println("New shooter."); + CrapsPlayer shooter = new CrapsPlayer(); + gameOn.addPlayer(shooter); + + System.out.println("Place your bets. pass line only for the moment"); + System.out.println("How much?"); + + double passLineBet = getDoubleInput(); + + System.out.println("Ok betting $" + passLineBet + "." ); + System.out.println("S to shoot"); + String play = getAnyKey(); + + if (play.equals("y")){ + Integer roll = shooter.roll2Dice(); + shooter.printRoll(); + gameOn.setComeOut(true); + if((!(gameOn.passBetWins(roll)) && !(gameOn.passBetLoses(roll)))){ + do{ + System.out.println("Roll again!"); + // gameOn.setComeOut(false); + roll = shooter.roll2Dice(); + shooter.printRoll(); + }while(!(gameOn.passBetWins(roll)) && !(gameOn.passBetLoses(roll))); + } + if(gameOn.passBetWins(roll)){ + System.out.println("You win! Added " + passLineBet + " to your bank."); + + }else if(gameOn.passBetLoses(roll)) { + System.out.println("You you lose."); + } + + + + + + } + + + // boolean won = isWinner(bet, roll): + // boolean rollAgain = isEndRound(); + + } + + private boolean isWinner() { + return true; + } + + private BetType getBet() { + return null; + } + + public void playBlackJack() { + } + + public void playGoFish() { + } + + public String getInput(){ + Scanner scan = new Scanner(System.in); + return "y"; + } + + public String getAnyKey(){ + Scanner scan = new Scanner(System.in); + scan.hasNext(); + return "y"; + } + + public double getDoubleInput() { + Scanner scan = new Scanner(System.in); + double dblInput; + String stringInput = scan.nextLine(); + + dblInput = Double.valueOf(stringInput); + + return dblInput; + } +} + + diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index 85a4f461..1958673e 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -2,9 +2,47 @@ public class Craps extends Game implements PlayForMoney { private Bank house; + private BetType betType; + private double betAmount; + private boolean isComeOut; + private Integer point; + private Integer comePoint; + public void startRound(double betAmount){ + isComeOut = true; - public void bet() { + + } + + public boolean passBetWins(int roll) { + if (isComeOut && (roll == 7 || roll == 11)) {return true;} + else if (!isComeOut && (roll == point)) {return true;} + return false; + } + + public boolean passBetLoses(int roll){ + if (isComeOut && (roll == 2 || roll == 3 || roll == 12)) {return true;} + else if (!isComeOut && (roll == 7)) {return true;} + return false; + } + + + public boolean dontPassWins(int roll){ + if (isComeOut && (roll == 2 || roll == 3)) {return true;} + else if (!isComeOut && (roll == 7)) {return true;} + return false; + //refactor to add push condition for 12 + } + + public void setBetType(BetType betType) { + this.betType = betType; + } + + public void placeBet(double betAmount) { + this.betAmount = betAmount; + } + + public void rollAgain(){ } @@ -12,4 +50,11 @@ public void resolveBets() { } + public void setComeOut(boolean comeOut) { + isComeOut = comeOut; + } + + public void setPoint(Integer point) { + this.point = point; + } } diff --git a/src/main/java/io/zipcoder/casino/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/CrapsPlayer.java index a500b349..8a731667 100644 --- a/src/main/java/io/zipcoder/casino/CrapsPlayer.java +++ b/src/main/java/io/zipcoder/casino/CrapsPlayer.java @@ -1,8 +1,31 @@ package io.zipcoder.casino; public class CrapsPlayer extends Player { - private Dice[] dice; + private Bank wallet; + private Integer[] currentRoll = new Integer[2]; - public void rollDice() { + public Integer roll2Dice() { + + int rollOne = (int) (Math.random()*6)+1; + int rollTwo = (int) (Math.random()*6)+1; + + currentRoll[0] = rollOne; + currentRoll[1] = rollTwo; + + return rollOne+rollTwo; + } + + public void printRoll(){ + System.out.println("["+ currentRoll[0]+"," +currentRoll[1]+"]"); + } + + + + public Bank getWallet() { + return wallet; + } + + public void setWallet(Bank wallet) { + this.wallet = wallet; } } diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java index a1da1628..b56aca4d 100644 --- a/src/main/java/io/zipcoder/casino/Deck.java +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -1,8 +1,13 @@ -package io.zipcoder.casino; - -public class Deck { - private Card cards; - - public void shuffle() { - } -} +//package io.zipcoder.casino; +// +//public class Deck { +// private Card cards; +// +// public void shuffle() { +// } +// +// public Card nextAvailableCard(){ +// Card card = new Card; +// return card; +// } +//} diff --git a/src/main/java/io/zipcoder/casino/Dice.java b/src/main/java/io/zipcoder/casino/Dice.java index 36e09020..5d204882 100644 --- a/src/main/java/io/zipcoder/casino/Dice.java +++ b/src/main/java/io/zipcoder/casino/Dice.java @@ -2,4 +2,12 @@ public class Dice { private int value; + + public void setValue(int value) { + this.value = value; + } + + public int getValue() { + return value; + } } diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index 5effbf76..d843497c 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -1,17 +1,20 @@ package io.zipcoder.casino; +import java.util.ArrayList; + public class Game { private int round; - private Player currentPlayer; - private Player[] players; + private ArrayList players = new ArrayList(); public void startRound() { + } - public Player setActivePlayer() { - return null; + public void addPlayer(Player player){ + players.add(player); } - public void endRound() { + public boolean isEndRound() { + return false; } } diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 2b12b038..69be602a 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -1,12 +1,12 @@ -package io.zipcoder.casino; - -public class GoFish extends Game { - private Integer[] score; - private Deck gameDeck; - - public void requestCard() { - } - - public void giveCardToPlayer() { - } -} +//package io.zipcoder.casino; +// +//public class GoFish extends Game { +// private Integer[] score; +// private Deck gameDeck; +// +// public void requestCard() { +// } +// +// public void giveCardToPlayer() { +// } +//} diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index 6d508fd3..a59a2a35 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -2,4 +2,5 @@ public class GoFishPlayer extends Player { private int score; + private Card[] hand; } diff --git a/src/main/java/io/zipcoder/casino/Main.java b/src/main/java/io/zipcoder/casino/Main.java new file mode 100644 index 00000000..50221ebb --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Main.java @@ -0,0 +1,10 @@ +package io.zipcoder.casino; + +public class Main { + + public static void main(String[] args) { + + Console console = new Console(); + console.playCraps(); + } +} diff --git a/src/main/java/io/zipcoder/casino/PlayForMoney.java b/src/main/java/io/zipcoder/casino/PlayForMoney.java index cfa71eae..a49fe47e 100644 --- a/src/main/java/io/zipcoder/casino/PlayForMoney.java +++ b/src/main/java/io/zipcoder/casino/PlayForMoney.java @@ -1,7 +1,7 @@ package io.zipcoder.casino; public interface PlayForMoney { - void bet(); + void placeBet(double betAmount ); void resolveBets(); } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index 1e234629..60446d62 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -2,7 +2,7 @@ public class Player { private double bank; - private Hand playerHand; + private String name; public Card drawCard() { return null; @@ -11,6 +11,14 @@ public Card drawCard() { public void checkHand() { } + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + public boolean isWinner() { return false; } diff --git a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java new file mode 100644 index 00000000..08678047 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java @@ -0,0 +1,22 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CrapsPlayerTest { + + @Test + public void roll2DiceTest(){ + + CrapsPlayer shooter = new CrapsPlayer(); + Dice dice = new Dice(); + + Integer actual = shooter.roll2Dice(); + + Assert.assertTrue(actual <13 && actual > 0); + + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java new file mode 100644 index 00000000..609eb9af --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -0,0 +1,60 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CrapsTest { + @Test + public void startRoundB() throws Exception { + } + + @Test + public void passBetWinsTest() throws Exception { + Craps game = new Craps(); + game.setComeOut(true); + Assert.assertTrue(game.passBetWins(7)); + Assert.assertTrue(game.passBetWins(11)); + + game.setPoint(9); + game.setComeOut(false); + Assert.assertTrue(game.passBetWins(9)); + + + } + + @Test + public void passBetLosesTest() throws Exception { + Craps game = new Craps(); + game.setComeOut(true); + Assert.assertTrue(game.passBetLoses(2)); + Assert.assertTrue(game.passBetLoses(3)); + Assert.assertTrue(game.passBetLoses(12)); + + game.setComeOut(false); + game.setPoint(4); + Assert.assertTrue(game.passBetLoses(7)); + } + + @Test + public void dontPassWins() throws Exception { + } + + @Test + public void setBetType() throws Exception { + } + + @Test + public void placeBet() throws Exception { + } + + @Test + public void rollAgain() throws Exception { + } + + @Test + public void resolveBets() throws Exception { + } + +} \ No newline at end of file From 03ca592f0005b9b9f283374320b36b5e06ced650 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 19 Nov 2017 13:57:00 -0500 Subject: [PATCH 04/30] working on gofish player --- src/main/java/io/zipcoder/casino/Card.java | 13 ++++ src/main/java/io/zipcoder/casino/Console.java | 20 ++++-- src/main/java/io/zipcoder/casino/Craps.java | 27 ++++++-- src/main/java/io/zipcoder/casino/Deck.java | 58 ++++++++++++---- src/main/java/io/zipcoder/casino/Dice.java | 13 ---- src/main/java/io/zipcoder/casino/GoFish.java | 33 ++++++---- .../java/io/zipcoder/casino/GoFishPlayer.java | 47 ++++++++++++- src/main/java/io/zipcoder/casino/Player.java | 7 -- src/main/java/io/zipcoder/casino/Suit.java | 2 +- .../io/zipcoder/casino/CrapsPlayerTest.java | 6 +- .../java/io/zipcoder/casino/CrapsTest.java | 13 ++-- .../java/io/zipcoder/casino/DeckTest.java | 48 ++++++++++++++ .../io/zipcoder/casino/GoFishPlayerTest.java | 66 +++++++++++++++++++ 13 files changed, 285 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/io/zipcoder/casino/Dice.java create mode 100644 src/test/java/io/zipcoder/casino/DeckTest.java create mode 100644 src/test/java/io/zipcoder/casino/GoFishPlayerTest.java diff --git a/src/main/java/io/zipcoder/casino/Card.java b/src/main/java/io/zipcoder/casino/Card.java index 32fe300f..c3ad2c59 100644 --- a/src/main/java/io/zipcoder/casino/Card.java +++ b/src/main/java/io/zipcoder/casino/Card.java @@ -3,4 +3,17 @@ public class Card { private Suit suit; private Rank rank; + + public Card(Rank rank,Suit suit){ + this.suit = suit; + this.rank = rank; + } + + public Rank getRank() { + return rank; + } + + public Suit getSuit() { + return suit; + } } diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 575741b2..53d985de 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -30,21 +30,29 @@ public void playCraps() { Integer roll = shooter.roll2Dice(); shooter.printRoll(); gameOn.setComeOut(true); - if((!(gameOn.passBetWins(roll)) && !(gameOn.passBetLoses(roll)))){ + if(!gameOn.passBetWinsComeOut(roll) && !gameOn.passBetLosesComeOut(roll)){ do{ System.out.println("Roll again!"); - // gameOn.setComeOut(false); + if(gameOn.getIsComeOut()){ + gameOn.setPoint(roll); + } roll = shooter.roll2Dice(); shooter.printRoll(); - }while(!(gameOn.passBetWins(roll)) && !(gameOn.passBetLoses(roll))); + gameOn.setComeOut(false); + }while(roll != 7 && roll !=gameOn.getPoint()); } - if(gameOn.passBetWins(roll)){ + else if(gameOn.passBetWinsComeOut(roll)){ System.out.println("You win! Added " + passLineBet + " to your bank."); - }else if(gameOn.passBetLoses(roll)) { - System.out.println("You you lose."); + }else if(gameOn.passBetLosesComeOut(roll)) { + System.out.println("You lose."); } + if(gameOn.passBetWins(roll)){ + System.out.println("You win! Added " + passLineBet + " to your bank."); + }else if(gameOn.passBetLoses(roll)){ + System.out.println("You lose."); + } diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index 1958673e..f476c1fe 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -14,19 +14,26 @@ public void startRound(double betAmount){ } + public boolean passBetWinsComeOut(int roll) { + return (roll == 7 || roll == 11); + } + + public boolean passBetLosesComeOut(int roll){ + return (roll == 2 || roll == 3 || roll == 12); + + } + public boolean passBetWins(int roll) { - if (isComeOut && (roll == 7 || roll == 11)) {return true;} - else if (!isComeOut && (roll == point)) {return true;} - return false; + return(roll == this.point); } public boolean passBetLoses(int roll){ - if (isComeOut && (roll == 2 || roll == 3 || roll == 12)) {return true;} - else if (!isComeOut && (roll == 7)) {return true;} - return false; + return (roll == 7); } + + public boolean dontPassWins(int roll){ if (isComeOut && (roll == 2 || roll == 3)) {return true;} else if (!isComeOut && (roll == 7)) {return true;} @@ -54,7 +61,15 @@ public void setComeOut(boolean comeOut) { isComeOut = comeOut; } + public boolean getIsComeOut(){ + return isComeOut; + } + public void setPoint(Integer point) { this.point = point; } + + public int getPoint() { + return point; + } } diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java index b56aca4d..330e3b0e 100644 --- a/src/main/java/io/zipcoder/casino/Deck.java +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -1,13 +1,45 @@ -//package io.zipcoder.casino; -// -//public class Deck { -// private Card cards; -// -// public void shuffle() { -// } -// -// public Card nextAvailableCard(){ -// Card card = new Card; -// return card; -// } -//} +package io.zipcoder.casino; + +import sun.security.jca.GetInstance; + +import java.util.ArrayList; +import java.util.Collections; + +public class Deck { + private ArrayList cards; + + public Deck(){ + + cards = new ArrayList(); + + for (int i = 0; i < 4; i++) { + Suit[] suitArray = new Suit[]{Suit.CLUB, Suit.DIAMOND, Suit.HEART, Suit.SPADE}; + for (int j = 0; j < 13; j++) { + Rank[] rankArray = new Rank[]{Rank.ACE, Rank.TWO, Rank.THREE, Rank.FOUR, Rank.FIVE, Rank.SIX, Rank.SEVEN, Rank.EIGHT, Rank.NINE, Rank.TEN, Rank.JACK, Rank.QUEEN, Rank.KING}; + + Card card = new Card(rankArray[j], suitArray[i]); + + cards.add(card); + } + } + + } + + public ArrayList getCards() { + return cards; + } + + public void shuffle() { + Collections.shuffle(cards); + } + + public Card nextAvailableCard(){ + + return null; + } + + + public Integer getDeckSize() { + return cards.size(); + } +} diff --git a/src/main/java/io/zipcoder/casino/Dice.java b/src/main/java/io/zipcoder/casino/Dice.java deleted file mode 100644 index 5d204882..00000000 --- a/src/main/java/io/zipcoder/casino/Dice.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.zipcoder.casino; - -public class Dice { - private int value; - - public void setValue(int value) { - this.value = value; - } - - public int getValue() { - return value; - } -} diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 69be602a..20dca038 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -1,12 +1,21 @@ -//package io.zipcoder.casino; -// -//public class GoFish extends Game { -// private Integer[] score; -// private Deck gameDeck; -// -// public void requestCard() { -// } -// -// public void giveCardToPlayer() { -// } -//} +package io.zipcoder.casino; + +import java.util.ArrayList; + +public class GoFish extends Game { + private Deck gameDeck; + + public GoFish(){ + this.gameDeck = new Deck(); + gameDeck.shuffle(); + } + + public Deck getGameDeck() { + return gameDeck; + } + + public Player endGameDeclareWinner(){ + return null; + } + +} diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index a59a2a35..dbf8858e 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -1,6 +1,51 @@ package io.zipcoder.casino; +import java.util.ArrayList; + public class GoFishPlayer extends Player { private int score; - private Card[] hand; + private ArrayList hand = new ArrayList(); + + + public Card drawCard(Deck deck) { + Card playerCard = deck.getCards().remove(0); + return playerCard; + } + + public void addCardToHand(Card card){ + hand.add(card); + } + + public ArrayList getHand() { + return hand; + } + + public boolean checkHandForCard(Rank rank){ + for(Card card: hand){ + if(card.getRank() == rank) return true; + }return false; + + } + + public Card giveCard(Rank rank){ + for(Card card: hand){ + if(card.getRank() == rank){ + hand.remove(card); + return card; + } + } + return null; + } + + public boolean checkFourOfAKind(){ + for(Card card: hand){ + + } + } + + public void drawFiveCards(){ + + } + + } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index 60446d62..d2ae7068 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -4,13 +4,6 @@ public class Player { private double bank; private String name; - public Card drawCard() { - return null; - } - - public void checkHand() { - } - public void setName(String name) { this.name = name; } diff --git a/src/main/java/io/zipcoder/casino/Suit.java b/src/main/java/io/zipcoder/casino/Suit.java index 5962ae17..e1134d60 100644 --- a/src/main/java/io/zipcoder/casino/Suit.java +++ b/src/main/java/io/zipcoder/casino/Suit.java @@ -1,4 +1,4 @@ package io.zipcoder.casino; -public enum Suit {SPADES,CLUBS,HEARTS,DIAMONDS; +public enum Suit {SPADE,CLUB,HEART,DIAMOND; } diff --git a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java index 08678047..c3a48105 100644 --- a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java @@ -11,12 +11,14 @@ public class CrapsPlayerTest { public void roll2DiceTest(){ CrapsPlayer shooter = new CrapsPlayer(); - Dice dice = new Dice(); Integer actual = shooter.roll2Dice(); - Assert.assertTrue(actual <13 && actual > 0); + for(int i =0; i < 1000000; i++){ + actual = shooter.roll2Dice(); + Assert.assertTrue(actual <13 && actual > 0); + } } } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index 609eb9af..af823afe 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -14,11 +14,10 @@ public void startRoundB() throws Exception { public void passBetWinsTest() throws Exception { Craps game = new Craps(); game.setComeOut(true); - Assert.assertTrue(game.passBetWins(7)); - Assert.assertTrue(game.passBetWins(11)); + Assert.assertTrue(game.passBetWinsComeOut(7)); + Assert.assertTrue(game.passBetWinsComeOut(11)); - game.setPoint(9); - game.setComeOut(false); + game.setPoint(9);; Assert.assertTrue(game.passBetWins(9)); @@ -28,9 +27,9 @@ public void passBetWinsTest() throws Exception { public void passBetLosesTest() throws Exception { Craps game = new Craps(); game.setComeOut(true); - Assert.assertTrue(game.passBetLoses(2)); - Assert.assertTrue(game.passBetLoses(3)); - Assert.assertTrue(game.passBetLoses(12)); + Assert.assertTrue(game.passBetLosesComeOut(2)); + Assert.assertTrue(game.passBetLosesComeOut(3)); + Assert.assertTrue(game.passBetLosesComeOut(12)); game.setComeOut(false); game.setPoint(4); diff --git a/src/test/java/io/zipcoder/casino/DeckTest.java b/src/test/java/io/zipcoder/casino/DeckTest.java new file mode 100644 index 00000000..82df34a3 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DeckTest.java @@ -0,0 +1,48 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +import static org.junit.Assert.*; + +public class DeckTest { + + @Test + public void constructorTest(){ + Deck deck = new Deck(); + + ArrayList cards = deck.getCards(); + + String expected = "a bunch of cards"; + String actual = "***output***\n"; + + for(Card card: cards){ + actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); + } + + Assert.assertEquals(expected, actual); + } + + @Test + public void shuffleTest() throws Exception { + Deck deck = new Deck(); + deck.shuffle(); + ArrayList cards = deck.getCards(); + + String expected = "a bunch of cards"; + + String actual = "***output***\n"; + + for(Card card: cards){ + actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); + } + + Assert.assertEquals(expected, actual); + + + } + + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java new file mode 100644 index 00000000..8d90774e --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java @@ -0,0 +1,66 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.theories.suppliers.TestedOn; + +import static org.junit.Assert.*; + +public class GoFishPlayerTest { + @Test + public void checkHandForCard() throws Exception { + GoFish gameOn = new GoFish(); + GoFishPlayer player1 = new GoFishPlayer(); + + String expected = ""; + for(int i=0; i<5;i++){ + Card card = player1.drawCard(gameOn.getGameDeck()); + player1.addCardToHand(card); + expected += card.getRank() + " of " +card.getSuit()+"s\n"; + } + + Rank rank = player1.getHand().get(3).getRank(); + + System.out.println(expected); + Assert.assertTrue(player1.checkHandForCard(rank)); + + } + + @Test + public void giveCard() throws Exception { + GoFish gameOn = new GoFish(); + GoFishPlayer player1 = new GoFishPlayer(); + + String expected = ""; + for(int i=0; i<5;i++){ + Card card = player1.drawCard(gameOn.getGameDeck()); + player1.addCardToHand(card); + expected += card.getRank() + " of " +card.getSuit()+"s\n"; + } + + System.out.println(expected); + + Rank rank = player1.getHand().get(3).getRank(); + Card myCard = player1.giveCard(rank); + + Assert.assertEquals(myCard.getRank(), rank); + + } + + @Test + public void drawCard() throws Exception { + GoFish gameOn = new GoFish(); + GoFishPlayer player1 = new GoFishPlayer(); + + gameOn.addPlayer(player1); + + for(int i = 0; i < 52; i++){ + Card expectedCard = gameOn.getGameDeck().getCards().get(0); + Card actualCard = player1.drawCard(gameOn.getGameDeck()); + //System.out.println(gameOn.getGameDeck().getDeckSize()); + Assert.assertEquals(expectedCard,actualCard); + } + } + + +} \ No newline at end of file From 7180752b34ded6fc86ecefa3d12f00bfcf127143 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Mon, 20 Nov 2017 11:44:54 -0500 Subject: [PATCH 05/30] casino UML 2.0_withRaulBus-Lina --- .../java/io/zipcoder/casino/BlackJack.java | 64 +++---- .../io/zipcoder/casino/BlackJackDealer.java | 4 + .../io/zipcoder/casino/BlackJackPlayer.java | 2 +- .../java/io/zipcoder/casino/CardGame.java | 4 + .../java/io/zipcoder/casino/CardPlayer.java | 4 + src/main/java/io/zipcoder/casino/Casino.uml | 87 +-------- src/main/java/io/zipcoder/casino/Craps.java | 2 +- src/main/java/io/zipcoder/casino/Deck.java | 6 - src/main/java/io/zipcoder/casino/GoFish.java | 2 +- .../io/zipcoder/casino/GoFishConsole.java | 58 ++++++ .../java/io/zipcoder/casino/GoFishPlayer.java | 42 ++++- .../io/zipcoder/casino/GoFishPlayerTest.java | 165 +++++++++++------- .../java/io/zipcoder/casino/GoFishTest.java | 48 +++++ userStories | 0 14 files changed, 297 insertions(+), 191 deletions(-) create mode 100644 src/main/java/io/zipcoder/casino/BlackJackDealer.java create mode 100644 src/main/java/io/zipcoder/casino/CardGame.java create mode 100644 src/main/java/io/zipcoder/casino/CardPlayer.java create mode 100644 src/main/java/io/zipcoder/casino/GoFishConsole.java create mode 100644 src/test/java/io/zipcoder/casino/GoFishTest.java create mode 100644 userStories diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index e63ede9d..5a775983 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -1,30 +1,34 @@ -//package io.zipcoder.casino; -// -//public class BlackJack extends Game implements PlayForMoney { -// private Bank house; -// private Deck gameDeck; -// -// public void scoreHand() { -// } -// -// public void addPlayers() { -// } -// -// public void bet() { -// -// } -// -// public void bet(double betAmount) { -// -// } -// -// public void bet(BetType betType, double betAmount) { -// -// } -// -// public void resolveBets() { -// } -// -// public void dealNewHand() { -// } -//} +package io.zipcoder.casino; + +public class BlackJack extends CardGame implements PlayForMoney { + private Bank house; + private Deck gameDeck; + + public void scoreHand() { + } + + public void addPlayers() { + } + + public void bet() { + + } + + public void bet(double betAmount) { + + } + + public void bet(BetType betType, double betAmount) { + + } + + public void placeBet(double betAmount) { + + } + + public void resolveBets() { + } + + public void dealNewHand() { + } +} diff --git a/src/main/java/io/zipcoder/casino/BlackJackDealer.java b/src/main/java/io/zipcoder/casino/BlackJackDealer.java new file mode 100644 index 00000000..b0860aa1 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/BlackJackDealer.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public class BlackJackDealer extends CardPlayer{ +} diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index 53435f8b..ad6723de 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -1,6 +1,6 @@ package io.zipcoder.casino; -public class BlackJackPlayer extends Player { +public class BlackJackPlayer extends CardPlayer { private Card[] hand; public void hit() { diff --git a/src/main/java/io/zipcoder/casino/CardGame.java b/src/main/java/io/zipcoder/casino/CardGame.java new file mode 100644 index 00000000..1354740d --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGame.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public class CardGame extends Game { +} diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java new file mode 100644 index 00000000..3cc6686b --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public class CardPlayer extends Player{ +} diff --git a/src/main/java/io/zipcoder/casino/Casino.uml b/src/main/java/io/zipcoder/casino/Casino.uml index 034d423a..5e58d802 100644 --- a/src/main/java/io/zipcoder/casino/Casino.uml +++ b/src/main/java/io/zipcoder/casino/Casino.uml @@ -5,16 +5,15 @@ io.zipcoder.casino.Casino io.zipcoder.casino.Game - io.zipcoder.casino.Hand + io.zipcoder.casino.Hand io.zipcoder.casino.Card io.zipcoder.casino.PlayForMoney io.zipcoder.casino.CrapsPlayer io.zipcoder.casino.Deck - io.zipcoder.casino.Dice io.zipcoder.casino.BlackJackPlayer io.zipcoder.casino.Suit - io.zipcoder.casino.Craps io.zipcoder.casino.Player + io.zipcoder.casino.Craps io.zipcoder.casino.BlackJack io.zipcoder.casino.Rank io.zipcoder.casino.GoFish @@ -23,78 +22,24 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -105,12 +50,6 @@ - - - - - - @@ -123,31 +62,17 @@ - - - - - - - - - - - - - - - - - - + + + io.zipcoder.casino.Hand + Fields Methods diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index f476c1fe..a846b12f 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -5,7 +5,7 @@ public class Craps extends Game implements PlayForMoney { private BetType betType; private double betAmount; private boolean isComeOut; - private Integer point; + private Integer point=0; private Integer comePoint; public void startRound(double betAmount){ diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java index 330e3b0e..3fed4241 100644 --- a/src/main/java/io/zipcoder/casino/Deck.java +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -33,12 +33,6 @@ public void shuffle() { Collections.shuffle(cards); } - public Card nextAvailableCard(){ - - return null; - } - - public Integer getDeckSize() { return cards.size(); } diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 20dca038..0ed0f92b 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -public class GoFish extends Game { +public class GoFish extends CardGame { private Deck gameDeck; public GoFish(){ diff --git a/src/main/java/io/zipcoder/casino/GoFishConsole.java b/src/main/java/io/zipcoder/casino/GoFishConsole.java new file mode 100644 index 00000000..73bb4592 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GoFishConsole.java @@ -0,0 +1,58 @@ +package io.zipcoder.casino; + +import java.util.ArrayList; +import java.util.Scanner; + +public class GoFishConsole extends Console{ + + /* public void playGoFish( + + do { + + game.player1turn(); + + player1.askForCard(); + if player2hascard + getCard + player1turn; + check for pairs + checkdeckempty + else player2doesnthave card + GOFISH. player1 draws card + + player2turn(); + + player1.askForCard(); + if player2hascard + getCard + player2turn; + check for pairs + checkdeckempty + else player2doesnthave card + GOFISH. player1 draws card + } + */ + + public void playerTurn(ArrayList players){ + System.out.println(players.get(0).getName()+ " your turn."); + + Rank rank = getRankInput(); + + System.out.println(rank); + } + + + public Rank getRankInput(){ + Scanner scan = new Scanner(System.in); + + do { + String stringInput = scan.nextLine(); + for (Rank rank : Rank.values()) { + if (rank.toString().equalsIgnoreCase(stringInput)) { + return rank; + } + } + System.out.println("Please enter a valid card."); + } while (true); + } +} diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index dbf8858e..a5673453 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -1,8 +1,12 @@ package io.zipcoder.casino; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Collectors; +import java.util.stream.Stream; -public class GoFishPlayer extends Player { +public class GoFishPlayer extends CardPlayer { private int score; private ArrayList hand = new ArrayList(); @@ -37,13 +41,41 @@ public Card giveCard(Rank rank){ return null; } - public boolean checkFourOfAKind(){ + public Suit checkFourOfAKind(){ + + Stream handStream = hand.stream(). + + /* int diamonds = 0; + int spades = 0; + int hearts = 0; + int clubs =0; + for(Card card: hand){ - + if (card.getSuit() == Suit.DIAMOND) { + diamonds++; + if (diamonds == 4) return Suit.DIAMOND; + } + if (card.getSuit() == Suit.HEART){ + hearts++; + if (hearts == 4) return Suit.HEART; + } + if (card.getSuit() == Suit.CLUB) { + clubs++; + if (clubs == 4) return Suit.CLUB; + } + if (card.getSuit() == Suit.SPADE) { + spades++; + if (spades == 4) return Suit.SPADE; + } + }return null; + + }*/ + + public void drawFiveCards(Deck deck){ + for(int i = 0; i<5; i++){ + hand.add(drawCard(deck)); } - } - public void drawFiveCards(){ } diff --git a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java index 8d90774e..677c6b8c 100644 --- a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java @@ -1,66 +1,99 @@ -package io.zipcoder.casino; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.theories.suppliers.TestedOn; - -import static org.junit.Assert.*; - -public class GoFishPlayerTest { - @Test - public void checkHandForCard() throws Exception { - GoFish gameOn = new GoFish(); - GoFishPlayer player1 = new GoFishPlayer(); - - String expected = ""; - for(int i=0; i<5;i++){ - Card card = player1.drawCard(gameOn.getGameDeck()); - player1.addCardToHand(card); - expected += card.getRank() + " of " +card.getSuit()+"s\n"; - } - - Rank rank = player1.getHand().get(3).getRank(); - - System.out.println(expected); - Assert.assertTrue(player1.checkHandForCard(rank)); - - } - - @Test - public void giveCard() throws Exception { - GoFish gameOn = new GoFish(); - GoFishPlayer player1 = new GoFishPlayer(); - - String expected = ""; - for(int i=0; i<5;i++){ - Card card = player1.drawCard(gameOn.getGameDeck()); - player1.addCardToHand(card); - expected += card.getRank() + " of " +card.getSuit()+"s\n"; - } - - System.out.println(expected); - - Rank rank = player1.getHand().get(3).getRank(); - Card myCard = player1.giveCard(rank); - - Assert.assertEquals(myCard.getRank(), rank); - - } - - @Test - public void drawCard() throws Exception { - GoFish gameOn = new GoFish(); - GoFishPlayer player1 = new GoFishPlayer(); - - gameOn.addPlayer(player1); - - for(int i = 0; i < 52; i++){ - Card expectedCard = gameOn.getGameDeck().getCards().get(0); - Card actualCard = player1.drawCard(gameOn.getGameDeck()); - //System.out.println(gameOn.getGameDeck().getDeckSize()); - Assert.assertEquals(expectedCard,actualCard); - } - } - - -} \ No newline at end of file +//package io.zipcoder.casino; +// +//import org.junit.Assert; +//import org.junit.Test; +//import org.junit.experimental.theories.suppliers.TestedOn; +// +//import java.util.ArrayList; +// +//import static org.junit.Assert.*; +// +//public class GoFishPlayerTest { +// @Test +// public void checkHandForCard() throws Exception { +// GoFish gameOn = new GoFish(); +// GoFishPlayer player1 = new GoFishPlayer(); +// +// String expected = ""; +// for(int i=0; i<5;i++){ +// Card card = player1.drawCard(gameOn.getGameDeck()); +// player1.addCardToHand(card); +// expected += card.getRank() + " of " +card.getSuit()+"s\n"; +// } +// +// Rank rank = player1.getHand().get(3).getRank(); +// +// System.out.println(expected); +// Assert.assertTrue(player1.checkHandForCard(rank)); +// +// } +// +// @Test +// public void giveCard() throws Exception { +// GoFish gameOn = new GoFish(); +// GoFishPlayer player1 = new GoFishPlayer(); +// +// String expected = ""; +// for(int i=0; i<5;i++){ +// Card card = player1.drawCard(gameOn.getGameDeck()); +// player1.addCardToHand(card); +// expected += card.getRank() + " of " +card.getSuit()+"s\n"; +// } +// +// System.out.println(expected); +// +// Rank rank = player1.getHand().get(3).getRank(); +// Card myCard = player1.giveCard(rank); +// +// Assert.assertEquals(myCard.getRank(), rank); +// +// } +// +// @Test +// public void drawCard() throws Exception { +// GoFish gameOn = new GoFish(); +// GoFishPlayer player1 = new GoFishPlayer(); +// +// gameOn.addPlayer(player1); +// +// for(int i = 0; i < 52; i++){ +// Card expectedCard = gameOn.getGameDeck().getCards().get(0); +// Card actualCard = player1.drawCard(gameOn.getGameDeck()); +// //System.out.println(gameOn.getGameDeck().getDeckSize()); +// Assert.assertEquals(expectedCard,actualCard); +// } +// } +// +// @Test +// public void checkFourOfAKindTest(){ +// Card someClub = new Card(Rank.EIGHT,Suit.CLUB); +// GoFishPlayer somePlayer = new GoFishPlayer(); +// +// for(int i =0; i<4;i++){ +// somePlayer.addCardToHand(someClub); +// } +// somePlayer.addCardToHand(new Card(Rank.ACE,Suit.HEART)); +// +// Assert.assertEquals(somePlayer.checkFourOfAKind(), Suit.CLUB); +// +// } +// +// @Test +// public void drawFiveCardsTest(){ +// GoFishPlayer somePlayer = new GoFishPlayer(); +// GoFish gameOn = new GoFish(); +// +// somePlayer.drawFiveCards(gameOn.getGameDeck()); +// +// ArrayList hand = somePlayer.getHand(); +// +// +// for(Card card:hand){ +// String expected = card.getRank() + " of " +card.getSuit()+"s"; +// System.out.println(expected); +// } +// +// +// } +// +//} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/GoFishTest.java b/src/test/java/io/zipcoder/casino/GoFishTest.java new file mode 100644 index 00000000..50bd18b1 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GoFishTest.java @@ -0,0 +1,48 @@ +//package io.zipcoder.casino; +// +//import org.junit.Assert; +//import org.junit.Test; +// +//import static org.junit.Assert.*; +// +//public class GoFishTest { +// @Test +// public void getGameDeck() throws Exception { +// } +// +// @Test +// public void checkForPairsTest() throws Exception{ +// GoFish gameOn = new GoFish(); +// +// GoFishPlayer player1 = new GoFishPlayer(); +// +// Card someSeven = new Card(Rank.SEVEN, Suit.CLUB); +// Card anotherSeven = new Card(Rank.SIX, Suit.HEART); +// +// player1.addCardToHand(someSeven); +// player1.addCardToHand(anotherSeven); +// player1.addCardToHand(new Card(Rank.FIVE, Suit.HEART)); +// player1.addCardToHand(new Card(Rank.FOUR, Suit.HEART)); +// player1.addCardToHand(new Card(Rank.THREE, Suit.HEART)); +// // player1.drawCard(gameOn.getGameDeck()); +// // player1.drawCard(gameOn.getGameDeck()); +// +// Assert.assertTrue(gameOn.hasPair(player1)); +// +// } +// +// @Test +// public void endGameDeclareWinner() throws Exception { +// GoFish gameOn = new GoFish(); +// GoFishPlayer player1 = new GoFishPlayer(); +// GoFishPlayer player2 = new GoFishPlayer(); +// +// gameOn.addPlayer(player1); +// gameOn.addPlayer(player2); +// +// player1.drawFiveCards(gameOn.getGameDeck()); +// player2.drawFiveCards(gameOn.getGameDeck()); +// +// } +// +//} \ No newline at end of file diff --git a/userStories b/userStories new file mode 100644 index 00000000..e69de29b From b95839350083cc06dc428c48ef13bdec9ea881ed Mon Sep 17 00:00:00 2001 From: gpatelos Date: Mon, 20 Nov 2017 12:41:50 -0500 Subject: [PATCH 06/30] user stories --- userStories | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/userStories b/userStories index e69de29b..1fce214b 100644 --- a/userStories +++ b/userStories @@ -0,0 +1,48 @@ +-As user I want to be able choose between blackjack, craps and go fish. +-As a user I want to set my profile. +-As a user I want to play anonymously. + +-As a blackjack player I want to place a bet on a blackjack hand. + +-As a blackjack player I want to play blackjack. + -As a blackjack player I want to start a game + -As a blackjack player I want look at my cards. + -As a blackjack player I want to know my bank account balance. + -As a blackjack player I want to hit so that I can get a card. + -As a blackjack player I would like to stand and see if I win my bet. + (As a blackjack player I would like to raise my bet if I have a good hand) + -As a blackjack player I would like to exit the game with my winnings. + + +-As a blackjack dealer I would like to deal in a however many players would like to join my game. +-As a blackjack dealer I would like to hit on everything up to 17. +(As a blackjack dealer I would also like to hit on a "soft" 17, + i.e. a hand containing an ace and one or more other cards totaling six.) +-As a blackjack dealer I would like to take bets from players. +-As a blackjack dealer I would like to payout winning bets from winning players. +-As a blackjack dealer I would like to reveal my cards at the end of each round. +-As a blackjack dealer I would like to determine winners / loser / pushers at the end of each round. + + +-As a gofish player I would like to start a game. +-As a gofish I would like to draw 7 cards. +-As a gofish player I would like to ask my opponent for a particular card. +-As a gofish player I would like to score a point when I have a book to lay down. +-As a gofish player I would like to draw a card when my opponent doesn't have what I requested. +-As a gofish player I would like to give a card that has been requested. +-As a gofish player I would like to see the final score when the deck is empty. + +-As a gofish bot. I would like to ask for the card that I have the most of + (or that that has been asked of me). +-As a gofish programmer I would like a display method for my bot, for testing purposes only. + + +-As a craps player I would like to start the game. +-As a craps I bet on a dice roll. +-As a craps player I want to roll the dice. +-As a craps player I would like to bet on the pass line. +-As a craps player I would like to bet on the don't pass line. +(As a craps player I would like make "come" bets) +(As a craps player I would like make "don't come bets") +-As a craps player I would like take my winnings and go home. +(As a craps player I would like to borrow money from the casino when I run out.) From af9e21222cbd704933a9ba9ad5fd8af7addcd7f6 Mon Sep 17 00:00:00 2001 From: amyaim Date: Mon, 20 Nov 2017 16:07:57 -0500 Subject: [PATCH 07/30] done with the userstory --- src/main/java/io/zipcoder/casino/BetType.java | 4 - src/main/java/io/zipcoder/casino/Hand.java | 5 -- userStories | 73 +++++++++++++++++-- 3 files changed, 67 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/io/zipcoder/casino/BetType.java delete mode 100644 src/main/java/io/zipcoder/casino/Hand.java diff --git a/src/main/java/io/zipcoder/casino/BetType.java b/src/main/java/io/zipcoder/casino/BetType.java deleted file mode 100644 index 4fc88d5e..00000000 --- a/src/main/java/io/zipcoder/casino/BetType.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.zipcoder.casino; - -public enum BetType {PASS, DONTPASS, COME, DONTCOME, ODDS, PLACEWIN, PLACELOSE,BUY -} diff --git a/src/main/java/io/zipcoder/casino/Hand.java b/src/main/java/io/zipcoder/casino/Hand.java deleted file mode 100644 index cb06c8f3..00000000 --- a/src/main/java/io/zipcoder/casino/Hand.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.zipcoder.casino; - -public class Hand { - private Card[] cards; -} diff --git a/userStories b/userStories index 1fce214b..8665f683 100644 --- a/userStories +++ b/userStories @@ -6,41 +6,102 @@ -As a blackjack player I want to play blackjack. -As a blackjack player I want to start a game + test can create a game (Blackjack) + test can add a players to the game (Game) + test existance of a deck (BlackJack, Deck) + test existace of a hand (Blackjack, player) + - As a blackjack player I want to bet before I get the cards + test the bank balance of the player is sufficient to bet (BlackJack, Player) + and the player's pot in the game is increased (BlackJack) + the player money decrease by the bet amount (Player) + + -As a blackjack player I want look at my cards. - -As a blackjack player I want to know my bank account balance. + test when the player deal/ hit, it can view the cards (Player) + + -As a blackjack player I want to know my bank account balance + test before you place a bet, it can check the balance (Player) -As a blackjack player I want to hit so that I can get a card. + test when hit the player gets additional card (Player) + test the deck will remove the same card (Blackjack) -As a blackjack player I would like to stand and see if I win my bet. + show sum of the player card when stands (Player) + check if the sum will beat the dealer (Blackjack) + (As a blackjack player I would like to raise my bet if I have a good hand) -As a blackjack player I would like to exit the game with my winnings. + test the player has all the money it win before exit (Player) + test the game return null value for the player after the player exist (BlackJack) -As a blackjack dealer I would like to deal in a however many players would like to join my game. + test when the game starts the player/s receive cards (Player) -As a blackjack dealer I would like to hit on everything up to 17. + test the dealer hit only if the score is less than 17 (Blackjack) (As a blackjack dealer I would also like to hit on a "soft" 17, i.e. a hand containing an ace and one or more other cards totaling six.) --As a blackjack dealer I would like to take bets from players. --As a blackjack dealer I would like to payout winning bets from winning players. -As a blackjack dealer I would like to reveal my cards at the end of each round. + test the hand of the dealer are visible for the player (dealer) -As a blackjack dealer I would like to determine winners / loser / pushers at the end of each round. + test the highest score less than 22 win the game (Blackjack) -As a gofish player I would like to start a game. --As a gofish I would like to draw 7 cards. + + test can create a game (GoFish) + test can add a players to the game (GoFish) + test existance of a deck (GoFish, Deck) + test existace of a hand (GoFish, GoFishPlayer) + +-As a gofish I would like to draw 7 cards (GoFish) + test that the first 7 cards from the deck are in my hand + test that these cards are removed from the deck + -As a gofish player I would like to ask my opponent for a particular card. + test boolean on the other player whether or not has the card asked + -As a gofish player I would like to score a point when I have a book to lay down. + test I have 4 cards of the same Rank, I remove the cards from my hand + test my score incremented one point. + -As a gofish player I would like to draw a card when my opponent doesn't have what I requested. + test I GoFish and draw a card from the deck + -As a gofish player I would like to give a card that has been requested. + test the card is removed from my hand and it's add to the requested hand. -As a gofish player I would like to see the final score when the deck is empty. + test which player has the biggest amount of points -As a gofish bot. I would like to ask for the card that I have the most of (or that that has been asked of me). + test the goFish bot request a card of rank that it's on its hand -As a gofish programmer I would like a display method for my bot, for testing purposes only. -As a craps player I would like to start the game. --As a craps I bet on a dice roll. + test can add a players to the game (Game) + +-As a craps I bet on a dice roll + test the bank balance of the player is sufficient to bet (Craps, CrapsPlayer) + and the player's pot in the game is increased (Craps) + the player money decrease by the bet amount (Player) + -As a craps player I want to roll the dice. --As a craps player I would like to bet on the pass line. + test dice are rolling and returning values + +-As craps player I would like to win my pass bet when I roll a 7 or 11 on the comeout. + test a sum of 7 or 11 in the first roll will win the game + test the money of the player increase by the amount of the bet +-As a craps player I would to like to lose my pass bet when I roll a 2, 3 or 12 on the comeout. + test 2,3,12 will make the player loose the game + test the money of the player decrease by the bet amount +-As a craps player I would like to win my pass bet when I have rolled anything but a 7, 11, 2, 3, 12, +to set a point and rolled that point. + test the player is able to roll the dice untill it get a sum of the point or 7 + test the money of the player increase by the amount of the bet if the sum equals the point +-As a craps player I would like to lose my pass bet when I have rolled a 7. + test 7 will make the player loose the game + test the money of the player decrease by the bet amount -As a craps player I would like to bet on the don't pass line. (As a craps player I would like make "come" bets) (As a craps player I would like make "don't come bets") From 1d2fd12951824a70f9408114b3d71b08d2525171 Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 20 Nov 2017 16:18:43 -0500 Subject: [PATCH 08/30] jobdone --- .../java/io/zipcoder/casino/BlackJack.java | 7 ++- .../io/zipcoder/casino/BlackJackPlayer.java | 19 ++++++-- .../java/io/zipcoder/casino/CardPlayer.java | 2 + src/main/java/io/zipcoder/casino/Deck.java | 4 ++ src/main/java/io/zipcoder/casino/Game.java | 4 ++ src/main/java/io/zipcoder/casino/Hand.java | 1 + src/main/java/io/zipcoder/casino/Player.java | 2 + .../zipcoder/casino/BlackJackPlayerTest.java | 11 +++++ .../java/io/zipcoder/casino/DeckTest.java | 7 +-- userStories | 48 +++++++++++++++++++ 10 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index 5a775983..f6a33e41 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -1,13 +1,18 @@ package io.zipcoder.casino; public class BlackJack extends CardGame implements PlayForMoney { + + + private Bank house; private Deck gameDeck; public void scoreHand() { + } - public void addPlayers() { + public void addPlayers(Player player) { + } public void bet() { diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index ad6723de..609f2955 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -1,12 +1,25 @@ package io.zipcoder.casino; public class BlackJackPlayer extends CardPlayer { - private Card[] hand; + private Hand hand; + + + public void startGame(Deck deck) { + + } + + public double showBalance() { - public void hit() { } - public void stay() { + public Card hit(Deck deck) { + return deck.pop(); } + public boolean stay() { + + return true; + } + + } diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index 3cc6686b..e3cd8cbc 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -1,4 +1,6 @@ package io.zipcoder.casino; public class CardPlayer extends Player{ + + } diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java index 3fed4241..73f2865e 100644 --- a/src/main/java/io/zipcoder/casino/Deck.java +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -36,4 +36,8 @@ public void shuffle() { public Integer getDeckSize() { return cards.size(); } + + public Card pop() { + return null; + } } diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index d843497c..c82a2465 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -17,4 +17,8 @@ public void addPlayer(Player player){ public boolean isEndRound() { return false; } + + public void startGame(){ + + } } diff --git a/src/main/java/io/zipcoder/casino/Hand.java b/src/main/java/io/zipcoder/casino/Hand.java index cb06c8f3..6b4e9781 100644 --- a/src/main/java/io/zipcoder/casino/Hand.java +++ b/src/main/java/io/zipcoder/casino/Hand.java @@ -2,4 +2,5 @@ public class Hand { private Card[] cards; + } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index d2ae7068..0eec281d 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -16,4 +16,6 @@ public boolean isWinner() { return false; } + + } diff --git a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java new file mode 100644 index 00000000..d79dd32d --- /dev/null +++ b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino; + +import org.junit.Test; + +public class BlackJackPlayerTest { + + @Test + public void startGameTest(){ + + } +} diff --git a/src/test/java/io/zipcoder/casino/DeckTest.java b/src/test/java/io/zipcoder/casino/DeckTest.java index 82df34a3..8f0eb751 100644 --- a/src/test/java/io/zipcoder/casino/DeckTest.java +++ b/src/test/java/io/zipcoder/casino/DeckTest.java @@ -8,11 +8,11 @@ import static org.junit.Assert.*; public class DeckTest { + Deck deck = new Deck(); + @Test public void constructorTest(){ - Deck deck = new Deck(); - ArrayList cards = deck.getCards(); String expected = "a bunch of cards"; @@ -27,7 +27,6 @@ public void constructorTest(){ @Test public void shuffleTest() throws Exception { - Deck deck = new Deck(); deck.shuffle(); ArrayList cards = deck.getCards(); @@ -41,7 +40,9 @@ public void shuffleTest() throws Exception { Assert.assertEquals(expected, actual); + } + public void testPop() { } diff --git a/userStories b/userStories index e69de29b..3f2a95b7 100644 --- a/userStories +++ b/userStories @@ -0,0 +1,48 @@ +-As user I want to be able choose between blackjack, craps and go fish. +-As a user I want to set my profile. +-As a user I want to play anonymously. + +-As a blackjack player I want to place a bet on a blackjack hand. + +-As a blackjack player I want to play blackjack. + -As a blackjack player I want to start a game + -As a blackjack player I want look at my cards. + -As a blackjack player I want to know my bank account balance. + -As a blackjack player I want to hit so that I can get a card. + -As a blackjack player I would like to stand and see if I win my bet. + (As a blackjack player I would like to raise my bet if I have a good hand) + -As a blackjack player I would like to exit the game with my winnings. + + +-As a blackjack dealer I would like to deal in a however many players would like to join my game. +-As a blackjack dealer I would like to hit on everything up to 17. +(As a blackjack dealer I would also like to hit on a "soft" 17, + i.e. a hand containing an ace and one or more other cards totaling six.) +-As a blackjack dealer I would like to take bets from players. +-As a blackjack dealer I would like to payout winning bets from winning players. +-As a blackjack dealer I would like to reveal my cards at the end of each round. +-As a blackjack dealer I would like to determine winners / loser / pushers at the end of each round. + + +-As a gofish player I would like to start a game. +-As a gofish I would like to draw 7 cards. +-As a gofish player I would like to ask my opponent for a particular card. +-As a gofish player I would like to score a point when I have a book to lay down. +-As a gofish player I would like to draw a card when my opponent doesn't have what I requested. +-As a gofish player I would like to give a card that has been requested. +-As a gofish player I would like to see the final score when the deck is empty. + +-As a gofish bot. I would like to ask for the card that I have the most of + (or that that has been asked of me). +-As a gofish programmer I would like a display method for my bot, for testing purposes only. + + +-As a craps player I would like to start the game. +-As a craps I bet on a dice roll. +-As a craps player I want to roll the dice. +-As a craps player I would like to bet on the pass line. +-As a craps player I would like to bet on the don't pass line. +(As a craps player I would like make "come" bets) +(As a craps player I would like make "don't come bets") +-As a craps player I would like take my winnings and go home. +(As a craps player I would like to borrow money from the casino when I run out.) \ No newline at end of file From f528985d739b49c455a3245d1ddcbd7c58fd3867 Mon Sep 17 00:00:00 2001 From: amyaim Date: Mon, 20 Nov 2017 17:42:53 -0500 Subject: [PATCH 09/30] changed content of some classes --- .../io/zipcoder/casino/BlackJackPlayer.java | 2 ++ .../java/io/zipcoder/casino/CardGame.java | 9 ++++++ .../java/io/zipcoder/casino/CardPlayer.java | 14 +++++++++ src/main/java/io/zipcoder/casino/Game.java | 9 +++--- src/main/java/io/zipcoder/casino/GoFish.java | 2 +- .../java/io/zipcoder/casino/GoFishPlayer.java | 13 ++++----- src/main/java/io/zipcoder/casino/Player.java | 4 +-- .../java/io/zipcoder/casino/GoFishTest.java | 29 ++++++++++--------- 8 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index ad6723de..a03031ad 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -9,4 +9,6 @@ public void hit() { public void stay() { } + + } diff --git a/src/main/java/io/zipcoder/casino/CardGame.java b/src/main/java/io/zipcoder/casino/CardGame.java index 1354740d..bcdd8036 100644 --- a/src/main/java/io/zipcoder/casino/CardGame.java +++ b/src/main/java/io/zipcoder/casino/CardGame.java @@ -1,4 +1,13 @@ package io.zipcoder.casino; +import java.util.ArrayList; + public class CardGame extends Game { + + private Deck gameDeck; + + + public void startPlayerTurn() { + + } } diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index 3cc6686b..896551c0 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -1,4 +1,18 @@ package io.zipcoder.casino; +import java.util.ArrayList; + public class CardPlayer extends Player{ + private ArrayList hand; + + + + + public ArrayList getHand() { + return hand; + } + + public void setHand(ArrayList hand) { + this.hand = hand; + } } diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index d843497c..7960decb 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -2,13 +2,12 @@ import java.util.ArrayList; -public class Game { - private int round; - private ArrayList players = new ArrayList(); +public abstract class Game { + private int playerTurn; - public void startRound() { + private ArrayList players = new ArrayList(); - } + public abstract void startPlayerTurn(); public void addPlayer(Player player){ players.add(player); diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 0ed0f92b..473079e0 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -3,7 +3,7 @@ import java.util.ArrayList; public class GoFish extends CardGame { - private Deck gameDeck; + public GoFish(){ this.gameDeck = new Deck(); diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index a5673453..934c6e1d 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -7,8 +7,7 @@ import java.util.stream.Stream; public class GoFishPlayer extends CardPlayer { - private int score; - private ArrayList hand = new ArrayList(); + public Card drawCard(Deck deck) { @@ -43,7 +42,7 @@ public Card giveCard(Rank rank){ public Suit checkFourOfAKind(){ - Stream handStream = hand.stream(). + // Stream handStream = hand.stream(). /* int diamonds = 0; int spades = 0; @@ -71,10 +70,10 @@ public Suit checkFourOfAKind(){ }*/ - public void drawFiveCards(Deck deck){ - for(int i = 0; i<5; i++){ - hand.add(drawCard(deck)); - } +// public void drawFiveCards(Deck deck){ +// for(int i = 0; i<5; i++){ +// hand.add(drawCard(deck)); +// } } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index d2ae7068..2bc5fcbd 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -12,8 +12,6 @@ public String getName() { return name; } - public boolean isWinner() { - return false; - } + } diff --git a/src/test/java/io/zipcoder/casino/GoFishTest.java b/src/test/java/io/zipcoder/casino/GoFishTest.java index 50bd18b1..3b1a80f1 100644 --- a/src/test/java/io/zipcoder/casino/GoFishTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishTest.java @@ -1,14 +1,17 @@ -//package io.zipcoder.casino; -// -//import org.junit.Assert; -//import org.junit.Test; -// -//import static org.junit.Assert.*; -// -//public class GoFishTest { -// @Test -// public void getGameDeck() throws Exception { -// } +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class GoFishTest { + @Test + public void createGoFishGameTest() throws Exception { + + ; + + } // // @Test // public void checkForPairsTest() throws Exception{ @@ -44,5 +47,5 @@ // player2.drawFiveCards(gameOn.getGameDeck()); // // } -// -//} \ No newline at end of file + +} \ No newline at end of file From 2940bc00c02db1b6ce62782e35c27d9e11591164 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Mon, 20 Nov 2017 17:48:50 -0500 Subject: [PATCH 10/30] adding craps tests2 --- .DS_Store | Bin 0 -> 6148 bytes src/main/java/io/zipcoder/casino/Craps.java | 59 ++++++++++++++++-- .../java/io/zipcoder/casino/GoFishPlayer.java | 5 +- .../java/io/zipcoder/casino/CrapsTest.java | 12 ++++ userStories | 7 ++- 5 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9a874b5768f336915163bb88cd434575b859f936 GIT binary patch literal 6148 zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tF3k&vj^b9A16778<}(6eNJu~Vz<8=6`~ zboab&MFtUB!i}=AFfm2m$tVxGT*u4pe81nUlA49C} z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7*lF7m<7{{#Hn{6A@7N(HFEpDCdI z{ handStream = hand.stream(). - + Stream handStream = hand.stream() + .collect(Collectors.toMap(Rank.values() , p->p,(p,q) ->p)).values() + .stream(); /* int diamonds = 0; int spades = 0; int hearts = 0; diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index af823afe..55b47c19 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -10,6 +10,18 @@ public class CrapsTest { public void startRoundB() throws Exception { } + @Test + // as a craps player I would like to roll again if I my roll + // doesn't win or lose + public boolean rollAgain(){ + Craps gameOn = new Craps(); + Integer = + + if(!gameOn.passBetWins()&& passBetLosesTest();) + + } + + @Test public void passBetWinsTest() throws Exception { Craps game = new Craps(); diff --git a/userStories b/userStories index 8665f683..7b27859d 100644 --- a/userStories +++ b/userStories @@ -99,9 +99,10 @@ to set a point and rolled that point. test the player is able to roll the dice untill it get a sum of the point or 7 test the money of the player increase by the amount of the bet if the sum equals the point --As a craps player I would like to lose my pass bet when I have rolled a 7. - test 7 will make the player loose the game - test the money of the player decrease by the bet amount +-As a craps player I would like to lose my pass bet when when I have rolled anything but a 7, 11, 2, 3, 12, +to set a point and rolled 7 before my the set point. + test 7 will make the player loose the game + test the money of the player decrease by the bet amount -As a craps player I would like to bet on the don't pass line. (As a craps player I would like make "come" bets) (As a craps player I would like make "don't come bets") From 1e7b9dac684d93f889f1b66438839df3a826b712 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 21 Nov 2017 15:32:49 -0500 Subject: [PATCH 11/30] blackJack --- pom.xml | 6 ++++ .../java/io/zipcoder/casino/BlackJack.java | 31 +++++++++++++------ .../io/zipcoder/casino/BlackJackDealer.java | 4 +-- .../io/zipcoder/casino/BlackJackPlayer.java | 12 +++++++ src/main/java/io/zipcoder/casino/Card.java | 2 ++ .../java/io/zipcoder/casino/CardPlayer.java | 10 +++--- .../java/io/zipcoder/casino/PlayForMoney.java | 4 ++- src/main/java/io/zipcoder/casino/Player.java | 16 +++++++--- .../zipcoder/casino/BlackJackPlayerTest.java | 28 ++++++++++++++++- .../io/zipcoder/casino/BlackJackTest.java | 3 ++ .../java/io/zipcoder/casino/DeckTest.java | 8 ++--- .../java/io/zipcoder/casino/GameTest.java | 12 +++++-- .../java/io/zipcoder/casino/HandTest.java | 13 ++++++++ 13 files changed, 119 insertions(+), 30 deletions(-) create mode 100644 src/test/java/io/zipcoder/casino/HandTest.java diff --git a/pom.xml b/pom.xml index c6ec0cc8..e6f7cb34 100644 --- a/pom.xml +++ b/pom.xml @@ -15,5 +15,11 @@ 4.12 test + + org.mockito + mockito-all + 1.9.5 + test + diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index 6b8093cf..082e59b0 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -1,36 +1,49 @@ package io.zipcoder.casino; +import java.util.ArrayList; + public class BlackJack extends CardGame implements PlayForMoney { private Bank house; private Deck gameDeck; + BlackJackPlayer blackJackPlayer; + ArrayList moneyfromPlayers = new ArrayList(); - public Deck getDeckCards(){ + public ArrayList getDeckCards() { - return + return null; } - public void scoreHand() { + public double betReceiveFromPlayers() { + for(Double amountInGame: moneyfromPlayers){ + moneyfromPlayers.add(blackJackPlayer.getBet()); + return amountInGame; + } + return 0; } - public void bet() { - + public void resolveBets() { } - public void bet(double betAmount) { + public void dealNewHand() { } + public double betInplay() { - public void placeBet(double betAmount) { + return 0; } - public void resolveBets() { + public void hand(Card card1, Card card2) { + + card1.getSuit(); + } - public void dealNewHand() { + + public void scoreHand() { } } diff --git a/src/main/java/io/zipcoder/casino/BlackJackDealer.java b/src/main/java/io/zipcoder/casino/BlackJackDealer.java index b0860aa1..c901e6b8 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackDealer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackDealer.java @@ -1,4 +1,4 @@ package io.zipcoder.casino; -public class BlackJackDealer extends CardPlayer{ -} +//public class BlackJackDealer extends CardPlayer{ +//} diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index a5faf910..a80ecea2 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -2,8 +2,20 @@ public class BlackJackPlayer extends CardPlayer { + private double bet; + public void startGame(Deck deck) { + if (deck == null) { + throw new IllegalStateException("Deck is null"); + } + } + + public void setBet(double amount){ + this.bet = amount; + } + public double getBet() { + return bet; } public double showBalance() { diff --git a/src/main/java/io/zipcoder/casino/Card.java b/src/main/java/io/zipcoder/casino/Card.java index c3ad2c59..3b735143 100644 --- a/src/main/java/io/zipcoder/casino/Card.java +++ b/src/main/java/io/zipcoder/casino/Card.java @@ -16,4 +16,6 @@ public Rank getRank() { public Suit getSuit() { return suit; } + + } diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index e3cd8cbc..0513c5da 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -1,6 +1,6 @@ package io.zipcoder.casino; - -public class CardPlayer extends Player{ - - -} +// +//public class CardPlayer extends Player{ +// +// +//} diff --git a/src/main/java/io/zipcoder/casino/PlayForMoney.java b/src/main/java/io/zipcoder/casino/PlayForMoney.java index a49fe47e..90eb13df 100644 --- a/src/main/java/io/zipcoder/casino/PlayForMoney.java +++ b/src/main/java/io/zipcoder/casino/PlayForMoney.java @@ -1,7 +1,9 @@ package io.zipcoder.casino; public interface PlayForMoney { - void placeBet(double betAmount ); + + + double betReceiveFromPlayers(); void resolveBets(); } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index 0eec281d..84a5d5ef 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -4,6 +4,15 @@ public class Player { private double bank; private String name; + + public Player(String name) { + this.name = name; + } + + public void setBank(double bank) { + this.bank = bank; + } + public void setName(String name) { this.name = name; } @@ -12,10 +21,7 @@ public String getName() { return name; } - public boolean isWinner() { - return false; + public double getBank() { + return bank; } - - - } diff --git a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java index d79dd32d..11904fa1 100644 --- a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java @@ -1,11 +1,37 @@ package io.zipcoder.casino; + +// -As a blackjack player I want to place a bet on a blackjack hand. + +import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) + public class BlackJackPlayerTest { + BlackJack blackJack = new BlackJack(); + + @Test(expected = IllegalStateException.class) + public void shouldThrowIllegalStateExceptionWhenDeckIsNull() { + BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + Deck deck = null; + blackJackPlayer.startGame(deck); + Assert.assertNull(deck); + } + @Test - public void startGameTest(){ + public void placeBetTest() { + + BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + blackJackPlayer.setBet(10); + double actual = 10; + double expected = blackJack.betReceiveFromPlayers();// 10 + Assert.assertEquals(actual, expected, 0); } + } diff --git a/src/test/java/io/zipcoder/casino/BlackJackTest.java b/src/test/java/io/zipcoder/casino/BlackJackTest.java index a3f493f8..4c964a9b 100644 --- a/src/test/java/io/zipcoder/casino/BlackJackTest.java +++ b/src/test/java/io/zipcoder/casino/BlackJackTest.java @@ -20,4 +20,7 @@ public void playersAddTest(){ Assert.assertEquals(expected, actual); } + + + } diff --git a/src/test/java/io/zipcoder/casino/DeckTest.java b/src/test/java/io/zipcoder/casino/DeckTest.java index 8f0eb751..5dc7bee4 100644 --- a/src/test/java/io/zipcoder/casino/DeckTest.java +++ b/src/test/java/io/zipcoder/casino/DeckTest.java @@ -14,14 +14,11 @@ public class DeckTest { @Test public void constructorTest(){ ArrayList cards = deck.getCards(); - String expected = "a bunch of cards"; - String actual = "***output***\n"; - + String actual = "***output***\n "; for(Card card: cards){ actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); } - Assert.assertEquals(expected, actual); } @@ -42,7 +39,8 @@ public void shuffleTest() throws Exception { } - public void testPop() { + public void testPop(){ + } diff --git a/src/test/java/io/zipcoder/casino/GameTest.java b/src/test/java/io/zipcoder/casino/GameTest.java index 6f55c296..32864ddb 100644 --- a/src/test/java/io/zipcoder/casino/GameTest.java +++ b/src/test/java/io/zipcoder/casino/GameTest.java @@ -1,5 +1,6 @@ package io.zipcoder.casino; +import org.junit.Assert; import org.junit.Test; import java.lang.reflect.Array; @@ -8,9 +9,16 @@ public class GameTest { + Game game = new Game(); + @Test - public void addPlayerTest(){ - ArrayList players = new ArrayList(); + public void addPlayerTest() { + + Player raul = new Player(); + game.addPlayer(raul); + int expected = 1; + int actual = game.getPlayers().size(); + Assert.assertEquals(actual, expected); } } diff --git a/src/test/java/io/zipcoder/casino/HandTest.java b/src/test/java/io/zipcoder/casino/HandTest.java new file mode 100644 index 00000000..ab82b630 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/HandTest.java @@ -0,0 +1,13 @@ +package io.zipcoder.casino; + +import org.junit.Test; + +public class HandTest { + + Hand hand = new Hand(); + @Test + public void getCards(){ + + + } +} From 78686d63e5b1544a5401b80be30b4aaacfb5b099 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Tue, 21 Nov 2017 16:12:53 -0500 Subject: [PATCH 12/30] craps redo --- pom.xml | 7 + .../java/io/zipcoder/casino/BlackJack.java | 4 +- src/main/java/io/zipcoder/casino/Console.java | 19 ++- src/main/java/io/zipcoder/casino/Craps.java | 63 ++++++-- .../java/io/zipcoder/casino/CrapsBetType.java | 4 + src/main/java/io/zipcoder/casino/GoFish.java | 2 + .../java/io/zipcoder/casino/GoFishPlayer.java | 12 +- .../java/io/zipcoder/casino/PlayForMoney.java | 2 +- .../io/zipcoder/casino/CrapsPlayerTest.java | 14 +- .../java/io/zipcoder/casino/CrapsTest.java | 146 +++++++++++++++++- 10 files changed, 229 insertions(+), 44 deletions(-) create mode 100644 src/main/java/io/zipcoder/casino/CrapsBetType.java diff --git a/pom.xml b/pom.xml index c6ec0cc8..30f14b32 100644 --- a/pom.xml +++ b/pom.xml @@ -15,5 +15,12 @@ 4.12 test + + org.mockito + mockito-all + 1.9.5 + test + + diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index 5a775983..64162ea1 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -18,11 +18,11 @@ public void bet(double betAmount) { } - public void bet(BetType betType, double betAmount) { + public void bet(CrapsBetType betType, double betAmount) { } - public void placeBet(double betAmount) { + public void takeBet(Double betAmount) { } diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 53d985de..1a2c0aca 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -26,6 +26,14 @@ public void playCraps() { System.out.println("S to shoot"); String play = getAnyKey(); + /* if(playerWantsToPlay(promptPlayer())){ + Integer roll = shooter.roll2Dice(); + showResultsOfRoll(shooter) + gameOn.setComeOut(true); + if(comeOutRollIsNeitherWinNorLose(roll)){ + + } + } if (play.equals("y")){ Integer roll = shooter.roll2Dice(); shooter.printRoll(); @@ -57,7 +65,7 @@ else if(gameOn.passBetWinsComeOut(roll)){ - } + }*/ // boolean won = isWinner(bet, roll): @@ -69,9 +77,6 @@ private boolean isWinner() { return true; } - private BetType getBet() { - return null; - } public void playBlackJack() { } @@ -99,6 +104,12 @@ public double getDoubleInput() { return dblInput; } + +/* + comeOutRollIsNeitherWinNorLose(int roll){ + return game.comeOutPassBet(roll) && gemae.comeOutPassLoss(roll) + //// + }*/ } diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index 0336aa86..ed0129f7 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -2,7 +2,7 @@ public class Craps extends Game implements PlayForMoney { private Bank house; - private BetType betType; + private CrapsBetType betType; private Double playerBet; private boolean isComeOut; private Integer point=0; @@ -12,6 +12,18 @@ public void getDiceRoll(CrapsPlayer player){ player.roll2Dice(); } + public void startPlayerTurn() { + + + } + public void takeBet(Double betAmount) { + this.playerBet = betAmount; + } + + + public Double getPlayerBet() { + return playerBet; + } /* if (play.equals("y")){ @@ -40,16 +52,10 @@ else if(gameOn.passBetWinsComeOut(roll)){ System.out.println("You win! Added " + passLineBet + " to your bank."); }else if(gameOn.passBetLoses(roll)){ System.out.println("You lose."); - } + }*/ - */ - - public void takeBets(CrapsPlayer player){ - - } - public void isWinner(){ } @@ -65,9 +71,7 @@ public void crapsRound(){ - public boolean passBetWinsComeOut(int roll) { - return (roll == 7 || roll == 11); - } + /* public boolean passBetLosesComeOut(int roll){ return (roll == 2 || roll == 3 || roll == 12); @@ -80,7 +84,7 @@ public boolean passBetWins(int roll) { public boolean passBetLoses(int roll){ return (roll == 7); - } + }*/ @@ -92,7 +96,7 @@ public boolean dontPassWins(int roll){ //refactor to add push condition for 12 } - public void setBetType(BetType betType) { + public void setBetType(CrapsBetType betType) { this.betType = betType; } @@ -104,6 +108,11 @@ public void rollAgain(){ } + + public void takeBet(double betAmount) { + + } + public void resolveBets() { } @@ -123,4 +132,32 @@ public void setPoint(Integer point) { public int getPoint() { return point; } + + public boolean isBetWinComeOut(int roll, CrapsBetType betType) { + if(betType == CrapsBetType.PASSLINE) + return (roll == 7 || roll == 11); + if (betType == CrapsBetType.DONTPASS) + return (roll == 2 || roll == 3); + return false; + + } + + public boolean isBetLossComeOut(int roll, CrapsBetType betType) { + if(betType == CrapsBetType.PASSLINE) + return (roll == 2 || roll == 3 || roll ==12); + if (betType == CrapsBetType.DONTPASS) + return (roll == 7 || roll == 11); + return false; + + } + + + public CrapsBetType getBetType() { + return betType; + } + + public boolean isNoResultRoll(int roll, CrapsBetType betType) { + return !isBetWinComeOut(roll, betType) && !isBetLossComeOut(roll,betType); + + } } diff --git a/src/main/java/io/zipcoder/casino/CrapsBetType.java b/src/main/java/io/zipcoder/casino/CrapsBetType.java new file mode 100644 index 00000000..6b42afe5 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CrapsBetType.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public enum CrapsBetType {PASSLINE, DONTPASS +} diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 473079e0..0d6a8c9c 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -2,6 +2,7 @@ import java.util.ArrayList; +/* public class GoFish extends CardGame { @@ -19,3 +20,4 @@ public Player endGameDeclareWinner(){ } } +*/ diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index 934c6e1d..5614a610 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -9,12 +9,11 @@ public class GoFishPlayer extends CardPlayer { - public Card drawCard(Deck deck) { Card playerCard = deck.getCards().remove(0); return playerCard; } - +/* public void addCardToHand(Card card){ hand.add(card); } @@ -38,11 +37,11 @@ public Card giveCard(Rank rank){ } } return null; - } + }*/ - public Suit checkFourOfAKind(){ + // public Suit checkFourOfAKind() { - // Stream handStream = hand.stream(). + // Stream handStream = hand.stream(). /* int diamonds = 0; int spades = 0; @@ -76,7 +75,4 @@ public Suit checkFourOfAKind(){ // } - } - - } diff --git a/src/main/java/io/zipcoder/casino/PlayForMoney.java b/src/main/java/io/zipcoder/casino/PlayForMoney.java index a49fe47e..94d69d58 100644 --- a/src/main/java/io/zipcoder/casino/PlayForMoney.java +++ b/src/main/java/io/zipcoder/casino/PlayForMoney.java @@ -1,7 +1,7 @@ package io.zipcoder.casino; public interface PlayForMoney { - void placeBet(double betAmount ); + void takeBet(Double betAmount ); void resolveBets(); } diff --git a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java index c3a48105..99d322b3 100644 --- a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java @@ -1,24 +1,20 @@ package io.zipcoder.casino; -import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; public class CrapsPlayerTest { @Test - public void roll2DiceTest(){ + public void shouldReturnAvalueBetween2AND12WhileRollingDiceTest(){ CrapsPlayer shooter = new CrapsPlayer(); Integer actual = shooter.roll2Dice(); - Assert.assertTrue(actual <13 && actual > 0); - - for(int i =0; i < 1000000; i++){ - actual = shooter.roll2Dice(); - Assert.assertTrue(actual <13 && actual > 0); - } + assertTrue(actual <13 && actual > 2); } + + } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index 55b47c19..354a79db 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -2,27 +2,159 @@ import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; + +@RunWith(MockitoJUnitRunner.class) public class CrapsTest { + + @Test + public void shouldAskPlayerTypeOfBet(){ + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer(); + + CrapsBetType expected = CrapsBetType.PASSLINE; + craps.setBetType(CrapsBetType.PASSLINE); + + CrapsBetType actual = craps.getBetType(); + + } + @Test + public void shouldTakePlayerMoneyAndSetBetAmount(){ + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer(); + + Double expected = 50.0; + craps.takeBet(expected); + + Double actual = craps.getPlayerBet(); + + Assert.assertEquals(expected,actual, 0); + } + + @Test + public void isWinOnComeRoll(){ + //given betType + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.PASSLINE); + CrapsBetType passBet = craps.getBetType(); + + Assert.assertTrue(craps.isBetWinComeOut(7, passBet)); + Assert.assertTrue(craps.isBetWinComeOut(11, passBet)); + + craps.setBetType(CrapsBetType.DONTPASS); + CrapsBetType dontPassBet = craps.getBetType(); + + Assert.assertTrue(craps.isBetWinComeOut(2, dontPassBet)); + Assert.assertTrue(craps.isBetWinComeOut(3, dontPassBet)); + + + } + @Test - public void startRoundB() throws Exception { + public void isLossOnComeRoll(){ + //given betType + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.DONTPASS); + CrapsBetType dontPass = craps.getBetType(); + + Assert.assertTrue(craps.isBetLossComeOut(7, dontPass)); + Assert.assertTrue(craps.isBetLossComeOut(11, dontPass)); + + craps.setBetType(CrapsBetType.PASSLINE); + CrapsBetType passBet = craps.getBetType(); + + Assert.assertTrue(craps.isBetLossComeOut(2, passBet)); + Assert.assertTrue(craps.isBetLossComeOut(3, passBet)); + Assert.assertTrue(craps.isBetLossComeOut(12,passBet)); + + } + @Test + public void isNeitherWinNorLossOnComeOut(){ + //given betType + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.DONTPASS); + CrapsBetType dontPass = craps.getBetType(); + + Assert.assertTrue(craps.isNoResultRoll(4, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(5, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(6, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(8, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(9, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(10, dontPass)); + Assert.assertTrue(craps.isNoResultRoll(12, dontPass)); + + craps.setBetType(CrapsBetType.PASSLINE); + CrapsBetType passBet = craps.getBetType(); + + Assert.assertTrue(craps.isNoResultRoll(4, passBet)); + Assert.assertTrue(craps.isNoResultRoll(5, passBet)); + Assert.assertTrue(craps.isNoResultRoll(6, passBet)); + Assert.assertTrue(craps.isNoResultRoll(8, passBet)); + Assert.assertTrue(craps.isNoResultRoll(9, passBet)); + Assert.assertTrue(craps.isNoResultRoll(10, passBet)); + + + } + + + + @Test + public void shouldDetermineIfPlayerWinsLosesOrSetsPointUponRoll(){ + //given betType, roll + + // when each of three diff scenarios are rolled + + // then Win/Lose/PointSet + } + + @Test + public void determineIfPlayerWinsOrLosesAfterPointHasBeenSet(){ + //given betType, roll + } + + + + @Test + public void paysOutPlayerThatHasWon(){ + + } + + @Test + public void shouldReturnTrueIfDicesAreSevenOrEleven(){ + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.PASSLINE); + CrapsBetType passBet = craps.getBetType(); + + assertEquals(true, craps.isBetWinComeOut(7, passBet)); + } + + @Test // as a craps player I would like to roll again if I my roll // doesn't win or lose - public boolean rollAgain(){ - Craps gameOn = new Craps(); - Integer = + public void rollAgainTest(){ + Craps craps = new Craps(); + Integer roll = 5; + + craps.setBetType(CrapsBetType.PASSLINE); + CrapsBetType passBet = craps.getBetType(); +// boolean flag = crapsGame.passBetLosesComeOut(roll); + boolean flag2 = craps.isBetWinComeOut(roll, passBet); - if(!gameOn.passBetWins()&& passBetLosesTest();) + // Assert.assertFalse(); } - @Test + //as a craps player would like to + + /* @Test public void passBetWinsTest() throws Exception { Craps game = new Craps(); game.setComeOut(true); @@ -46,7 +178,7 @@ public void passBetLosesTest() throws Exception { game.setComeOut(false); game.setPoint(4); Assert.assertTrue(game.passBetLoses(7)); - } + }*/ @Test public void dontPassWins() throws Exception { From cc939f101f4997546d7bed1acfef9a5e18bfbf01 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Tue, 21 Nov 2017 17:40:07 -0500 Subject: [PATCH 13/30] more craps tests --- .../io/zipcoder/casino/BlackJackPlayer.java | 4 ++ .../java/io/zipcoder/casino/CardPlayer.java | 4 +- src/main/java/io/zipcoder/casino/Console.java | 2 +- src/main/java/io/zipcoder/casino/Craps.java | 51 +++++++++++++------ .../java/io/zipcoder/casino/CrapsPlayer.java | 4 ++ src/main/java/io/zipcoder/casino/Game.java | 4 +- .../java/io/zipcoder/casino/GoFishPlayer.java | 7 ++- src/main/java/io/zipcoder/casino/Hand.java | 4 ++ .../zipcoder/casino/BlackJackPlayerTest.java | 4 +- .../io/zipcoder/casino/BlackJackTest.java | 4 +- .../io/zipcoder/casino/CrapsPlayerTest.java | 4 +- .../java/io/zipcoder/casino/CrapsTest.java | 34 ++++++++++--- .../java/io/zipcoder/casino/GameTest.java | 2 +- 13 files changed, 91 insertions(+), 37 deletions(-) create mode 100644 src/main/java/io/zipcoder/casino/Hand.java diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index c9b6a1c7..9d310f9d 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -4,6 +4,10 @@ public class BlackJackPlayer extends CardPlayer { private double bet; + public BlackJackPlayer(String name) { + super(name); + } + public void startGame(Deck deck) { if (deck == null) { throw new IllegalStateException("Deck is null"); diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index 9a0db589..f536767d 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -6,7 +6,9 @@ public class CardPlayer extends Player{ private ArrayList hand; - + public CardPlayer(String name) { + super(name); + } public ArrayList getHand() { diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 1a2c0aca..01dd1cb3 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -14,7 +14,7 @@ public void playCraps() { Craps gameOn = new Craps(); System.out.println("New shooter."); - CrapsPlayer shooter = new CrapsPlayer(); + CrapsPlayer shooter = new CrapsPlayer("panther"); gameOn.addPlayer(shooter); System.out.println("Place your bets. pass line only for the moment"); diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index 6482cef1..136333cc 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -6,10 +6,10 @@ public class Craps extends Game implements PlayForMoney { private CrapsBetType betType; private Double playerBet; private boolean isComeOut; - private Integer point=0; + private Integer point = 0; private Integer comePoint; - public void getDiceRoll(CrapsPlayer player){ + public void getDiceRoll(CrapsPlayer player) { player.roll2Dice(); } @@ -17,10 +17,15 @@ public void startPlayerTurn() { } + public void takeBet(Double betAmount) { this.playerBet = betAmount; } + public double betReceiveFromPlayers() { + return 0; + } + public Double getPlayerBet() { return playerBet; @@ -56,12 +61,11 @@ else if(gameOn.passBetWinsComeOut(roll)){ }*/ - - public void isWinner(){ + public void isWinner() { } - public void crapsRound(){ + public void crapsRound() { //take bets //roll dice @@ -88,11 +92,12 @@ public boolean passBetLoses(int roll){ }*/ - - - public boolean dontPassWins(int roll){ - if (isComeOut && (roll == 2 || roll == 3)) {return true;} - else if (!isComeOut && (roll == 7)) {return true;} + public boolean dontPassWins(int roll) { + if (isComeOut && (roll == 2 || roll == 3)) { + return true; + } else if (!isComeOut && (roll == 7)) { + return true; + } return false; //refactor to add push condition for 12 } @@ -106,7 +111,7 @@ public void placeBet(double betAmount) { this.playerBet = betAmount; } - public void rollAgain(){ + public void rollAgain() { } @@ -123,7 +128,7 @@ public void setComeOut(boolean comeOut) { isComeOut = comeOut; } - public boolean getIsComeOut(){ + public boolean getIsComeOut() { return isComeOut; } @@ -136,7 +141,7 @@ public int getPoint() { } public boolean isBetWinComeOut(int roll, CrapsBetType betType) { - if(betType == CrapsBetType.PASSLINE) + if (betType == CrapsBetType.PASSLINE) return (roll == 7 || roll == 11); if (betType == CrapsBetType.DONTPASS) return (roll == 2 || roll == 3); @@ -145,8 +150,8 @@ public boolean isBetWinComeOut(int roll, CrapsBetType betType) { } public boolean isBetLossComeOut(int roll, CrapsBetType betType) { - if(betType == CrapsBetType.PASSLINE) - return (roll == 2 || roll == 3 || roll ==12); + if (betType == CrapsBetType.PASSLINE) + return (roll == 2 || roll == 3 || roll == 12); if (betType == CrapsBetType.DONTPASS) return (roll == 7 || roll == 11); return false; @@ -159,7 +164,21 @@ public CrapsBetType getBetType() { } public boolean isNoResultRoll(int roll, CrapsBetType betType) { - return !isBetWinComeOut(roll, betType) && !isBetLossComeOut(roll,betType); + setPoint(roll); + return !isBetWinComeOut(roll, betType) && !isBetLossComeOut(roll, betType); } + + public boolean isBetWin(int roll, CrapsBetType betType) { + if (betType == CrapsBetType.PASSLINE) + return (roll == this.point); + if (betType == CrapsBetType.DONTPASS) + return (roll == 7); + return false; + } + + public boolean isBetLoss(int roll, CrapsBetType betType) { + return (!isBetWin(roll, betType)); + } } + diff --git a/src/main/java/io/zipcoder/casino/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/CrapsPlayer.java index 8a731667..e90634da 100644 --- a/src/main/java/io/zipcoder/casino/CrapsPlayer.java +++ b/src/main/java/io/zipcoder/casino/CrapsPlayer.java @@ -4,6 +4,10 @@ public class CrapsPlayer extends Player { private Bank wallet; private Integer[] currentRoll = new Integer[2]; + public CrapsPlayer(String name) { + super(name); + } + public Integer roll2Dice() { int rollOne = (int) (Math.random()*6)+1; diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index 90e682fd..c6fd43e6 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -6,12 +6,10 @@ public class Game { private int round; - private ArrayList players = new ArrayList(); - private ArrayList players = new ArrayList(); - public abstract void startPlayerTurn(); + public void startPlayerTurn(){}; public void addPlayer(Player player){ players.add(player); diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index d81747ff..4f538bd5 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -3,12 +3,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.stream.Collectors; -import java.util.stream.Stream; + public class GoFishPlayer extends CardPlayer { + public GoFishPlayer(String name) { + super(name); + } + public Card drawCard(Deck deck) { Card playerCard = deck.getCards().remove(0); return playerCard; diff --git a/src/main/java/io/zipcoder/casino/Hand.java b/src/main/java/io/zipcoder/casino/Hand.java new file mode 100644 index 00000000..628980c9 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Hand.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino; + +public class Hand { +} diff --git a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java index 11904fa1..ecd7822f 100644 --- a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java @@ -17,7 +17,7 @@ public class BlackJackPlayerTest { @Test(expected = IllegalStateException.class) public void shouldThrowIllegalStateExceptionWhenDeckIsNull() { - BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + BlackJackPlayer blackJackPlayer = new BlackJackPlayer("el pato"); Deck deck = null; blackJackPlayer.startGame(deck); Assert.assertNull(deck); @@ -26,7 +26,7 @@ public void shouldThrowIllegalStateExceptionWhenDeckIsNull() { @Test public void placeBetTest() { - BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + BlackJackPlayer blackJackPlayer = new BlackJackPlayer("el pato"); blackJackPlayer.setBet(10); double actual = 10; double expected = blackJack.betReceiveFromPlayers();// 10 diff --git a/src/test/java/io/zipcoder/casino/BlackJackTest.java b/src/test/java/io/zipcoder/casino/BlackJackTest.java index 4c964a9b..7f05ff19 100644 --- a/src/test/java/io/zipcoder/casino/BlackJackTest.java +++ b/src/test/java/io/zipcoder/casino/BlackJackTest.java @@ -11,8 +11,8 @@ public class BlackJackTest { @Test public void playersAddTest(){ - Player abrar = new Player(); - Player greg = new Player(); + Player abrar = new Player("el pato"); + Player greg = new Player("el pato"); blackJack.addPlayer(abrar); blackJack.addPlayer(greg); int expected = 2; diff --git a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java index 99d322b3..7c50bd05 100644 --- a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java @@ -7,9 +7,9 @@ public class CrapsPlayerTest { @Test - public void shouldReturnAvalueBetween2AND12WhileRollingDiceTest(){ + public void shouldReturnAValueBetween2AND12WhileRollingDiceTest(){ - CrapsPlayer shooter = new CrapsPlayer(); + CrapsPlayer shooter = new CrapsPlayer("el pato"); Integer actual = shooter.roll2Dice(); assertTrue(actual <13 && actual > 2); diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index 354a79db..3803abf8 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -14,7 +14,7 @@ public class CrapsTest { @Test public void shouldAskPlayerTypeOfBet(){ Craps craps = new Craps(); - CrapsPlayer crapsPlayer = new CrapsPlayer(); + CrapsPlayer crapsPlayer = new CrapsPlayer("el Pato"); CrapsBetType expected = CrapsBetType.PASSLINE; craps.setBetType(CrapsBetType.PASSLINE); @@ -25,7 +25,7 @@ public void shouldAskPlayerTypeOfBet(){ @Test public void shouldTakePlayerMoneyAndSetBetAmount(){ Craps craps = new Craps(); - CrapsPlayer crapsPlayer = new CrapsPlayer(); + CrapsPlayer crapsPlayer = new CrapsPlayer("el Pato"); Double expected = 50.0; craps.takeBet(expected); @@ -55,7 +55,7 @@ public void isWinOnComeRoll(){ } @Test - public void isLossOnComeRoll(){ + public void isLossOnComeOutRoll(){ //given betType Craps craps = new Craps(); craps.setBetType(CrapsBetType.DONTPASS); @@ -105,17 +105,37 @@ public void isNeitherWinNorLossOnComeOut(){ @Test - public void shouldDetermineIfPlayerWinsLosesOrSetsPointUponRoll(){ - //given betType, roll + public void TestPointSetUponNoResultComeoutRoll(){ + + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.DONTPASS); + CrapsBetType dontPass = craps.getBetType(); + + boolean flag = craps.isNoResultRoll(4, dontPass); + + Integer expected_point = 4; + Integer actual_point = craps.getPoint(); - // when each of three diff scenarios are rolled + Assert.assertEquals(expected_point,actual_point); - // then Win/Lose/PointSet } @Test public void determineIfPlayerWinsOrLosesAfterPointHasBeenSet(){ //given betType, roll + Craps craps = new Craps(); + craps.setBetType(CrapsBetType.DONTPASS); + CrapsBetType dontPass = craps.getBetType(); + + boolean flag = craps.isNoResultRoll(4, dontPass); + + Assert.assertTrue(craps.isBetWin(7, CrapsBetType.DONTPASS)); + Assert.assertTrue(craps.isBetLoss(4, CrapsBetType.DONTPASS)); + Assert.assertTrue(craps.isBetLoss(5, CrapsBetType.DONTPASS)); + Assert.assertTrue(craps.isBetLoss(6, CrapsBetType.DONTPASS)); + + Assert.assertTrue(craps.isBetLoss(7, CrapsBetType.PASSLINE)); + Assert.assertTrue(craps.isBetWin(4, CrapsBetType.PASSLINE)); } diff --git a/src/test/java/io/zipcoder/casino/GameTest.java b/src/test/java/io/zipcoder/casino/GameTest.java index 32864ddb..d94fb6cd 100644 --- a/src/test/java/io/zipcoder/casino/GameTest.java +++ b/src/test/java/io/zipcoder/casino/GameTest.java @@ -14,7 +14,7 @@ public class GameTest { @Test public void addPlayerTest() { - Player raul = new Player(); + Player raul = new Player("el pato"); game.addPlayer(raul); int expected = 1; int actual = game.getPlayers().size(); From a0564f699d31bbec38a91b1725d32415a1e2e72c Mon Sep 17 00:00:00 2001 From: amyaim Date: Thu, 23 Nov 2017 10:13:31 -0500 Subject: [PATCH 14/30] almost done with gofish:qa :w :q --- pom.xml | 18 + .../java/io/zipcoder/casino/BlackJack.java | 68 +-- src/main/java/io/zipcoder/casino/Card.java | 12 +- .../java/io/zipcoder/casino/CardGame.java | 18 + .../java/io/zipcoder/casino/CardPlayer.java | 8 +- src/main/java/io/zipcoder/casino/Casino.java | 4 + src/main/java/io/zipcoder/casino/Console.java | 208 +++++----- src/main/java/io/zipcoder/casino/Craps.java | 150 +++---- src/main/java/io/zipcoder/casino/Deck.java | 8 +- src/main/java/io/zipcoder/casino/GoFish.java | 109 ++++- .../io/zipcoder/casino/GoFishConsole.java | 58 --- .../java/io/zipcoder/casino/GoFishGame.java | 388 ++++++++++++++++++ .../java/io/zipcoder/casino/GoFishPlayer.java | 66 +-- .../java/io/zipcoder/casino/InPutConsole.java | 15 + src/main/java/io/zipcoder/casino/Main.java | 20 +- src/main/java/io/zipcoder/casino/Player.java | 6 +- src/main/java/io/zipcoder/casino/Rank.java | 31 +- .../java/io/zipcoder/casino/SampleClass.java | 7 + src/main/java/io/zipcoder/casino/Suit.java | 20 +- .../java/io/zipcoder/casino/CrapsTest.java | 118 +++--- .../java/io/zipcoder/casino/DeckTest.java | 96 ++--- .../io/zipcoder/casino/GoFishGameTest.java | 356 ++++++++++++++++ .../io/zipcoder/casino/GoFishPlayerTest.java | 8 +- .../java/io/zipcoder/casino/GoFishTest.java | 51 --- userStories | 25 +- 25 files changed, 1361 insertions(+), 507 deletions(-) delete mode 100644 src/main/java/io/zipcoder/casino/GoFishConsole.java create mode 100644 src/main/java/io/zipcoder/casino/GoFishGame.java create mode 100644 src/main/java/io/zipcoder/casino/InPutConsole.java create mode 100644 src/main/java/io/zipcoder/casino/SampleClass.java create mode 100644 src/test/java/io/zipcoder/casino/GoFishGameTest.java delete mode 100644 src/test/java/io/zipcoder/casino/GoFishTest.java diff --git a/pom.xml b/pom.xml index c6ec0cc8..6b992891 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder casino 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + @@ -15,5 +27,11 @@ 4.12 test + + org.mockito + mockito-all + 1.9.5 + test + diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index 5a775983..0580baf8 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -1,34 +1,34 @@ -package io.zipcoder.casino; - -public class BlackJack extends CardGame implements PlayForMoney { - private Bank house; - private Deck gameDeck; - - public void scoreHand() { - } - - public void addPlayers() { - } - - public void bet() { - - } - - public void bet(double betAmount) { - - } - - public void bet(BetType betType, double betAmount) { - - } - - public void placeBet(double betAmount) { - - } - - public void resolveBets() { - } - - public void dealNewHand() { - } -} +//package io.zipcoder.casino; +// +//public class BlackJack extends CardGame implements PlayForMoney { +// private Bank house; +// private Deck gameDeck; +// +// public void scoreHand() { +// } +// +// public void addPlayers() { +// } +// +// public void bet() { +// +// } +// +// public void bet(double betAmount) { +// +// } +// +// public void bet(BetType betType, double betAmount) { +// +// } +// +// public void placeBet(double betAmount) { +// +// } +// +// public void resolveBets() { +// } +// +// public void dealNewHand() { +// } +//} diff --git a/src/main/java/io/zipcoder/casino/Card.java b/src/main/java/io/zipcoder/casino/Card.java index c3ad2c59..9f242036 100644 --- a/src/main/java/io/zipcoder/casino/Card.java +++ b/src/main/java/io/zipcoder/casino/Card.java @@ -9,6 +9,9 @@ public Card(Rank rank,Suit suit){ this.rank = rank; } + + + public Rank getRank() { return rank; } @@ -16,4 +19,11 @@ public Rank getRank() { public Suit getSuit() { return suit; } -} + + @Override + public String toString() { + return rank.getSymbol() + suit.getCardSymbol(); + } + + +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/CardGame.java b/src/main/java/io/zipcoder/casino/CardGame.java index bcdd8036..b1dd2c03 100644 --- a/src/main/java/io/zipcoder/casino/CardGame.java +++ b/src/main/java/io/zipcoder/casino/CardGame.java @@ -5,9 +5,27 @@ public class CardGame extends Game { private Deck gameDeck; + CardPlayer player = new CardPlayer(); + + + public CardGame(){ + + + + } public void startPlayerTurn() { +// this. gameDeck = gameDeck; +// this.player = player; + } + public Deck getGameDeck() { + Deck deck = new Deck(); + return deck; } + +// public void setGameDeck(Deck gameDeck) { +// this.gameDeck = gameDeck; +// } } diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index 896551c0..bab99cf3 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -2,17 +2,11 @@ import java.util.ArrayList; -public class CardPlayer extends Player{ +public class CardPlayer extends Player{ private ArrayList hand; - - public ArrayList getHand() { return hand; } - - public void setHand(ArrayList hand) { - this.hand = hand; - } } diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 38cb97e0..1795ae2c 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -3,4 +3,8 @@ public class Casino { private Game[] games; + + public static void main(String[] args) { + GoFish.goFishRun(); + } } diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 53d985de..3167afdf 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -1,104 +1,104 @@ -package io.zipcoder.casino; - -import java.util.Scanner; -import java.util.WeakHashMap; - -public class Console { - - public void casinoMenu() { - - } - - public void playCraps() { - - Craps gameOn = new Craps(); - - System.out.println("New shooter."); - CrapsPlayer shooter = new CrapsPlayer(); - gameOn.addPlayer(shooter); - - System.out.println("Place your bets. pass line only for the moment"); - System.out.println("How much?"); - - double passLineBet = getDoubleInput(); - - System.out.println("Ok betting $" + passLineBet + "." ); - System.out.println("S to shoot"); - String play = getAnyKey(); - - if (play.equals("y")){ - Integer roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(true); - if(!gameOn.passBetWinsComeOut(roll) && !gameOn.passBetLosesComeOut(roll)){ - do{ - System.out.println("Roll again!"); - if(gameOn.getIsComeOut()){ - gameOn.setPoint(roll); - } - roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(false); - }while(roll != 7 && roll !=gameOn.getPoint()); - } - else if(gameOn.passBetWinsComeOut(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - - }else if(gameOn.passBetLosesComeOut(roll)) { - System.out.println("You lose."); - } - - if(gameOn.passBetWins(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - }else if(gameOn.passBetLoses(roll)){ - System.out.println("You lose."); - } - - - - - } - - - // boolean won = isWinner(bet, roll): - // boolean rollAgain = isEndRound(); - - } - - private boolean isWinner() { - return true; - } - - private BetType getBet() { - return null; - } - - public void playBlackJack() { - } - - public void playGoFish() { - } - - public String getInput(){ - Scanner scan = new Scanner(System.in); - return "y"; - } - - public String getAnyKey(){ - Scanner scan = new Scanner(System.in); - scan.hasNext(); - return "y"; - } - - public double getDoubleInput() { - Scanner scan = new Scanner(System.in); - double dblInput; - String stringInput = scan.nextLine(); - - dblInput = Double.valueOf(stringInput); - - return dblInput; - } -} - - +//package io.zipcoder.casino; +// +//import java.util.Scanner; +//import java.util.WeakHashMap; +// +//public class Console { +// +// public void casinoMenu() { +// +// } +// +// public void playCraps() { +// +// Craps gameOn = new Craps(); +// +// System.out.println("New shooter."); +// CrapsPlayer shooter = new CrapsPlayer(); +// gameOn.addPlayer(shooter); +// +// System.out.println("Place your bets. pass line only for the moment"); +// System.out.println("How much?"); +// +// double passLineBet = getDoubleInput(); +// +// System.out.println("Ok betting $" + passLineBet + "." ); +// System.out.println("S to shoot"); +// String play = getAnyKey(); +// +// if (play.equals("y")){ +// Integer roll = shooter.roll2Dice(); +// shooter.printRoll(); +// gameOn.setComeOut(true); +// if(!gameOn.passBetWinsComeOut(roll) && !gameOn.passBetLosesComeOut(roll)){ +// do{ +// System.out.println("Roll again!"); +// if(gameOn.getIsComeOut()){ +// gameOn.setPoint(roll); +// } +// roll = shooter.roll2Dice(); +// shooter.printRoll(); +// gameOn.setComeOut(false); +// }while(roll != 7 && roll !=gameOn.getPoint()); +// } +// else if(gameOn.passBetWinsComeOut(roll)){ +// System.out.println("You win! Added " + passLineBet + " to your bank."); +// +// }else if(gameOn.passBetLosesComeOut(roll)) { +// System.out.println("You lose."); +// } +// +// if(gameOn.passBetWins(roll)){ +// System.out.println("You win! Added " + passLineBet + " to your bank."); +// }else if(gameOn.passBetLoses(roll)){ +// System.out.println("You lose."); +// } +// +// +// +// +// } +// +// +// // boolean won = isWinner(bet, roll): +// // boolean rollAgain = isEndRound(); +// +// } +// +// private boolean isWinner() { +// return true; +// } +// +// private BetType getBet() { +// return null; +// } +// +// public void playBlackJack() { +// } +// +// public void playGoFish() { +// } +// +// public String getInput(){ +// Scanner scan = new Scanner(System.in); +// return "y"; +// } +// +// public String getAnyKey(){ +// Scanner scan = new Scanner(System.in); +// scan.hasNext(); +// return "y"; +// } +// +// public double getDoubleInput() { +// Scanner scan = new Scanner(System.in); +// double dblInput; +// String stringInput = scan.nextLine(); +// +// dblInput = Double.valueOf(stringInput); +// +// return dblInput; +// } +//} +// +// diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index a846b12f..23ab317b 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -1,75 +1,75 @@ -package io.zipcoder.casino; - -public class Craps extends Game implements PlayForMoney { - private Bank house; - private BetType betType; - private double betAmount; - private boolean isComeOut; - private Integer point=0; - private Integer comePoint; - - public void startRound(double betAmount){ - isComeOut = true; - - - } - - public boolean passBetWinsComeOut(int roll) { - return (roll == 7 || roll == 11); - } - - public boolean passBetLosesComeOut(int roll){ - return (roll == 2 || roll == 3 || roll == 12); - - } - - public boolean passBetWins(int roll) { - return(roll == this.point); - } - - public boolean passBetLoses(int roll){ - return (roll == 7); - } - - - - - public boolean dontPassWins(int roll){ - if (isComeOut && (roll == 2 || roll == 3)) {return true;} - else if (!isComeOut && (roll == 7)) {return true;} - return false; - //refactor to add push condition for 12 - } - - public void setBetType(BetType betType) { - this.betType = betType; - } - - public void placeBet(double betAmount) { - this.betAmount = betAmount; - } - - public void rollAgain(){ - - } - - public void resolveBets() { - - } - - public void setComeOut(boolean comeOut) { - isComeOut = comeOut; - } - - public boolean getIsComeOut(){ - return isComeOut; - } - - public void setPoint(Integer point) { - this.point = point; - } - - public int getPoint() { - return point; - } -} +//package io.zipcoder.casino; +// +//public class Craps extends Game implements PlayForMoney { +// private Bank house; +// private BetType betType; +// private double betAmount; +// private boolean isComeOut; +// private Integer point=0; +// private Integer comePoint; +// +// public void startRound(double betAmount){ +// isComeOut = true; +// +// +// } +// +// public boolean passBetWinsComeOut(int roll) { +// return (roll == 7 || roll == 11); +// } +// +// public boolean passBetLosesComeOut(int roll){ +// return (roll == 2 || roll == 3 || roll == 12); +// +// } +// +// public boolean passBetWins(int roll) { +// return(roll == this.point); +// } +// +// public boolean passBetLoses(int roll){ +// return (roll == 7); +// } +// +// +// +// +// public boolean dontPassWins(int roll){ +// if (isComeOut && (roll == 2 || roll == 3)) {return true;} +// else if (!isComeOut && (roll == 7)) {return true;} +// return false; +// //refactor to add push condition for 12 +// } +// +// public void setBetType(BetType betType) { +// this.betType = betType; +// } +// +// public void placeBet(double betAmount) { +// this.betAmount = betAmount; +// } +// +// public void rollAgain(){ +// +// } +// +// public void resolveBets() { +// +// } +// +// public void setComeOut(boolean comeOut) { +// isComeOut = comeOut; +// } +// +// public boolean getIsComeOut(){ +// return isComeOut; +// } +// +// public void setPoint(Integer point) { +// this.point = point; +// } +// +// public int getPoint() { +// return point; +// } +//} diff --git a/src/main/java/io/zipcoder/casino/Deck.java b/src/main/java/io/zipcoder/casino/Deck.java index 3fed4241..067bee98 100644 --- a/src/main/java/io/zipcoder/casino/Deck.java +++ b/src/main/java/io/zipcoder/casino/Deck.java @@ -15,7 +15,9 @@ public Deck(){ for (int i = 0; i < 4; i++) { Suit[] suitArray = new Suit[]{Suit.CLUB, Suit.DIAMOND, Suit.HEART, Suit.SPADE}; for (int j = 0; j < 13; j++) { - Rank[] rankArray = new Rank[]{Rank.ACE, Rank.TWO, Rank.THREE, Rank.FOUR, Rank.FIVE, Rank.SIX, Rank.SEVEN, Rank.EIGHT, Rank.NINE, Rank.TEN, Rank.JACK, Rank.QUEEN, Rank.KING}; + Rank[] rankArray = new Rank[]{Rank.ACE, Rank.TWO, Rank.THREE, Rank.FOUR, Rank.FIVE, + Rank.SIX, Rank.SEVEN, Rank.EIGHT, Rank.NINE, Rank.TEN, Rank.JACK, Rank.QUEEN, + Rank.KING}; Card card = new Card(rankArray[j], suitArray[i]); @@ -25,7 +27,7 @@ public Deck(){ } - public ArrayList getCards() { + public ArrayList getDeck() { return cards; } @@ -37,3 +39,5 @@ public Integer getDeckSize() { return cards.size(); } } + + diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 473079e0..69c98beb 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -1,21 +1,110 @@ package io.zipcoder.casino; -import java.util.ArrayList; +import java.util.Scanner; -public class GoFish extends CardGame { +public class GoFish extends GoFishGame { - public GoFish(){ - this.gameDeck = new Deck(); - gameDeck.shuffle(); - } - public Deck getGameDeck() { - return gameDeck; + Scanner scanner = new Scanner(System.in); + + static GoFishGame goFishGame = new GoFishGame(); + + public static void goFishRun(){ + + System.out.print("Welcome to the table!"); + + + String response = "No"; + + goFishGame.startGame(); + goFishGame.playerHand(); + goFishGame.computerHand(); + + try { + do { + + while (!goFishGame.getDeck().isEmpty()) { + //System.out.println(goFishGame.getComputerHand()); + System.out.println("Insert the rank of the card you want to request: "); + String rank = InPutConsole.getInput(); + goFishGame.checkInput(rank); + goFishGame.playerHandDisplay(); + // goFishGame.increasePlayerScoreForBook(); + goFishGame.goFishingPlayer(); + + goFishGame.checkIfComputerHandHasAcard(); + goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); + // goFishGame.checkComputerForBook(); + goFishGame.goFishingComputer(); + + // System.out.println(goFishGame.getPlayerHand()); + } + + System.out.println("The deck has finished"); + // goFishGame.increasePlayerScore(); + + // goFishGame.increaseComputerScore(); + + System.out.println("Computer score is " + goFishGame.getComputerPlayer().getScore()); + System.out.println("Your score is " + goFishGame.getGoFishPlayer().getScore()); + goFishGame.decideWiner(); + System.out.println("Do you want to play again?"); + response = InPutConsole.getInput(); + } while (response == "YES"); + } catch (Exception e) { + System.out.println("please insert YES or NO" ); } +} + + /* public void playGoFish( + + do { + + game.player1turn(); + + player1.askForCard(); + if player2hascard + getCard + player1turn; + check for pairs + checkdeckempty + else player2doesnthave card + GOFISH. player1 draws card + + player2turn(); - public Player endGameDeclareWinner(){ - return null; + player1.askForCard(); + if player2hascard + getCard + player2turn; + check for pairs + checkdeckempty + else player2doesnthave card + GOFISH. player1 draws card } + */ +// public void playerTurn(ArrayList players){ +// System.out.println(players.get(0).getName()+ " your turn."); +// +// Rank rank = getRankInput(); +// +// System.out.println(rank); +// } +// +// +// public Rank getRankInput(){ +// Scanner scan = new Scanner(System.in); +// +// do { +// String stringInput = scan.nextLine(); +// for (Rank rank : Rank.values()) { +// if (rank.toString().equalsIgnoreCase(stringInput)) { +// return rank; +// } +// } +// System.out.println("Please enter a valid card."); +// } while (true); +// } } diff --git a/src/main/java/io/zipcoder/casino/GoFishConsole.java b/src/main/java/io/zipcoder/casino/GoFishConsole.java deleted file mode 100644 index 73bb4592..00000000 --- a/src/main/java/io/zipcoder/casino/GoFishConsole.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.zipcoder.casino; - -import java.util.ArrayList; -import java.util.Scanner; - -public class GoFishConsole extends Console{ - - /* public void playGoFish( - - do { - - game.player1turn(); - - player1.askForCard(); - if player2hascard - getCard - player1turn; - check for pairs - checkdeckempty - else player2doesnthave card - GOFISH. player1 draws card - - player2turn(); - - player1.askForCard(); - if player2hascard - getCard - player2turn; - check for pairs - checkdeckempty - else player2doesnthave card - GOFISH. player1 draws card - } - */ - - public void playerTurn(ArrayList players){ - System.out.println(players.get(0).getName()+ " your turn."); - - Rank rank = getRankInput(); - - System.out.println(rank); - } - - - public Rank getRankInput(){ - Scanner scan = new Scanner(System.in); - - do { - String stringInput = scan.nextLine(); - for (Rank rank : Rank.values()) { - if (rank.toString().equalsIgnoreCase(stringInput)) { - return rank; - } - } - System.out.println("Please enter a valid card."); - } while (true); - } -} diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java new file mode 100644 index 00000000..8e326d35 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -0,0 +1,388 @@ +package io.zipcoder.casino; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class GoFishGame extends CardGame { + + private ArrayList deck; + private GoFishPlayer goFishPlayer; + private ArrayList playerHand; + private ArrayList computerHand; + private GoFishPlayer computerPlayer; + + + public GoFishGame() { + this.goFishPlayer = new GoFishPlayer(); + this.deck = new Deck().getDeck(); + Collections.shuffle(deck); + this.playerHand = new ArrayList(); + this.computerHand = new ArrayList(); + this.computerPlayer = new GoFishPlayer(); + } + + + public void startGame() { + if (goFishPlayer == null || deck == null || playerHand == null) { + throw new IllegalStateException("Player doesnt exist"); + } + } + + + public ArrayList playerHand() { + int i = 0; + while (playerHand.size() != 7) { + playerHand.add(deck.get(i)); + deck.remove(i); + i++; + } + System.out.println("Here is your hand " + playerHand.toString() + ". GoodLuck!!!"); + return playerHand; + } + + + public ArrayList computerHand() { + + int i = 0; + while (computerHand.size() != 7) { + computerHand.add(deck.get(i)); + deck.remove(i); + i++; + } + return computerHand; + } + + + public ArrayList getPlayerHand() { + return playerHand; + } + + public ArrayList getDeck() { + return deck; + } + + public GoFishPlayer getGoFishPlayer() { + return goFishPlayer; + } + + + public void setDeck(ArrayList deck) { //used for testing purpose. Delete when done. + this.deck = deck; + } + + public Boolean checkComputerHandForPlayerRequestedCard(String rank) { + Boolean checkOutcome = false; + for (int i = 0; i < getComputerHand().size(); i++) { + if (rank.equals(getComputerHand().get(i).getRank().getSymbol())) + checkOutcome = true; + } + return checkOutcome; + } + + + public void askComputerHandForACard(String rank) { + ArrayList cards = new ArrayList<>(); + if (checkComputerHandForPlayerRequestedCard(rank)) { + // System.out.println("The computer has " + rank + ". The card is being added to your hand..."); + Card card = null; + while (checkComputerHandForPlayerRequestedCard(rank)) { + for (int i = 0; i < getComputerHand().size(); i++) { + card = getComputerHand().get(i); + if (rank.equals(card.getRank().getSymbol())) cards.add(card); + } + getPlayerHand().addAll(cards); + //checkPlayerForBook(); + getComputerHand().removeAll(cards); + cards = new ArrayList<>(); + + System.out.println("The computer has " + rank +".The card" + + " is added to your hand. Insert the next card you want: "); + + rank = InPutConsole.getInput(); + + } + } + System.out.println("The computer doesnt have the card. Go Fish!!"); + } + + + public void goFishingPlayer() { + getPlayerHand().add(getDeck().get(0)); + getDeck().remove(0); + } + + + public void checkIfComputerHandHasAcard() { + getComputerHand(); + if (computerHand.size() == 0) + computerHand(); + } + + public String computerCardToRequest() { + int maxCount = 0; + int count = 0; + Card card = null; + for (int i = 0; i < getComputerHand().size() - 1; i++) { + card = getComputerHand().get(i); + for (int j = i + 1; j < getComputerHand().size() - 1; j++) { + if (card.getRank() == getComputerHand().get(j).getRank()) { + count++; + } + } + if (count > maxCount) + + maxCount = count; + card = getComputerHand().get(i); + } + return card.getRank().getSymbol(); + } + + + public Boolean checkPlayerHasRequestedCardRank(String rank) { + rank = computerCardToRequest(); + Boolean checkOutcome = false; + for (int i = 0; i < getPlayerHand().size(); i++) { + if (rank.equals(getPlayerHand().get(i).getRank().getSymbol())) + checkOutcome = true; + } + return checkOutcome; + } + + + public ArrayList askPlayerForACard(String rank) { + System.out.println("The computer requested " + rank); + if (checkPlayerHasRequestedCardRank(rank)) { + ArrayList cards = new ArrayList<>(); + Card card = null; + while (checkPlayerHasRequestedCardRank(rank)) { + for (int i = 0; i < getPlayerHand().size(); i++) { + card = getPlayerHand().get(i); + if (rank.equals(card.getRank().getSymbol())) cards.add(card); + } + getComputerHand().addAll(cards); + getPlayerHand().removeAll(cards); + // checkComputerForBook(); + cards = new ArrayList<>(); + rank = computerCardToRequest(); + checkPlayerHasRequestedCardRank(rank); + } + } + System.out.println("The player doesnt have " + rank + ". Go Fish!!"); + return getComputerHand(); + } + + public void goFishingComputer() { + getComputerHand().add(getDeck().get(0)); + getDeck().remove(0); + } + + public Map playerHandDisplay() { + // int score = player.getScore(); + + Map result = getPlayerHand() + .stream().map(card -> card.getRank().getSymbol()) + .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + + System.out.println("You have " + result); + + return result; + + } + + public void checkPlayerHandForBook() { + Map playerMap = playerHandDisplay(); + int z=0; + int count=0; + + int score = goFishPlayer.getScore(); + ArrayList cards2 = new ArrayList<>(); + ArrayList cards = getPlayerHand(); + // while (getPlayerHand().size() > 3) { + while(z< getPlayerHand().size()){ + String rank = getPlayerHand().get(z).getRank().getSymbol(); + for (Iterator it = getPlayerHand().iterator(); it.hasNext(); ){ + Card card = it.next(); + if (it.next().getRank().getSymbol().equalsIgnoreCase(rank)){ + count++; + } +// for (int i = 1; i < getPlayerHand().size(); i++) { +// int count = 0; +// Card card = getPlayerHand().get(i); +// //for (int j = 0; j < getPlayerHand().size(); j++) { +// Card card1 = cards.get(i-1); +// if ((card.getRank().getSymbol().equals(card1.getRank().getSymbol())) ) +// count++; + + if (count == 4) { + // score++; + System.out.println("You booked " + card.getRank().getSymbol()); + System.out.println("Your score is " + score); + + for (int k = 0; k < 4; k++) + cards.add(card); + } + + } + } + cards.removeAll(cards); + } + // } + + + public void checkComputerForBook() { + int score = computerPlayer.getScore(); + for (int i = 0; i < getComputerHand().size(); i++) { + int count = 0; + Card card = getComputerHand().get(i); + + for (int j = i + 1; j < getComputerHand().size(); j++) { + Card card2 = getComputerHand().get(j); + if (card.getRank().getSymbol().equals(card2.getRank().getSymbol()) && i != j) + count++; + if (count == 4) { + System.out.println("Computer booked " + card.getRank().getSymbol()); + for (int k = 0; k < 4; k++) + getComputerHand().remove(card); + score++; + System.out.println("Computer score is " + score); + } + } + } + } +// + public Boolean checkPlayersCardRequestForInputBoundary(String input) { + Boolean checkResult = true; + if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) || input.toUpperCase().equals("K") + || input.toUpperCase().equals("J") || input.toUpperCase().equals("J")) { + checkResult = true; + } else { + System.out.println("insert proper value"); + checkResult = false; + } + return checkResult; + } + + + public Boolean checkPlayersCardRequestForGameRule(String input) { + Boolean checkresult = false; + for (int i = 0; i < getPlayerHand().size(); i++) { + if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { + checkresult = true; + } + } + + return checkresult; + } + + public void checkInput(String input) { + + + while (!checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { + System.out.println("Insert proper value"); + } + askComputerHandForACard(input); + } + + + + public void increaseComputerScore() { + int computerSameRankCardCount = 0; + int computerScore = computerPlayer.getScore(); + Card card = null; + + for (int i = 0; i < getComputerHand().size() - 1; i++) { + card = getComputerHand().get(i); + for (int j = i + 1; j < getComputerHand().size() - 1; j++) + if (card.getRank() == getComputerHand().get(j).getRank()) { + computerSameRankCardCount++; + if (computerSameRankCardCount == 2) + computerScore += 1; + + } + + } + System.out.println("Computer score is " + computerScore); + + } + + // public static void main(String[] args) { + +// Scanner scanner = new Scanner(System.in); +// +// GoFishGame goFishGame = new GoFishGame(); +// String response = "No"; +// +// goFishGame.startGame(); +// goFishGame.playerHand(); +// goFishGame.computerHand(); +// +// try { +// do { +// +// while (!goFishGame.getDeck().isEmpty()) { +// //System.out.println(goFishGame.getComputerHand()); +// System.out.println("Insert the rank of the card you want to request: "); +// String rank = InPutConsole.getInput(); +// goFishGame.askComputerHandForACard(rank); +// goFishGame.playerHandDisplay(); +// goFishGame.increasePlayerScoreForBook(); +// goFishGame.goFishingPlayer(); +// goFishGame.checkIfComputerHandHasAcard(); +// goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); +// goFishGame.checkComputerForBook(); +// goFishGame.goFishingComputer(); +// +// // System.out.println(goFishGame.getPlayerHand()); +// } +// +// System.out.println("The deck has finished"); +// // goFishGame.increasePlayerScore(); +// +// // goFishGame.increaseComputerScore(); +// +// System.out.println("Computer score is " + goFishGame.computerPlayer.getScore()); +// System.out.println("Your score is " + goFishGame.goFishPlayer.getScore()); +// goFishGame.decideWiner(); +// System.out.println("Do you want to play again?"); +// response = InPutConsole.getInput(); +// } while (response == "YES"); +// } catch(Exception e) { +// System.out.println("please insert YES or NO" ); +// } +// } + + public void decideWiner() { + if (computerPlayer.getScore() > goFishPlayer.getScore()) + System.out.println("nayyy! The machine won"); + else if (computerPlayer.getScore() < goFishPlayer.getScore()) + System.out.println("Wow, you won! Congrats!!!"); + else if (computerPlayer.getScore() == goFishPlayer.getScore()) + System.out.println("The game is tie! try again"); + else + System.out.println("Sorry the score is not yet available. Please check again") ; + } + + + public void setPlayerHand(ArrayList playerHand) { + this.playerHand = playerHand; + } + + public void setComputerHand(ArrayList computerHand) { + this.computerHand = computerHand; + } + + public void setGoFishPlayer(GoFishPlayer goFishPlayer) { + this.goFishPlayer = goFishPlayer; + } + + public ArrayList getComputerHand() { + return computerHand; + } + + public GoFishPlayer getComputerPlayer() { + return computerPlayer; + } +} + + diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index 934c6e1d..707a5566 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -3,46 +3,52 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.stream.Collectors; -import java.util.stream.Stream; -public class GoFishPlayer extends CardPlayer { + public class GoFishPlayer extends CardPlayer { + - public Card drawCard(Deck deck) { - Card playerCard = deck.getCards().remove(0); - return playerCard; - } - public void addCardToHand(Card card){ - hand.add(card); - } - public ArrayList getHand() { - return hand; - } - public boolean checkHandForCard(Rank rank){ - for(Card card: hand){ - if(card.getRank() == rank) return true; - }return false; - } - public Card giveCard(Rank rank){ - for(Card card: hand){ - if(card.getRank() == rank){ - hand.remove(card); - return card; - } - } - return null; - } - public Suit checkFourOfAKind(){ - // Stream handStream = hand.stream(). +// public Card drawCard(Deck deck) { +// Card playerCard = deck.getCards().remove(0); +// return playerCard; +// } +// +// public void addCardToHand(Card card){ +// getHand().add(card); +// } + +// public ArrayList getHand() { +// return hand; +// } +// +// public boolean checkHandForCard(Rank rank){ +// for(Card card: hand){ +// if(card.getRank() == rank) return true; +// }return false; +// +// } +// +// public Card giveCard(Rank rank){ +// for(Card card: hand){ +// if(card.getRank() == rank){ +// hand.remove(card); +// return card; +// } +// } +// return null; +// } +// +// public Suit checkFourOfAKind(){ +// +// // Stream handStream = hand.stream(). /* int diamonds = 0; int spades = 0; @@ -79,4 +85,4 @@ public Suit checkFourOfAKind(){ } -} + diff --git a/src/main/java/io/zipcoder/casino/InPutConsole.java b/src/main/java/io/zipcoder/casino/InPutConsole.java new file mode 100644 index 00000000..ce40ae60 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/InPutConsole.java @@ -0,0 +1,15 @@ +package io.zipcoder.casino; + +import java.util.Scanner; + +public class InPutConsole { + + static Scanner scanner = new Scanner(System.in); + + private InPutConsole(){} + + public static String getInput(){ + + return scanner.nextLine().toUpperCase(); + } +} diff --git a/src/main/java/io/zipcoder/casino/Main.java b/src/main/java/io/zipcoder/casino/Main.java index 50221ebb..3c15ab15 100644 --- a/src/main/java/io/zipcoder/casino/Main.java +++ b/src/main/java/io/zipcoder/casino/Main.java @@ -1,10 +1,10 @@ -package io.zipcoder.casino; - -public class Main { - - public static void main(String[] args) { - - Console console = new Console(); - console.playCraps(); - } -} +//package io.zipcoder.casino; +// +//public class Main { +// +// public static void main(String[] args) { +// +// Console console = new Console(); +// console.playCraps(); +// } +//} diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index 2bc5fcbd..e0bb7a00 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -3,6 +3,7 @@ public class Player { private double bank; private String name; + private int score; public void setName(String name) { this.name = name; @@ -12,6 +13,7 @@ public String getName() { return name; } - - + public int getScore() { + return score; + } } diff --git a/src/main/java/io/zipcoder/casino/Rank.java b/src/main/java/io/zipcoder/casino/Rank.java index 2911a120..384febab 100644 --- a/src/main/java/io/zipcoder/casino/Rank.java +++ b/src/main/java/io/zipcoder/casino/Rank.java @@ -1,17 +1,44 @@ package io.zipcoder.casino; -public enum Rank {ACE(11), TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10); +public enum Rank +{ + ACE(11, "11"), + TWO(2, "2"), + THREE(3, "3"), + FOUR(4, "4"), + FIVE(5, "5"), + SIX(6, "6"), + SEVEN(7, "7"), + EIGHT(8, "8"), + NINE(9, "9"), + TEN(10, "10"), + JACK(10,"J"), + QUEEN(10, "Q"), + KING(10, "K"); private final int value; + private final String symbol; - Rank(int val) { + Rank(int val, String symbol) { this.value = val; + this.symbol = symbol; } public int getValue() { return value; } + + public String getSymbol() { + return symbol; + } + + @Override + public String toString() { + return "Rank{" + + "value=" + value + + '}'; + } } diff --git a/src/main/java/io/zipcoder/casino/SampleClass.java b/src/main/java/io/zipcoder/casino/SampleClass.java new file mode 100644 index 00000000..37d93d23 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/SampleClass.java @@ -0,0 +1,7 @@ +package io.zipcoder.casino; + +public class SampleClass { + public void myMethod() { + + } +} diff --git a/src/main/java/io/zipcoder/casino/Suit.java b/src/main/java/io/zipcoder/casino/Suit.java index e1134d60..ee078f6f 100644 --- a/src/main/java/io/zipcoder/casino/Suit.java +++ b/src/main/java/io/zipcoder/casino/Suit.java @@ -1,4 +1,20 @@ package io.zipcoder.casino; -public enum Suit {SPADE,CLUB,HEART,DIAMOND; -} +public enum Suit +{ + HEART( "♡"), + DIAMOND("♢"), + CLUB("♤"), + SPADE("♧"); + + private String cardSymbol; + + Suit( String cardSymbol) { + this.cardSymbol = cardSymbol; + } + + + public String getCardSymbol() { + return cardSymbol; + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index af823afe..32acd05d 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -1,59 +1,59 @@ -package io.zipcoder.casino; - -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class CrapsTest { - @Test - public void startRoundB() throws Exception { - } - - @Test - public void passBetWinsTest() throws Exception { - Craps game = new Craps(); - game.setComeOut(true); - Assert.assertTrue(game.passBetWinsComeOut(7)); - Assert.assertTrue(game.passBetWinsComeOut(11)); - - game.setPoint(9);; - Assert.assertTrue(game.passBetWins(9)); - - - } - - @Test - public void passBetLosesTest() throws Exception { - Craps game = new Craps(); - game.setComeOut(true); - Assert.assertTrue(game.passBetLosesComeOut(2)); - Assert.assertTrue(game.passBetLosesComeOut(3)); - Assert.assertTrue(game.passBetLosesComeOut(12)); - - game.setComeOut(false); - game.setPoint(4); - Assert.assertTrue(game.passBetLoses(7)); - } - - @Test - public void dontPassWins() throws Exception { - } - - @Test - public void setBetType() throws Exception { - } - - @Test - public void placeBet() throws Exception { - } - - @Test - public void rollAgain() throws Exception { - } - - @Test - public void resolveBets() throws Exception { - } - -} \ No newline at end of file +//package io.zipcoder.casino; +// +//import org.junit.Assert; +//import org.junit.Test; +// +//import static org.junit.Assert.*; +// +//public class CrapsTest { +// @Test +// public void startRoundB() throws Exception { +// } +// +// @Test +// public void passBetWinsTest() throws Exception { +// Craps game = new Craps(); +// game.setComeOut(true); +// Assert.assertTrue(game.passBetWinsComeOut(7)); +// Assert.assertTrue(game.passBetWinsComeOut(11)); +// +// game.setPoint(9);; +// Assert.assertTrue(game.passBetWins(9)); +// +// +// } +// +// @Test +// public void passBetLosesTest() throws Exception { +// Craps game = new Craps(); +// game.setComeOut(true); +// Assert.assertTrue(game.passBetLosesComeOut(2)); +// Assert.assertTrue(game.passBetLosesComeOut(3)); +// Assert.assertTrue(game.passBetLosesComeOut(12)); +// +// game.setComeOut(false); +// game.setPoint(4); +// Assert.assertTrue(game.passBetLoses(7)); +// } +// +// @Test +// public void dontPassWins() throws Exception { +// } +// +// @Test +// public void setBetType() throws Exception { +// } +// +// @Test +// public void placeBet() throws Exception { +// } +// +// @Test +// public void rollAgain() throws Exception { +// } +// +// @Test +// public void resolveBets() throws Exception { +// } +// +//} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/DeckTest.java b/src/test/java/io/zipcoder/casino/DeckTest.java index 82df34a3..cf1fa3dd 100644 --- a/src/test/java/io/zipcoder/casino/DeckTest.java +++ b/src/test/java/io/zipcoder/casino/DeckTest.java @@ -1,48 +1,48 @@ -package io.zipcoder.casino; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; - -import static org.junit.Assert.*; - -public class DeckTest { - - @Test - public void constructorTest(){ - Deck deck = new Deck(); - - ArrayList cards = deck.getCards(); - - String expected = "a bunch of cards"; - String actual = "***output***\n"; - - for(Card card: cards){ - actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); - } - - Assert.assertEquals(expected, actual); - } - - @Test - public void shuffleTest() throws Exception { - Deck deck = new Deck(); - deck.shuffle(); - ArrayList cards = deck.getCards(); - - String expected = "a bunch of cards"; - - String actual = "***output***\n"; - - for(Card card: cards){ - actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); - } - - Assert.assertEquals(expected, actual); - - - } - - -} \ No newline at end of file +//package io.zipcoder.casino; +// +//import org.junit.Assert; +//import org.junit.Test; +// +//import java.util.ArrayList; +// +//import static org.junit.Assert.*; +// +//public class DeckTest { +// +// @Test +// public void constructorTest(){ +// Deck deck = new Deck(); +// +// ArrayList cards = deck.getCards(); +// +// String expected = "a bunch of cards"; +// String actual = "***output***\n"; +// +// for(Card card: cards){ +// actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); +// } +// +// Assert.assertEquals(expected, actual); +// } +// +// @Test +// public void shuffleTest() throws Exception { +// Deck deck = new Deck(); +// deck.shuffle(); +// ArrayList cards = deck.getCards(); +// +// String expected = "a bunch of cards"; +// +// String actual = "***output***\n"; +// +// for(Card card: cards){ +// actual +=(card.getRank() + " of " + card.getSuit()+"s\n"); +// } +// +// Assert.assertEquals(expected, actual); +// +// +// } +// +// +//} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java new file mode 100644 index 00000000..6dee306e --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -0,0 +1,356 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Map; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +/*- + + + +-As a gofish player I would like to score a point when I have a book to lay down. + test for the number of cards of the same rank in the player hand + test I have 4 cards of the same Rank, I remove the cards from my hand + test my score incremented one point. + + +-As a gofish player I would like to see the final score when the deck is empty. + test which player has the biggest amount of points + + +*/ + +public class GoFishGameTest { + + GoFishGame goFishGame = new GoFishGame(); + + @Test + public void createGoFishGameTest() throws Exception { + + int expected = 52; + int expected2 = 7; + int actual = goFishGame.getDeck().size(); + int actual2 = goFishGame.playerHand().size(); + + Assert.assertEquals(expected, actual); + Assert.assertEquals(expected2, actual2); + Assert.assertTrue(goFishGame.player instanceof Player); + + } + + @Test(expected = IllegalStateException.class) + public void shouldThrowExceptionWhenDeckIsNullStartingGame() { + goFishGame.setDeck(null); + GoFishPlayer goFishPlayer = mock(GoFishPlayer.class); + goFishGame.startGame(); + } + @Test + + public void playerHandget7CardStartOfGame() { + int expectedBeforeMethodCall = 0; + int actualBeforeMethodCall = goFishGame.getComputerHand().size(); + goFishGame.playerHand(); + int expectedPlayerHandSize = 7; + int actualPlayerHandSize = goFishGame.getPlayerHand().size(); + Assert.assertEquals(expectedBeforeMethodCall, actualBeforeMethodCall); + Assert.assertEquals(expectedPlayerHandSize, actualPlayerHandSize); + } + @Test + + public void computerHandget7CardStartOfGame() { + int expectedBeforeMethodCall = 0; + int actualBeforeMethodCall = goFishGame.getComputerHand().size(); + + goFishGame.computerHand(); + + int expectedComputerHandSize = 7; + int actualComputerhandSize = goFishGame.getComputerHand().size(); + Assert.assertEquals(expectedBeforeMethodCall, actualBeforeMethodCall); + Assert.assertEquals(expectedComputerHandSize, actualComputerhandSize); + + } + + + @Test + public void deckSizeDecreaseAfterDeal() throws Exception { + goFishGame.getDeck(); + + int expectedBeforeDealing = 52; + int actualBeforeDealing = goFishGame.getDeck().size(); + + goFishGame.computerHand(); + goFishGame.playerHand(); + + int expectedAfterDealing = 52 - (goFishGame.getPlayerHand().size() + goFishGame.getComputerHand().size()); + int actualAfterDealing = goFishGame.getDeck().size(); + + Assert.assertEquals(expectedBeforeDealing, actualBeforeDealing); + Assert.assertEquals(expectedAfterDealing, actualAfterDealing); + } + @Test + + public void playerHandDisplayTest() { +// Card card = new Card(Rank.EIGHT, Suit.SPADE); +// Card card1 = new Card(Rank.SEVEN, Suit.CLUB); +// Card card3 = new Card(Rank.SEVEN, Suit.HEART); +// Card card2 = new Card(Rank.ACE, Suit.CLUB); +// ArrayList playerHand1 = new ArrayList<>(); +// playerHand1.add(card); +// playerHand1.add(card1); +// playerHand1.add(card2); +// playerHand1.add(card3); +// +// goFishGame.setPlayerHand(playerHand1); +// +// String expected = "You have {7=1, 8=1}"; +// +// String actual = goFishGame.playerHandDisplay().toString(); +// +// // Map playerMap = goFishGame.playerHandDisplay(); +// ArrayList cards = goFishGame.playerHand(); +// // System.out.println(playerMap.values()); +// System.out.println(cards.size()); + + // String[] rank = {"7", "8","9", "10", "J"}; + + // for (int i = 0; i < goFishGame.getPlayerHand().size()-1; i++) { + // String rank = goFishGame.getComputerHand().get(i).getRank().getSymbol(); + // for (Iterator iter = cards.iterator(); iter.hasNext(); ){ + // Rank rank = iter.next().getRank(); + // for(int i =0; i cards = goFishGame.playerHand(); + while(z it = cards.iterator(); it.hasNext(); ) { + + if (it.next().getRank().getSymbol().equalsIgnoreCase(rank)) { + count++; + if (count == 3) + score++; + it.remove(); + + } + } + z++; + } + System.out.println("count is " + count); + System.out.println("score is " + score); + + System.out.println(cards); + + + } + + + @Test + public void passingCardFromPlayerToComputerTest() { + + Card card = new Card(Rank.EIGHT, Suit.SPADE); + Card card1 = new Card(Rank.SEVEN, Suit.CLUB); + Card card2 = new Card(Rank.ACE, Suit.CLUB); + ArrayList computerHand1 = new ArrayList<>(); + computerHand1.add(card); + computerHand1.add(card1); + goFishGame.setComputerHand(computerHand1); + Boolean expected = true; + Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("7"); + Boolean expected2 = false; + Boolean actual2 = goFishGame.checkPlayerHasRequestedCardRank("6"); + Assert.assertEquals(expected, actual); + Assert.assertEquals(expected2, actual2); + } + + @Test + + public void checkComputerHandForPlayerRequestedCardRank() { + goFishGame.playerHand(); + Card card0 = new Card(Rank.SIX, Suit.SPADE); + Card card = new Card(Rank.SEVEN, Suit.SPADE); + Card card1 = new Card(Rank.SEVEN, Suit.CLUB); + + ArrayList computerHand1 = new ArrayList<>(); + computerHand1.add(card0); + computerHand1.add(card); + computerHand1.add(card1); + + goFishGame.setComputerHand(computerHand1); + + Boolean expected = true; + Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("7"); + + Assert.assertEquals(expected, actual); + } + + /* @Test + public void checkPlayerCanTakeCardFromComputerTest() { // tested by viewing the console and passed the test. + goFishGame.getDeck(); + goFishGame.playerHand(); + Card card0 = new Card(Rank.SIX, Suit.SPADE); + Card card = new Card(Rank.SEVEN, Suit.SPADE); + + + ArrayList computerHand1 = new ArrayList<>(); + computerHand1.add(card0); + computerHand1.add(card); + + + goFishGame.setComputerHand(computerHand1); + + String expected = " The computer has 7\nYour hand is [5♧, 10♤, 9♧, 3♧, 6♢, 9♢, J♧, 7♧]\n" + + "Insert the next card you want: "; + + goFishGame.askComputerHandForACard("7"); + }*/ + + + @Test + + public void computerDecisionForCardTest() { + Card card0 = new Card(Rank.SIX, Suit.SPADE); + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card2 = new Card(Rank.SEVEN, Suit.SPADE); + Card card3 = new Card(Rank.SEVEN, Suit.HEART); + Card card4 = new Card(Rank.SEVEN, Suit.SPADE); + + ArrayList computerHand1 = new ArrayList<>(); + computerHand1.add(card0); + computerHand1.add(card1); + computerHand1.add(card2); + computerHand1.add(card3); + computerHand1.add(card4); + goFishGame.setComputerHand(computerHand1); + + String expected = "7"; + + String actual = goFishGame.computerCardToRequest(); + + Assert.assertEquals(expected, actual); + + } + + @Test + + public void checkPlayersCardRequestForInputBoundary() { + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card = new Card(Rank.SEVEN, Suit.DIAMOND); + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card); + + goFishGame.setPlayerHand(playerHand1); + Boolean expected = true; + Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); + Assert.assertEquals(expected, actual); + Boolean expected2 = false; + Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); + Assert.assertEquals(expected2, actual2); + } + + @Test + public void checkPlayersCardRequestForGameRuleTest(){ + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card = new Card(Rank.SEVEN, Suit.DIAMOND); + + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card); + + goFishGame.setPlayerHand(playerHand1); + + Boolean expected = false; + Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); + Assert.assertEquals(expected, actual); + + Boolean expected2 = true; + Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); + Assert.assertEquals(expected2, actual2); + } + + @Test + + public void goFishingPlayerTest(){ + ArrayList deck = goFishGame.getDeck(); + goFishGame.getPlayerHand(); + + Card card = deck.get(0); + int expectSizeOfHandIncreaseBy1AfterGoFish = goFishGame.getPlayerHand().size() +1; + Boolean expectedDeckTopCardToBeAvailable = true; + Boolean actualDeckTopcardAvaialble = deck.contains(card); + + goFishGame.goFishingPlayer(); + + int actualSizeOfPlayerHandIncreaseAfterGoFish = goFishGame.getPlayerHand().size(); + Boolean expectedDeckTopCardNotToBeAvailable= false; + Boolean actualDeckTopCardNotToBeAvailable = deck.contains(card); + Assert.assertEquals(expectedDeckTopCardNotToBeAvailable, actualDeckTopCardNotToBeAvailable); + Assert.assertEquals(expectedDeckTopCardToBeAvailable, actualDeckTopcardAvaialble); + Assert.assertEquals(expectSizeOfHandIncreaseBy1AfterGoFish, actualSizeOfPlayerHandIncreaseAfterGoFish); + } + @Test + + public void goFishingComputerTest(){ + ArrayList deck = goFishGame.getDeck(); + goFishGame.getComputerHand(); + + Card card = deck.get(0); + int expectSizeOfComouterHandIncreaseBy1AfterGoFish = goFishGame.getComputerHand().size() +1; + Boolean expectedDeckTopCardToBeAvailable = true; + Boolean actualDeckTopcardAvaialble = deck.contains(card); + + goFishGame.goFishingComputer(); + + int actualSizeOfComputerHandIncreaseAfterGoFish = goFishGame.getComputerHand().size(); + Boolean expectedDeckTopCardNotToBeAvailable= false; + Boolean actualDeckTopCardNotToBeAvailable = deck.contains(card); + Assert.assertEquals(expectedDeckTopCardNotToBeAvailable, actualDeckTopCardNotToBeAvailable); + Assert.assertEquals(expectedDeckTopCardToBeAvailable, actualDeckTopcardAvaialble); + Assert.assertEquals(expectSizeOfComouterHandIncreaseBy1AfterGoFish, actualSizeOfComputerHandIncreaseAfterGoFish); + + } + + @Test + + public void playerHandBookTest(){ + Card card1 = new Card(Rank.SIX, Suit.CLUB); + Card card2 = new Card(Rank.SEVEN, Suit.HEART); + Card card3 = new Card(Rank.SIX, Suit.DIAMOND); + Card card4 = new Card(Rank.EIGHT, Suit.HEART); + Card card5 = new Card(Rank.SIX, Suit.SPADE); + Card card6 = new Card(Rank.SEVEN, Suit.CLUB); + Card card7 = new Card(Rank.SIX, Suit.HEART); + Card card8 = new Card(Rank.FIVE, Suit.SPADE); + + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + playerHand1.add(card4); + playerHand1.add(card5); + playerHand1.add(card6); + playerHand1.add(card7); + playerHand1.add(card8); + + + goFishGame.setPlayerHand(playerHand1); + + // goFishGame.checkPlayerHandForBook(); + System.out.println(playerHand1.size()); + System.out.println(playerHand1.get(0)); + + + + + } + + + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java index 677c6b8c..ccd1848f 100644 --- a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java @@ -11,7 +11,7 @@ //public class GoFishPlayerTest { // @Test // public void checkHandForCard() throws Exception { -// GoFish gameOn = new GoFish(); +// GoFishGame gameOn = new GoFishGame(); // GoFishPlayer player1 = new GoFishPlayer(); // // String expected = ""; @@ -30,7 +30,7 @@ // // @Test // public void giveCard() throws Exception { -// GoFish gameOn = new GoFish(); +// GoFishGame gameOn = new GoFishGame(); // GoFishPlayer player1 = new GoFishPlayer(); // // String expected = ""; @@ -51,7 +51,7 @@ // // @Test // public void drawCard() throws Exception { -// GoFish gameOn = new GoFish(); +// GoFishGame gameOn = new GoFishGame(); // GoFishPlayer player1 = new GoFishPlayer(); // // gameOn.addPlayer(player1); @@ -81,7 +81,7 @@ // @Test // public void drawFiveCardsTest(){ // GoFishPlayer somePlayer = new GoFishPlayer(); -// GoFish gameOn = new GoFish(); +// GoFishGame gameOn = new GoFishGame(); // // somePlayer.drawFiveCards(gameOn.getGameDeck()); // diff --git a/src/test/java/io/zipcoder/casino/GoFishTest.java b/src/test/java/io/zipcoder/casino/GoFishTest.java deleted file mode 100644 index 3b1a80f1..00000000 --- a/src/test/java/io/zipcoder/casino/GoFishTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.zipcoder.casino; - -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class GoFishTest { - @Test - public void createGoFishGameTest() throws Exception { - - ; - - } -// -// @Test -// public void checkForPairsTest() throws Exception{ -// GoFish gameOn = new GoFish(); -// -// GoFishPlayer player1 = new GoFishPlayer(); -// -// Card someSeven = new Card(Rank.SEVEN, Suit.CLUB); -// Card anotherSeven = new Card(Rank.SIX, Suit.HEART); -// -// player1.addCardToHand(someSeven); -// player1.addCardToHand(anotherSeven); -// player1.addCardToHand(new Card(Rank.FIVE, Suit.HEART)); -// player1.addCardToHand(new Card(Rank.FOUR, Suit.HEART)); -// player1.addCardToHand(new Card(Rank.THREE, Suit.HEART)); -// // player1.drawCard(gameOn.getGameDeck()); -// // player1.drawCard(gameOn.getGameDeck()); -// -// Assert.assertTrue(gameOn.hasPair(player1)); -// -// } -// -// @Test -// public void endGameDeclareWinner() throws Exception { -// GoFish gameOn = new GoFish(); -// GoFishPlayer player1 = new GoFishPlayer(); -// GoFishPlayer player2 = new GoFishPlayer(); -// -// gameOn.addPlayer(player1); -// gameOn.addPlayer(player2); -// -// player1.drawFiveCards(gameOn.getGameDeck()); -// player2.drawFiveCards(gameOn.getGameDeck()); -// -// } - -} \ No newline at end of file diff --git a/userStories b/userStories index 8665f683..4b907ef9 100644 --- a/userStories +++ b/userStories @@ -46,7 +46,7 @@ test the highest score less than 22 win the game (Blackjack) --As a gofish player I would like to start a game. +-As a gofish game customer I would like the game to start with a player, computer player and a deck test can create a game (GoFish) test can add a players to the game (GoFish) @@ -54,13 +54,24 @@ test existace of a hand (GoFish, GoFishPlayer) -As a gofish I would like to draw 7 cards (GoFish) - test that the first 7 cards from the deck are in my hand + test that the player gets 7 cards from the deck at the start of the game test that these cards are removed from the deck + test the layer is able to see the card --As a gofish player I would like to ask my opponent for a particular card. - test boolean on the other player whether or not has the card asked + -As a gofish I would like the computer to draw 7 cards and save it without displaying (GoFish) + test that the computer player gets 7 cards from the deck at the start of the game + test that these cards are removed from the deck + - As a gofish player I would like to be able to see my card + test console displayes players card + +-As a gofish player I would like to ask the computer for a particular card +and the compuetr should given me all cards at the hand of that type. + test compuetr pass the requested card and is removed from the computer hand + -As a go fish player, I want the computer to make smart decision, i.e. ask for the card that it has most. + -test the computer ask for the most frequent rank in its hand. -As a gofish player I would like to score a point when I have a book to lay down. + test for the number of cards of the same rank in the player hand test I have 4 cards of the same Rank, I remove the cards from my hand test my score incremented one point. @@ -72,10 +83,8 @@ -As a gofish player I would like to see the final score when the deck is empty. test which player has the biggest amount of points --As a gofish bot. I would like to ask for the card that I have the most of - (or that that has been asked of me). - test the goFish bot request a card of rank that it's on its hand --As a gofish programmer I would like a display method for my bot, for testing purposes only. + + -As a craps player I would like to start the game. From 9c76dc6f41d8b9c4f9991b3d45a8ea2337f3afed Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sat, 25 Nov 2017 16:38:07 -0500 Subject: [PATCH 15/30] craps are rolling --- .../java/io/zipcoder/casino/BlackJack.java | 8 + .../io/zipcoder/casino/BlackJackPlayer.java | 8 +- src/main/java/io/zipcoder/casino/Console.java | 101 ------------ src/main/java/io/zipcoder/casino/Craps.java | 153 +++++------------- .../java/io/zipcoder/casino/CrapsConsole.java | 151 +++++++++++++++++ .../java/io/zipcoder/casino/CrapsPlayer.java | 36 ++++- src/main/java/io/zipcoder/casino/Main.java | 5 +- .../java/io/zipcoder/casino/PlayForMoney.java | 7 +- .../io/zipcoder/casino/CrapsPlayerTest.java | 21 +++ .../java/io/zipcoder/casino/CrapsTest.java | 30 ++++ 10 files changed, 296 insertions(+), 224 deletions(-) create mode 100644 src/main/java/io/zipcoder/casino/CrapsConsole.java diff --git a/src/main/java/io/zipcoder/casino/BlackJack.java b/src/main/java/io/zipcoder/casino/BlackJack.java index dd2acd22..d74ad99d 100644 --- a/src/main/java/io/zipcoder/casino/BlackJack.java +++ b/src/main/java/io/zipcoder/casino/BlackJack.java @@ -51,4 +51,12 @@ public void hand(Card card1, Card card2) { public void scoreHand() { } + + public double makeBet(Double amount) { + return 0; + } + + public double collectWinnings(boolean isWin) { + return 0; + } } diff --git a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java index 9d310f9d..9a7fd6e7 100644 --- a/src/main/java/io/zipcoder/casino/BlackJackPlayer.java +++ b/src/main/java/io/zipcoder/casino/BlackJackPlayer.java @@ -1,6 +1,6 @@ package io.zipcoder.casino; -public class BlackJackPlayer extends CardPlayer { +public class BlackJackPlayer extends CardPlayer implements PlayForMoney { private double bet; @@ -39,5 +39,11 @@ public boolean stay() { } + public double makeBet(Double amount) { + return 0; + } + public double collectWinnings(boolean isWin) { + return 0; + } } diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 01dd1cb3..a0b54e53 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -9,107 +9,6 @@ public void casinoMenu() { } - public void playCraps() { - - Craps gameOn = new Craps(); - - System.out.println("New shooter."); - CrapsPlayer shooter = new CrapsPlayer("panther"); - gameOn.addPlayer(shooter); - - System.out.println("Place your bets. pass line only for the moment"); - System.out.println("How much?"); - - double passLineBet = getDoubleInput(); - - System.out.println("Ok betting $" + passLineBet + "." ); - System.out.println("S to shoot"); - String play = getAnyKey(); - - /* if(playerWantsToPlay(promptPlayer())){ - Integer roll = shooter.roll2Dice(); - showResultsOfRoll(shooter) - gameOn.setComeOut(true); - if(comeOutRollIsNeitherWinNorLose(roll)){ - - } - } - if (play.equals("y")){ - Integer roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(true); - if(!gameOn.passBetWinsComeOut(roll) && !gameOn.passBetLosesComeOut(roll)){ - do{ - System.out.println("Roll again!"); - if(gameOn.getIsComeOut()){ - gameOn.setPoint(roll); - } - roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(false); - }while(roll != 7 && roll !=gameOn.getPoint()); - } - else if(gameOn.passBetWinsComeOut(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - - }else if(gameOn.passBetLosesComeOut(roll)) { - System.out.println("You lose."); - } - - if(gameOn.passBetWins(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - }else if(gameOn.passBetLoses(roll)){ - System.out.println("You lose."); - } - - - - - }*/ - - - // boolean won = isWinner(bet, roll): - // boolean rollAgain = isEndRound(); - - } - - private boolean isWinner() { - return true; - } - - - public void playBlackJack() { - } - - public void playGoFish() { - } - - public String getInput(){ - Scanner scan = new Scanner(System.in); - return "y"; - } - - public String getAnyKey(){ - Scanner scan = new Scanner(System.in); - scan.hasNext(); - return "y"; - } - - public double getDoubleInput() { - Scanner scan = new Scanner(System.in); - double dblInput; - String stringInput = scan.nextLine(); - - dblInput = Double.valueOf(stringInput); - - return dblInput; - } - -/* - comeOutRollIsNeitherWinNorLose(int roll){ - return game.comeOutPassBet(roll) && gemae.comeOutPassLoss(roll) - //// - }*/ } diff --git a/src/main/java/io/zipcoder/casino/Craps.java b/src/main/java/io/zipcoder/casino/Craps.java index 136333cc..277de4c2 100644 --- a/src/main/java/io/zipcoder/casino/Craps.java +++ b/src/main/java/io/zipcoder/casino/Craps.java @@ -1,135 +1,48 @@ package io.zipcoder.casino; +import static io.zipcoder.casino.CrapsConsole.getBooleanInput; + public class Craps extends Game implements PlayForMoney { private Bank house; private CrapsBetType betType; private Double playerBet; - private boolean isComeOut; private Integer point = 0; - private Integer comePoint; - - public void getDiceRoll(CrapsPlayer player) { - player.roll2Dice(); - } public void startPlayerTurn() { - - } public void takeBet(Double betAmount) { this.playerBet = betAmount; } - - public double betReceiveFromPlayers() { - return 0; - } - + public Double getPlayerBet() { return playerBet; } - /* - if (play.equals("y")){ - Integer roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(true); - if(!gameOn.passBetWinsComeOut(roll) && !gameOn.passBetLosesComeOut(roll)){ - do{ - System.out.println("Roll again!"); - if(gameOn.getIsComeOut()){ - gameOn.setPoint(roll); - } - roll = shooter.roll2Dice(); - shooter.printRoll(); - gameOn.setComeOut(false); - }while(roll != 7 && roll !=gameOn.getPoint()); - } - else if(gameOn.passBetWinsComeOut(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - - }else if(gameOn.passBetLosesComeOut(roll)) { - System.out.println("You lose."); - } - - if(gameOn.passBetWins(roll)){ - System.out.println("You win! Added " + passLineBet + " to your bank."); - }else if(gameOn.passBetLoses(roll)){ - System.out.println("You lose."); - }*/ - - - public void isWinner() { - - } - - public void crapsRound() { - //take bets - - //roll dice - - //determine winner loop if none. - - } - - - - /* - - public boolean passBetLosesComeOut(int roll){ - return (roll == 2 || roll == 3 || roll == 12); - - } - - public boolean passBetWins(int roll) { - return(roll == this.point); - } - - public boolean passBetLoses(int roll){ - return (roll == 7); - }*/ - - - public boolean dontPassWins(int roll) { - if (isComeOut && (roll == 2 || roll == 3)) { - return true; - } else if (!isComeOut && (roll == 7)) { - return true; - } - return false; - //refactor to add push condition for 12 + public void setPlayerBet(Double playerBet) { + this.playerBet = playerBet; } - public void setBetType(CrapsBetType betType) { this.betType = betType; } + - public void placeBet(double betAmount) { - this.playerBet = betAmount; - } - - public void rollAgain() { - - } - - - public void takeBet(double betAmount) { - - } - - public void resolveBets() { - - } - - public void setComeOut(boolean comeOut) { - isComeOut = comeOut; - } - - public boolean getIsComeOut() { - return isComeOut; + public double resolveBet(CrapsPlayer crapsPlayer, boolean isWin) { + Double newWalletTotal; + if(isWin){ + Double walletAmount = crapsPlayer.getWallet(); + newWalletTotal = walletAmount + this.getPlayerBet(); + crapsPlayer.setWallet(newWalletTotal); + return newWalletTotal; + }else{ + Double walletAmount = crapsPlayer.getWallet(); + newWalletTotal = walletAmount - this.getPlayerBet(); + crapsPlayer.setWallet(newWalletTotal); + return newWalletTotal; + } } public void setPoint(Integer point) { @@ -158,7 +71,6 @@ public boolean isBetLossComeOut(int roll, CrapsBetType betType) { } - public CrapsBetType getBetType() { return betType; } @@ -166,7 +78,6 @@ public CrapsBetType getBetType() { public boolean isNoResultRoll(int roll, CrapsBetType betType) { setPoint(roll); return !isBetWinComeOut(roll, betType) && !isBetLossComeOut(roll, betType); - } public boolean isBetWin(int roll, CrapsBetType betType) { @@ -178,7 +89,31 @@ public boolean isBetWin(int roll, CrapsBetType betType) { } public boolean isBetLoss(int roll, CrapsBetType betType) { - return (!isBetWin(roll, betType)); + if(betType == CrapsBetType.PASSLINE) + return(roll==7); + if(betType == CrapsBetType.DONTPASS) + return(roll == this.point); + return (false); + } + + public double makeBet(Double amount) { + return 0; + } + + public double collectWinnings(boolean isWin) { + return 0; + } + + public void playerWins(CrapsPlayer crapsPlayer) { + System.out.println("You win!"); + Double newBalance = resolveBet(crapsPlayer, true); + System.out.println("Your new balance is " + newBalance + "!"); + } + + public void playerLoses(CrapsPlayer crapsPlayer) { + System.out.println("You lose:("); + Double newBalance = resolveBet(crapsPlayer, false); + System.out.println("Your new balance is " + newBalance + "."); } } diff --git a/src/main/java/io/zipcoder/casino/CrapsConsole.java b/src/main/java/io/zipcoder/casino/CrapsConsole.java new file mode 100644 index 00000000..f1b3a72d --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CrapsConsole.java @@ -0,0 +1,151 @@ +package io.zipcoder.casino; + +import java.util.Scanner; + +public class CrapsConsole { + + + public void playCraps(){ + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer(); + + askIfPlayerWantsToPlay(); + boolean playGame = getBooleanInput(); + + while(playGame){ + + promptPlayerForBetType(); + craps.setBetType(getBetTypeInput()); + + promptPlayerForBet(); + craps.setPlayerBet(getEnforcedPositiveDoubleInput()); + + promptPlayerForRoll(); + Integer roll = getRoll(crapsPlayer); + crapsPlayer.printRoll(); + + rollComeout(craps, crapsPlayer, roll); + + playGame = askPlayAgain(); + } + + } + + + private void rollPointRound(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { + + craps.setPoint(roll); + System.out.println("Point is set at " + roll); + + while(true){ + promptPlayerForRoll(); + roll = getRoll(crapsPlayer); + crapsPlayer.printRoll(); + if(craps.isBetWin(roll, craps.getBetType())){ + craps.playerWins(crapsPlayer); + return; + }else if(craps.isBetLoss(roll, craps.getBetType())){ + craps.playerLoses(crapsPlayer); + return; + } + } + } + + private void rollComeout(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { + if(craps.isBetWinComeOut(roll, craps.getBetType())){ + craps.playerWins(crapsPlayer); + }else if (craps.isBetLossComeOut(roll, craps.getBetType())){ + craps.playerLoses(crapsPlayer); + }else { + rollPointRound(craps, crapsPlayer,roll); + } + } + + + private Integer getRoll(CrapsPlayer crapsPlayer) { + getUserInput(); + return crapsPlayer.roll2Dice(); + } + + private void promptPlayerForRoll() { + System.out.println("Ready? Enter to roll"); + } + + private void promptPlayerForBet() { + System.out.println("How much do you want to bet?"); + + } + + private static CrapsBetType getBetTypeInput() { + Scanner scan = new Scanner(System.in); + String input = scan.next(); + + while(true){ + + if(input.equalsIgnoreCase("pass")){ + return CrapsBetType.PASSLINE; + }else if(input.equalsIgnoreCase("dont")){ + return CrapsBetType.DONTPASS; + } + } + } + + private static void promptPlayerForBetType() { + System.out.println("Enter 'pass' to bet the passline\nEnter 'dont'" + + " to bet against the passline."); + } + + private static void askIfPlayerWantsToPlay() { + System.out.println("Ready to play some craps? Win big and make a bunch of friends along the way!\n" + + "Feeling lucky...? 'y' or 'n'" ); + + } + + public static boolean getBooleanInput() { + Scanner scan = new Scanner(System.in); + String input = scan.next(); + + if(input.equalsIgnoreCase("y")){ + return true; + }else{ + return false; + } + } + + public static String getUserInput() { + Scanner scanner = new Scanner(System.in); + String input = scanner.nextLine(); + return input; + } + + public static double getEnforcedPositiveDoubleInput(){ + Scanner in = new Scanner(System.in); + double dInput; + String sInput; + do { + sInput = in.nextLine(); + if (!isInputDouble(sInput)||(Double.valueOf(sInput)<0)) { + System.out.println("Please enter a decimal number greater than 0."); + } + }while (!isInputDouble(sInput)||(Double.valueOf(sInput)<0)); + dInput=Double.valueOf(sInput); + return dInput; + } + + private static boolean isInputDouble(String passedString) + { + try { + Double output = Double.valueOf(passedString); + } catch (NumberFormatException e) { + return false; + } + return (true); + } + + private boolean askPlayAgain() { + System.out.println("Play again?"); + return getBooleanInput(); + } + + +} diff --git a/src/main/java/io/zipcoder/casino/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/CrapsPlayer.java index e90634da..3ad674e1 100644 --- a/src/main/java/io/zipcoder/casino/CrapsPlayer.java +++ b/src/main/java/io/zipcoder/casino/CrapsPlayer.java @@ -1,11 +1,16 @@ package io.zipcoder.casino; -public class CrapsPlayer extends Player { - private Bank wallet; +public class CrapsPlayer extends Player implements PlayForMoney { + private double walletAmount; private Integer[] currentRoll = new Integer[2]; + public CrapsPlayer(){ + super("A player has no name"); + this.walletAmount = 10000.0; + } public CrapsPlayer(String name) { super(name); + this.walletAmount = 10000.0; } public Integer roll2Dice() { @@ -25,11 +30,30 @@ public void printRoll(){ - public Bank getWallet() { - return wallet; + public double getWallet() { + return walletAmount; + } + + public void setWallet(double amount) { + this.walletAmount = amount; + } + + public double makeBet(Double amount) { + return 0; + } + + public double collectWinnings(boolean isWin) { + return 0; + } + + public double collectWinnings(boolean isWin, Craps craps) { + return 0; } - public void setWallet(Bank wallet) { - this.wallet = wallet; + public void makeBet(Double amount, Craps craps) { + craps.setPlayerBet(amount); + + } + } diff --git a/src/main/java/io/zipcoder/casino/Main.java b/src/main/java/io/zipcoder/casino/Main.java index 50221ebb..610d1da5 100644 --- a/src/main/java/io/zipcoder/casino/Main.java +++ b/src/main/java/io/zipcoder/casino/Main.java @@ -4,7 +4,8 @@ public class Main { public static void main(String[] args) { - Console console = new Console(); - console.playCraps(); + + CrapsConsole crapsConsole = new CrapsConsole(); + crapsConsole.playCraps(); } } diff --git a/src/main/java/io/zipcoder/casino/PlayForMoney.java b/src/main/java/io/zipcoder/casino/PlayForMoney.java index 3330bd7a..1d0b3ecb 100644 --- a/src/main/java/io/zipcoder/casino/PlayForMoney.java +++ b/src/main/java/io/zipcoder/casino/PlayForMoney.java @@ -1,11 +1,8 @@ package io.zipcoder.casino; public interface PlayForMoney { - void takeBet(Double betAmount ); + double makeBet(Double amount); - - double betReceiveFromPlayers(); - - void resolveBets(); + double collectWinnings(boolean isWin); } diff --git a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java index 7c50bd05..b5617fc6 100644 --- a/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsPlayerTest.java @@ -1,5 +1,6 @@ package io.zipcoder.casino; +import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.assertTrue; @@ -15,6 +16,26 @@ public void shouldReturnAValueBetween2AND12WhileRollingDiceTest(){ assertTrue(actual <13 && actual > 2); } + @Test + public void shouldIncreasePlayerWalletByBetWhenIsWin(){ + //given + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer("el pato"); + crapsPlayer.setWallet(500.0); + //when + crapsPlayer.makeBet(100.0); + boolean wins = craps.isBetWinComeOut(7, CrapsBetType.PASSLINE); + + craps.resolveBet(crapsPlayer, false); + crapsPlayer.collectWinnings(wins, craps); + + Double expected = 600.0; + Double actual = crapsPlayer.getWallet(); + + Assert.assertEquals(expected,actual); + + } + } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index 3803abf8..92474802 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -142,6 +142,36 @@ public void determineIfPlayerWinsOrLosesAfterPointHasBeenSet(){ @Test public void paysOutPlayerThatHasWon(){ + //given + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer("el pato"); + crapsPlayer.setWallet(500.0); + //when + crapsPlayer.makeBet(100.0, craps); + boolean wins = craps.isBetWinComeOut(7, CrapsBetType.PASSLINE); + + //then + double expected = 600; + double actual = craps.resolveBet(crapsPlayer, true); + + Assert.assertTrue(expected ==actual); + + } + + @Test + public void takeMoneyFromPlayerThatHasLost(){ + //given + Craps craps = new Craps(); + CrapsPlayer crapsPlayer = new CrapsPlayer("el pato"); + crapsPlayer.setWallet(500.0); + //when + crapsPlayer.makeBet(100.0, craps); + boolean flag = craps.isBetWinComeOut(7, CrapsBetType.PASSLINE); + double expected = 600; + double actual = craps.resolveBet(crapsPlayer,flag); + + //then + Assert.assertTrue(expected ==actual); } From 454c9fe19bd18da516e8685fdb0703676c53e870 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sat, 25 Nov 2017 17:12:42 -0500 Subject: [PATCH 16/30] handled some input errs --- .../java/io/zipcoder/casino/CrapsConsole.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/CrapsConsole.java b/src/main/java/io/zipcoder/casino/CrapsConsole.java index f1b3a72d..00b916ad 100644 --- a/src/main/java/io/zipcoder/casino/CrapsConsole.java +++ b/src/main/java/io/zipcoder/casino/CrapsConsole.java @@ -21,7 +21,7 @@ public void playCraps(){ craps.setPlayerBet(getEnforcedPositiveDoubleInput()); promptPlayerForRoll(); - Integer roll = getRoll(crapsPlayer); + Integer roll = crapsPlayer.roll2Dice(); crapsPlayer.printRoll(); rollComeout(craps, crapsPlayer, roll); @@ -39,7 +39,8 @@ private void rollPointRound(Craps craps, CrapsPlayer crapsPlayer, Integer roll) while(true){ promptPlayerForRoll(); - roll = getRoll(crapsPlayer); + roll = crapsPlayer.roll2Dice(); + crapsPlayer.printRoll(); if(craps.isBetWin(roll, craps.getBetType())){ craps.playerWins(crapsPlayer); @@ -62,13 +63,9 @@ private void rollComeout(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { } - private Integer getRoll(CrapsPlayer crapsPlayer) { - getUserInput(); - return crapsPlayer.roll2Dice(); - } - private void promptPlayerForRoll() { System.out.println("Ready? Enter to roll"); + getUserInput(); } private void promptPlayerForBet() { @@ -78,16 +75,22 @@ private void promptPlayerForBet() { private static CrapsBetType getBetTypeInput() { Scanner scan = new Scanner(System.in); - String input = scan.next(); - - while(true){ + String input; + do{ + input = scan.next(); + if(!input.equalsIgnoreCase("pass")&&!input.equalsIgnoreCase("dont")){ + System.out.println("Please enter 'pass' or 'dont.'"); + } + }while(!input.equalsIgnoreCase("pass")&&!input.equalsIgnoreCase("dont")); if(input.equalsIgnoreCase("pass")){ return CrapsBetType.PASSLINE; }else if(input.equalsIgnoreCase("dont")){ return CrapsBetType.DONTPASS; - } } + + + return null; } private static void promptPlayerForBetType() { @@ -96,20 +99,21 @@ private static void promptPlayerForBetType() { } private static void askIfPlayerWantsToPlay() { - System.out.println("Ready to play some craps? Win big and make a bunch of friends along the way!\n" + + System.out.println("Ready to play some craps? Win big with small dice!\n" + "Feeling lucky...? 'y' or 'n'" ); } public static boolean getBooleanInput() { Scanner scan = new Scanner(System.in); - String input = scan.next(); - - if(input.equalsIgnoreCase("y")){ - return true; - }else{ - return false; - } + String input; + do{ + input = scan.next(); + if(!input.equalsIgnoreCase("y")&&!input.equalsIgnoreCase("n")){ + System.out.println("Please enter 'y' or 'n.'"); + } + }while(!input.equalsIgnoreCase("y")&&!input.equalsIgnoreCase("n")); + return input.equalsIgnoreCase("y"); } public static String getUserInput() { From 09168a5b2270f86e773150da7d8cb3f63e02f74b Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sat, 25 Nov 2017 18:12:27 -0500 Subject: [PATCH 17/30] basic menu added --- src/main/java/io/zipcoder/casino/Console.java | 53 ++++++++++++++++++- .../java/io/zipcoder/casino/CrapsConsole.java | 16 +++--- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index a0b54e53..19e155d9 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -3,10 +3,61 @@ import java.util.Scanner; import java.util.WeakHashMap; +import static io.zipcoder.casino.CrapsConsole.playCraps; + public class Console { - public void casinoMenu() { + public static void main(String[] args) { + + casinoHome(); + + } + + public static void casinoHome(){ + displayWelcomeMessage(); + selectGame(); + } + + + private static void selectGame() { + System.out.println("Which of our fine games would you like to try first?\n" + + "Enter 'blackjack' or 'b' to play BlackJack\n" + + "Enter 'craps' or 'c' to play Craps\n" + + "Enter 'GoFish or 'g to Go Fish.\n" + + "Type exit to quit"); + + Scanner scan = new Scanner(System.in); + String input; + do{ + input = scan.next(); + if(!input.equalsIgnoreCase("blackjack")&&!input.equalsIgnoreCase("b")&& + !input.equalsIgnoreCase("craps")&&!input.equalsIgnoreCase("c")&& + !input.equalsIgnoreCase("gofish")&&!input.equalsIgnoreCase("g")&& + !input.equalsIgnoreCase("exit")){ + System.out.println("I'm sorry that's not a valid entry"); + } + }while(!input.equalsIgnoreCase("blackjack")&&!input.equalsIgnoreCase("b")&& + !input.equalsIgnoreCase("craps")&&!input.equalsIgnoreCase("c")&& + !input.equalsIgnoreCase("gofish")&&!input.equalsIgnoreCase("g")&& + !input.equalsIgnoreCase("exit")); + + if(input.equalsIgnoreCase("blackjack")||input.equalsIgnoreCase("b")) { + // playBlackJack(); + } + else if(input.equalsIgnoreCase("craps")||input.equalsIgnoreCase("c")){ + playCraps(); + } + else if(input.equalsIgnoreCase("gofish")||input.equalsIgnoreCase("g")){ + playCraps(); + }else if(input.equalsIgnoreCase("exit")){ + System.exit(0); + } + } + + private static void displayWelcomeMessage() { + System.out.println("Welcome to our casino. Where the slots are are loose\n" + + "and the banker is liberal with credit\n"); } } diff --git a/src/main/java/io/zipcoder/casino/CrapsConsole.java b/src/main/java/io/zipcoder/casino/CrapsConsole.java index 00b916ad..1ffb2220 100644 --- a/src/main/java/io/zipcoder/casino/CrapsConsole.java +++ b/src/main/java/io/zipcoder/casino/CrapsConsole.java @@ -2,10 +2,12 @@ import java.util.Scanner; +import static io.zipcoder.casino.Console.casinoHome; + public class CrapsConsole { - public void playCraps(){ + public static void playCraps(){ Craps craps = new Craps(); CrapsPlayer crapsPlayer = new CrapsPlayer(); @@ -28,11 +30,11 @@ public void playCraps(){ playGame = askPlayAgain(); } - + casinoHome(); } - private void rollPointRound(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { + private static void rollPointRound(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { craps.setPoint(roll); System.out.println("Point is set at " + roll); @@ -52,7 +54,7 @@ private void rollPointRound(Craps craps, CrapsPlayer crapsPlayer, Integer roll) } } - private void rollComeout(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { + private static void rollComeout(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { if(craps.isBetWinComeOut(roll, craps.getBetType())){ craps.playerWins(crapsPlayer); }else if (craps.isBetLossComeOut(roll, craps.getBetType())){ @@ -63,12 +65,12 @@ private void rollComeout(Craps craps, CrapsPlayer crapsPlayer, Integer roll) { } - private void promptPlayerForRoll() { + private static void promptPlayerForRoll() { System.out.println("Ready? Enter to roll"); getUserInput(); } - private void promptPlayerForBet() { + private static void promptPlayerForBet() { System.out.println("How much do you want to bet?"); } @@ -146,7 +148,7 @@ private static boolean isInputDouble(String passedString) return (true); } - private boolean askPlayAgain() { + private static boolean askPlayAgain() { System.out.println("Play again?"); return getBooleanInput(); } From 740fdff11082ac96147cb1acfba44f666c38283e Mon Sep 17 00:00:00 2001 From: amyaim Date: Sat, 25 Nov 2017 22:27:29 -0500 Subject: [PATCH 18/30] first part done --- src/main/java/io/zipcoder/casino/Card.java | 1 + .../java/io/zipcoder/casino/CardPlayer.java | 5 +- src/main/java/io/zipcoder/casino/Game.java | 2 +- src/main/java/io/zipcoder/casino/GoFish.java | 73 ++-- .../java/io/zipcoder/casino/GoFishGame.java | 326 +++++++++--------- .../java/io/zipcoder/casino/GoFishPlayer.java | 41 ++- src/main/java/io/zipcoder/casino/Player.java | 11 + .../io/zipcoder/casino/GoFishGameTest.java | 149 +++++--- 8 files changed, 355 insertions(+), 253 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/Card.java b/src/main/java/io/zipcoder/casino/Card.java index 9f242036..16304852 100644 --- a/src/main/java/io/zipcoder/casino/Card.java +++ b/src/main/java/io/zipcoder/casino/Card.java @@ -20,6 +20,7 @@ public Suit getSuit() { return suit; } + @Override public String toString() { return rank.getSymbol() + suit.getCardSymbol(); diff --git a/src/main/java/io/zipcoder/casino/CardPlayer.java b/src/main/java/io/zipcoder/casino/CardPlayer.java index bab99cf3..3428df30 100644 --- a/src/main/java/io/zipcoder/casino/CardPlayer.java +++ b/src/main/java/io/zipcoder/casino/CardPlayer.java @@ -5,7 +5,10 @@ public class CardPlayer extends Player{ private ArrayList hand; - + public CardPlayer(){ + super(); + this.hand = hand; + } public ArrayList getHand() { return hand; } diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index 7960decb..2ef972d3 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -public abstract class Game { +public abstract class Game extends Exception { private int playerTurn; private ArrayList players = new ArrayList(); diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 69c98beb..64ad95ee 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -5,57 +5,54 @@ public class GoFish extends GoFishGame { - Scanner scanner = new Scanner(System.in); static GoFishGame goFishGame = new GoFishGame(); - public static void goFishRun(){ - - System.out.print("Welcome to the table!"); + public static void goFishRun() { + System.out.print("Welcome to the table!\n" + + "Insert nick name you want to use for the game? \n\n"); + goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); String response = "No"; goFishGame.startGame(); goFishGame.playerHand(); goFishGame.computerHand(); + int i =0; - try { - do { - - while (!goFishGame.getDeck().isEmpty()) { - //System.out.println(goFishGame.getComputerHand()); - System.out.println("Insert the rank of the card you want to request: "); - String rank = InPutConsole.getInput(); - goFishGame.checkInput(rank); - goFishGame.playerHandDisplay(); - // goFishGame.increasePlayerScoreForBook(); - goFishGame.goFishingPlayer(); - - goFishGame.checkIfComputerHandHasAcard(); - goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); - // goFishGame.checkComputerForBook(); - goFishGame.goFishingComputer(); - - // System.out.println(goFishGame.getPlayerHand()); - } - - System.out.println("The deck has finished"); - // goFishGame.increasePlayerScore(); - - // goFishGame.increaseComputerScore(); - - System.out.println("Computer score is " + goFishGame.getComputerPlayer().getScore()); - System.out.println("Your score is " + goFishGame.getGoFishPlayer().getScore()); - goFishGame.decideWiner(); - System.out.println("Do you want to play again?"); - response = InPutConsole.getInput(); - } while (response == "YES"); - } catch (Exception e) { - System.out.println("please insert YES or NO" ); + do { + + while (!goFishGame.getDeck().isEmpty()) { + System.out.println("Insert the rank of the card you want to request: "); + String rank = InPutConsole.getInput(); + goFishGame.askComputerHandForACard(rank); + goFishGame.playerHandDisplay(); + goFishGame.goFishingPlayer(); + // goFishGame.removeBookedCard(); + goFishGame.checkIfComputerHandHasAcard(); + goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); + goFishGame.goFishingComputer(); + // goFishGame.removeComputerBookedCard(); + + } + System.out.println("The deck has finished"); + System.out.println("Computer score is " + goFishGame.getComputerPlayer().getScore()); + System.out.println( goFishGame.getGoFishPlayer().getName() + " score is " + goFishGame.getGoFishPlayer().getScore()); + goFishGame.decideWiner(); + System.out.println("Do you want to play again?"); + response = InPutConsole.getInput(); + if(response.toUpperCase().equalsIgnoreCase("yes")){ + goFishGame.startGame(); + + } + else{ + i=1; + } + } while (i==0); + System.out.println("Bye bye, visit us again"); } -} /* public void playGoFish( diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 8e326d35..5a4bfa1f 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -1,5 +1,7 @@ package io.zipcoder.casino; +import com.sun.tools.doclets.formats.html.SourceToHTMLConverter; + import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -25,7 +27,7 @@ public GoFishGame() { public void startGame() { if (goFishPlayer == null || deck == null || playerHand == null) { - throw new IllegalStateException("Player doesnt exist"); + throw new IllegalStateException("Game tools doesnt exist"); } } @@ -37,20 +39,31 @@ public ArrayList playerHand() { deck.remove(i); i++; } - System.out.println("Here is your hand " + playerHand.toString() + ". GoodLuck!!!"); + System.out.println("Here is your cards " + playerHand.toString() + + ". GoodLuck " + goFishPlayer.getName() + " !!!"); return playerHand; } public ArrayList computerHand() { + int i =0; - int i = 0; - while (computerHand.size() != 7) { - computerHand.add(deck.get(i)); - deck.remove(i); - i++; - } - return computerHand; + + try { + if (getDeck().size() > 7) { + + while (computerHand.size() != 7) { + computerHand.add(deck.get(i)); + deck.remove(i); + i++; + } + } + + }catch (Exception e) {} + + + + return computerHand; } @@ -83,7 +96,7 @@ public Boolean checkComputerHandForPlayerRequestedCard(String rank) { public void askComputerHandForACard(String rank) { ArrayList cards = new ArrayList<>(); - if (checkComputerHandForPlayerRequestedCard(rank)) { + // if (checkComputerHandForPlayerRequestedCard(rank)) { // System.out.println("The computer has " + rank + ". The card is being added to your hand..."); Card card = null; while (checkComputerHandForPlayerRequestedCard(rank)) { @@ -92,22 +105,25 @@ public void askComputerHandForACard(String rank) { if (rank.equals(card.getRank().getSymbol())) cards.add(card); } getPlayerHand().addAll(cards); - //checkPlayerForBook(); + removeBookedCard(); getComputerHand().removeAll(cards); cards = new ArrayList<>(); System.out.println("The computer has " + rank +".The card" + - " is added to your hand. Insert the next card you want: "); + " is added to your hand.\n Insert the next card you want: "); rank = InPutConsole.getInput(); + checkComputerHandForPlayerRequestedCard(rank); } + System.out.println("The computer doesnt have the card. Go Fish!!"); } - System.out.println("The computer doesnt have the card. Go Fish!!"); - } + + //// } public void goFishingPlayer() { + System.out.println(goFishPlayer.getName() + " is fishing"); getPlayerHand().add(getDeck().get(0)); getDeck().remove(0); } @@ -123,19 +139,24 @@ public String computerCardToRequest() { int maxCount = 0; int count = 0; Card card = null; - for (int i = 0; i < getComputerHand().size() - 1; i++) { - card = getComputerHand().get(i); - for (int j = i + 1; j < getComputerHand().size() - 1; j++) { - if (card.getRank() == getComputerHand().get(j).getRank()) { - count++; - } - } - if (count > maxCount) - - maxCount = count; - card = getComputerHand().get(i); - } - return card.getRank().getSymbol(); + try { + for (int i = 0; i < getComputerHand().size() - 1; i++) { + card = getComputerHand().get(i); + for (int j = i + 1; j < getComputerHand().size() - 1; j++) { + if (card.getRank() == getComputerHand().get(j).getRank()) { + count++; + } + } + if (count > maxCount) + + maxCount = count; + card = getComputerHand().get(i); + } + return card.getRank().getSymbol(); + }catch(Exception e){ + System.out.println("no card, sorry!"); + return ""; + } } @@ -158,23 +179,33 @@ public ArrayList askPlayerForACard(String rank) { while (checkPlayerHasRequestedCardRank(rank)) { for (int i = 0; i < getPlayerHand().size(); i++) { card = getPlayerHand().get(i); - if (rank.equals(card.getRank().getSymbol())) cards.add(card); + if (rank.equals(card.getRank().getSymbol())) + cards.add(card); + + + } + System.out.println(goFishPlayer.getName() + " has " + rank +"." + + + "The card is added to the computer hand"); getComputerHand().addAll(cards); getPlayerHand().removeAll(cards); - // checkComputerForBook(); + removeComputerBookedCard(); cards = new ArrayList<>(); rank = computerCardToRequest(); checkPlayerHasRequestedCardRank(rank); } } - System.out.println("The player doesnt have " + rank + ". Go Fish!!"); + System.out.println(goFishPlayer.getName()+ " doesnt have " + rank + ". Go Fish!!"); return getComputerHand(); } public void goFishingComputer() { + try { + System.out.println("The computer is fishing"); getComputerHand().add(getDeck().get(0)); getDeck().remove(0); + }catch (Exception e){}git } public Map playerHandDisplay() { @@ -190,99 +221,128 @@ public Map playerHandDisplay() { } - public void checkPlayerHandForBook() { - Map playerMap = playerHandDisplay(); - int z=0; - int count=0; - - int score = goFishPlayer.getScore(); - ArrayList cards2 = new ArrayList<>(); - ArrayList cards = getPlayerHand(); - // while (getPlayerHand().size() > 3) { - while(z< getPlayerHand().size()){ - String rank = getPlayerHand().get(z).getRank().getSymbol(); - for (Iterator it = getPlayerHand().iterator(); it.hasNext(); ){ - Card card = it.next(); - if (it.next().getRank().getSymbol().equalsIgnoreCase(rank)){ - count++; - } -// for (int i = 1; i < getPlayerHand().size(); i++) { -// int count = 0; -// Card card = getPlayerHand().get(i); -// //for (int j = 0; j < getPlayerHand().size(); j++) { -// Card card1 = cards.get(i-1); -// if ((card.getRank().getSymbol().equals(card1.getRank().getSymbol())) ) -// count++; - - if (count == 4) { - // score++; - System.out.println("You booked " + card.getRank().getSymbol()); - System.out.println("Your score is " + score); - - for (int k = 0; k < 4; k++) - cards.add(card); - } - - } - } - cards.removeAll(cards); - } - // } - + public Card checkPlayerHandForBook() { + int count = 0; + Card card = null; + //ArrayList toBeRemoved=new ArrayList<>(); + //int score = getGoFishPlayer().getScore(); - public void checkComputerForBook() { - int score = computerPlayer.getScore(); - for (int i = 0; i < getComputerHand().size(); i++) { - int count = 0; - Card card = getComputerHand().get(i); + for (int i = 0; i < getPlayerHand().size() ; i++) { + boolean found = false; - for (int j = i + 1; j < getComputerHand().size(); j++) { - Card card2 = getComputerHand().get(j); - if (card.getRank().getSymbol().equals(card2.getRank().getSymbol()) && i != j) + for (int j = i + 1; !found && j < getPlayerHand().size(); j++) { + if (getPlayerHand().get(i).equals(getPlayerHand().get(j))) + found = true; count++; - if (count == 4) { - System.out.println("Computer booked " + card.getRank().getSymbol()); - for (int k = 0; k < 4; k++) - getComputerHand().remove(card); - score++; - System.out.println("Computer score is " + score); + + if (count == 4) + card = getPlayerHand().get(i); } } - } + //System.out.println("You booked " + card.getRank().getSymbol() + + // ". Your score is " + score); + + return card; } -// - public Boolean checkPlayersCardRequestForInputBoundary(String input) { - Boolean checkResult = true; - if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) || input.toUpperCase().equals("K") - || input.toUpperCase().equals("J") || input.toUpperCase().equals("J")) { - checkResult = true; - } else { - System.out.println("insert proper value"); - checkResult = false; - } - return checkResult; + + public void removeBookedCard(){ + String cardTobeRemoved= checkPlayerHandForBook().getRank().getSymbol(); + ArrayList tobeRemovedList = new ArrayList<>(); + Card card = null; + for(int i=0; i < getPlayerHand().size(); i++) { + card = getPlayerHand().get(i); + if(card.getRank().getSymbol().equals(cardTobeRemoved)) + tobeRemovedList.add(card); + } + + getPlayerHand().removeAll(tobeRemovedList); + int score= getGoFishPlayer().getScore()+1; + goFishPlayer.setScore(score); + System.out.println(getGoFishPlayer().getName()+ " score is "+ getGoFishPlayer().getScore()); + } + public Card checkComputerHandForBook() { + int count = 0; + Card card = null; + //ArrayList toBeRemoved=new ArrayList<>(); + //int score = getGoFishPlayer().getScore(); - public Boolean checkPlayersCardRequestForGameRule(String input) { - Boolean checkresult = false; - for (int i = 0; i < getPlayerHand().size(); i++) { - if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { - checkresult = true; - } - } + for (int i = 0; i < getComputerHand().size() ; i++) { + boolean found = false; - return checkresult; - } + for (int j = i + 1; !found && j < getComputerHand().size(); j++) { + if (getComputerHand().get(i).equals(getComputerHand().get(j))) + found = true; + count++; - public void checkInput(String input) { + if (count == 4) + card = getComputerHand().get(i); + } + } + //System.out.println("You booked " + card.getRank().getSymbol() + + // ". Your score is " + score); + + return card; + } + public void removeComputerBookedCard(){ + try { + String cardTobeRemoved = checkComputerHandForBook().getRank().getSymbol(); + ArrayList tobeRemovedList = new ArrayList<>(); + Card card = null; + for (int i = 0; i < computerHand().size(); i++) { + card = getComputerHand().get(i); + if (card.getRank().getSymbol().equals(cardTobeRemoved)) + tobeRemovedList.add(card); + } + getComputerHand().removeAll(tobeRemovedList); + int score = getComputerPlayer().getScore() + 1; + computerPlayer.setScore(score); + System.out.println("computer score is " + getComputerPlayer().getScore()); + }catch (Exception e){ + System.out.println("card cant be removed"); + } - while (!checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { - System.out.println("Insert proper value"); - } - askComputerHandForACard(input); - } + } + +// public void checkPlayersCardRequestForInputBoundary(String input) { +// Boolean checkResult = true; +// if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) +// || (input.toString().toUpperCase().equals("K")) +// || (input.toString().toUpperCase().equals("J")) || +// (input.toString().toUpperCase().equals("Q"))) { +// checkPlayersCardRequestForGameRule(input); +// } else { +// +// System.out.println("Insert proper value"); +// } +// +// } + + +// public void checkPlayersCardRequestForGameRule(String input) { +// // Boolean checkresult = false; +// for (int i = 0; i < getPlayerHand().size(); i++) { +// if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { +// askComputerHandForACard(input); +// } +// System.out.println("You cannot request for card not in hand"); +// break; +// +// } +// +// +// } + +// public void checkInput(String input) { +// +// +// while (checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { +// System.out.println("Insert proper value"); +// } +// askComputerHandForACard(input); +// } @@ -306,52 +366,6 @@ public void increaseComputerScore() { } - // public static void main(String[] args) { - -// Scanner scanner = new Scanner(System.in); -// -// GoFishGame goFishGame = new GoFishGame(); -// String response = "No"; -// -// goFishGame.startGame(); -// goFishGame.playerHand(); -// goFishGame.computerHand(); -// -// try { -// do { -// -// while (!goFishGame.getDeck().isEmpty()) { -// //System.out.println(goFishGame.getComputerHand()); -// System.out.println("Insert the rank of the card you want to request: "); -// String rank = InPutConsole.getInput(); -// goFishGame.askComputerHandForACard(rank); -// goFishGame.playerHandDisplay(); -// goFishGame.increasePlayerScoreForBook(); -// goFishGame.goFishingPlayer(); -// goFishGame.checkIfComputerHandHasAcard(); -// goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); -// goFishGame.checkComputerForBook(); -// goFishGame.goFishingComputer(); -// -// // System.out.println(goFishGame.getPlayerHand()); -// } -// -// System.out.println("The deck has finished"); -// // goFishGame.increasePlayerScore(); -// -// // goFishGame.increaseComputerScore(); -// -// System.out.println("Computer score is " + goFishGame.computerPlayer.getScore()); -// System.out.println("Your score is " + goFishGame.goFishPlayer.getScore()); -// goFishGame.decideWiner(); -// System.out.println("Do you want to play again?"); -// response = InPutConsole.getInput(); -// } while (response == "YES"); -// } catch(Exception e) { -// System.out.println("please insert YES or NO" ); -// } -// } - public void decideWiner() { if (computerPlayer.getScore() > goFishPlayer.getScore()) System.out.println("nayyy! The machine won"); diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index 707a5566..2b002a69 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -7,16 +7,37 @@ public class GoFishPlayer extends CardPlayer { - - - - - - - - - -// public Card drawCard(Deck deck) { + private int score; + private String name; + private ArrayList hand; + + public GoFishPlayer(){super();}; + + @Override + public int getScore() { + return score; + } + + @Override + public String getName() { + return name; + } + + @Override + public ArrayList getHand() { + return hand; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public void setScore(int score) { + this.score = score; + } + // public Card drawCard(Deck deck) { // Card playerCard = deck.getCards().remove(0); // return playerCard; // } diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java index e0bb7a00..2002c675 100644 --- a/src/main/java/io/zipcoder/casino/Player.java +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -5,6 +5,13 @@ public class Player { private String name; private int score; + public Player(){ + + this.bank=bank; + this.name = name; + this.score= score; + } + public void setName(String name) { this.name = name; } @@ -16,4 +23,8 @@ public String getName() { public int getScore() { return score; } + + public void setScore(int score) { // only for test purpose, delete it later + this.score = score; + } } diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index 6dee306e..a228b17d 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -237,43 +237,43 @@ public void computerDecisionForCardTest() { } - @Test - - public void checkPlayersCardRequestForInputBoundary() { - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card = new Card(Rank.SEVEN, Suit.DIAMOND); - ArrayList playerHand1 = new ArrayList<>(); - playerHand1.add(card1); - playerHand1.add(card); - - goFishGame.setPlayerHand(playerHand1); - Boolean expected = true; - Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); - Assert.assertEquals(expected, actual); - Boolean expected2 = false; - Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); - Assert.assertEquals(expected2, actual2); - } - - @Test - public void checkPlayersCardRequestForGameRuleTest(){ - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card = new Card(Rank.SEVEN, Suit.DIAMOND); - - ArrayList playerHand1 = new ArrayList<>(); - playerHand1.add(card1); - playerHand1.add(card); - - goFishGame.setPlayerHand(playerHand1); - - Boolean expected = false; - Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); - Assert.assertEquals(expected, actual); - - Boolean expected2 = true; - Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); - Assert.assertEquals(expected2, actual2); - } +// @Test +// +// public void checkPlayersCardRequestForInputBoundary() { +// Card card1 = new Card(Rank.SIX, Suit.HEART); +// Card card = new Card(Rank.SEVEN, Suit.DIAMOND); +// ArrayList playerHand1 = new ArrayList<>(); +// playerHand1.add(card1); +// playerHand1.add(card); +// +// goFishGame.setPlayerHand(playerHand1); +// Boolean expected = true; +// Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); +// Assert.assertEquals(expected, actual); +// Boolean expected2 = false; +// Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); +// Assert.assertEquals(expected2, actual2); +// } + +// @Test +// public void checkPlayersCardRequestForGameRuleTest(){ +// Card card1 = new Card(Rank.SIX, Suit.HEART); +// Card card = new Card(Rank.SEVEN, Suit.DIAMOND); +// +// ArrayList playerHand1 = new ArrayList<>(); +// playerHand1.add(card1); +// playerHand1.add(card); +// +// goFishGame.setPlayerHand(playerHand1); +// +// Boolean expected = false; +// Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); +// Assert.assertEquals(expected, actual); +// +// Boolean expected2 = true; +// Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); +// Assert.assertEquals(expected2, actual2); +// } @Test @@ -320,14 +320,14 @@ public void goFishingComputerTest(){ @Test public void playerHandBookTest(){ - Card card1 = new Card(Rank.SIX, Suit.CLUB); - Card card2 = new Card(Rank.SEVEN, Suit.HEART); - Card card3 = new Card(Rank.SIX, Suit.DIAMOND); - Card card4 = new Card(Rank.EIGHT, Suit.HEART); - Card card5 = new Card(Rank.SIX, Suit.SPADE); - Card card6 = new Card(Rank.SEVEN, Suit.CLUB); - Card card7 = new Card(Rank.SIX, Suit.HEART); - Card card8 = new Card(Rank.FIVE, Suit.SPADE); + Card card1 = new Card(Rank.TWO, Suit.CLUB); + Card card2 = new Card(Rank.TWO, Suit.HEART); + Card card3 = new Card(Rank.TWO, Suit.DIAMOND); + Card card4 = new Card(Rank.TWO, Suit.SPADE); + Card card5 = new Card(Rank.THREE, Suit.SPADE); + Card card6 = new Card(Rank.THREE, Suit.CLUB); + Card card7 = new Card(Rank.THREE, Suit.HEART); + Card card8 = new Card(Rank.THREE, Suit.SPADE); ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); @@ -339,15 +339,70 @@ public void playerHandBookTest(){ playerHand1.add(card7); playerHand1.add(card8); - + System.out.println(playerHand1.size()); goFishGame.setPlayerHand(playerHand1); // goFishGame.checkPlayerHandForBook(); + goFishGame.removeBookedCard(); + + System.out.println(playerHand1.size()); + System.out.println(goFishGame.getGoFishPlayer().getScore()); + // System.out.println(playerHand1.get(0)); + // System.out.println(playerHand1); + + + + + } + + @Test + + public void playerScoreTest(){ + Player player = goFishGame.getGoFishPlayer(); + int score =0; + Card card1 = new Card(Rank.TWO, Suit.CLUB); + Card card2 = new Card(Rank.TWO, Suit.HEART); + Card card3 = new Card(Rank.TWO, Suit.DIAMOND); + Card card4 = new Card(Rank.TWO, Suit.SPADE); + Card card5 = new Card(Rank.THREE, Suit.SPADE); + Card card6 = new Card(Rank.THREE, Suit.CLUB); + Card card7 = new Card(Rank.THREE, Suit.HEART); + Card card8 = new Card(Rank.THREE, Suit.SPADE); + + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + playerHand1.add(card4); + playerHand1.add(card5); + playerHand1.add(card6); + playerHand1.add(card7); + playerHand1.add(card8); + + System.out.println(playerHand1.size()); + goFishGame.setPlayerHand(playerHand1); + + // goFishGame.checkPlayerHandForBook(); + System.out.println(goFishGame.checkPlayerHandForBook()); + System.out.println(playerHand1.size()); - System.out.println(playerHand1.get(0)); + System.out.println(playerHand1); + System.out.println(score); + // System.out.println(playerHand1.get(0)); + // System.out.println(playerHand1); + + + } + + @Test + public void decideWinnerTest() { + goFishGame.getComputerPlayer().setScore(10); + goFishGame.getGoFishPlayer().setScore(2); + + goFishGame.decideWiner(); } From ab61446a6e68b4a55e3bd5ab0ff6ae8363fe1527 Mon Sep 17 00:00:00 2001 From: amyaim Date: Sun, 26 Nov 2017 09:29:56 -0500 Subject: [PATCH 19/30] added fw iems --- src/main/java/io/zipcoder/casino/GoFish.java | 30 +- .../java/io/zipcoder/casino/GoFishGame.java | 283 +++++++++--------- 2 files changed, 164 insertions(+), 149 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 64ad95ee..f41fb6df 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -11,22 +11,25 @@ public class GoFish extends GoFishGame { public static void goFishRun() { - System.out.print("Welcome to the table!\n" + - "Insert nick name you want to use for the game? \n\n"); - goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); - String response = "No"; - goFishGame.startGame(); - goFishGame.playerHand(); - goFishGame.computerHand(); + + + int i =0; do { + System.out.print("Welcome to the table!\n" + + "Insert nick name you want to use for the game? \n\n"); + goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); + goFishGame.startGame(); + goFishGame.playerHand(); + goFishGame.computerHand(); while (!goFishGame.getDeck().isEmpty()) { System.out.println("Insert the rank of the card you want to request: "); String rank = InPutConsole.getInput(); + goFishGame.askComputerHandForACard(rank); goFishGame.playerHandDisplay(); goFishGame.goFishingPlayer(); @@ -34,19 +37,20 @@ public static void goFishRun() { goFishGame.checkIfComputerHandHasAcard(); goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); goFishGame.goFishingComputer(); - // goFishGame.removeComputerBookedCard(); + // goFishGame.removeComputerBookedCard(); } System.out.println("The deck has finished"); System.out.println("Computer score is " + goFishGame.getComputerPlayer().getScore()); - System.out.println( goFishGame.getGoFishPlayer().getName() + " score is " + goFishGame.getGoFishPlayer().getScore()); + System.out.println(goFishGame.getGoFishPlayer().getName() + " score is " + goFishGame.getGoFishPlayer().getScore()); goFishGame.decideWiner(); System.out.println("Do you want to play again?"); - response = InPutConsole.getInput(); - if(response.toUpperCase().equalsIgnoreCase("yes")){ - goFishGame.startGame(); + String response = InPutConsole.getInput(); + if (response.toUpperCase().equalsIgnoreCase("yes")){ + GoFish.goFishRun(); + + } - } else{ i=1; } diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 5a4bfa1f..4a3008d5 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -26,44 +26,51 @@ public GoFishGame() { public void startGame() { + if (goFishPlayer == null || deck == null || playerHand == null) { throw new IllegalStateException("Game tools doesnt exist"); } + } public ArrayList playerHand() { - int i = 0; - while (playerHand.size() != 7) { - playerHand.add(deck.get(i)); - deck.remove(i); - i++; + try { + int i = 0; + while (playerHand.size() != 7) { + playerHand.add(deck.get(i)); + deck.remove(i); + i++; + } + System.out.println("Here is your cards " + playerHand.toString() + + ". GoodLuck " + goFishPlayer.getName() + " !!!"); + return playerHand; + } catch (Exception e) { + System.out.println("no card in the deck"); + return null; } - System.out.println("Here is your cards " + playerHand.toString() + - ". GoodLuck " + goFishPlayer.getName() + " !!!"); - return playerHand; } public ArrayList computerHand() { - int i =0; + int i = 0; - try { - if (getDeck().size() > 7) { - - while (computerHand.size() != 7) { - computerHand.add(deck.get(i)); - deck.remove(i); - i++; - } - } + try { + if (getDeck().size() > 7) { - }catch (Exception e) {} + while (computerHand.size() != 7) { + computerHand.add(deck.get(i)); + deck.remove(i); + i++; + } + } - + } catch (Exception e) { + } - return computerHand; + + return computerHand; } @@ -96,30 +103,30 @@ public Boolean checkComputerHandForPlayerRequestedCard(String rank) { public void askComputerHandForACard(String rank) { ArrayList cards = new ArrayList<>(); - // if (checkComputerHandForPlayerRequestedCard(rank)) { - // System.out.println("The computer has " + rank + ". The card is being added to your hand..."); - Card card = null; - while (checkComputerHandForPlayerRequestedCard(rank)) { - for (int i = 0; i < getComputerHand().size(); i++) { - card = getComputerHand().get(i); - if (rank.equals(card.getRank().getSymbol())) cards.add(card); - } - getPlayerHand().addAll(cards); - removeBookedCard(); - getComputerHand().removeAll(cards); - cards = new ArrayList<>(); + // if (checkComputerHandForPlayerRequestedCard(rank)) { + // System.out.println("The computer has " + rank + ". The card is being added to your hand..."); + Card card = null; + while (checkComputerHandForPlayerRequestedCard(rank)) { + for (int i = 0; i < getComputerHand().size(); i++) { + card = getComputerHand().get(i); + if (rank.equals(card.getRank().getSymbol())) cards.add(card); + } + getPlayerHand().addAll(cards); + removeBookedCard(); + getComputerHand().removeAll(cards); + cards = new ArrayList<>(); - System.out.println("The computer has " + rank +".The card" + - " is added to your hand.\n Insert the next card you want: "); + System.out.println("The computer has " + rank + ".The card" + + " is added to your hand.\n Insert the next card you want: "); - rank = InPutConsole.getInput(); - checkComputerHandForPlayerRequestedCard(rank); + rank = InPutConsole.getInput(); + checkComputerHandForPlayerRequestedCard(rank); - } - System.out.println("The computer doesnt have the card. Go Fish!!"); } + System.out.println("The computer doesnt have the card. Go Fish!!"); + } - //// } + //// } public void goFishingPlayer() { @@ -139,24 +146,24 @@ public String computerCardToRequest() { int maxCount = 0; int count = 0; Card card = null; - try { - for (int i = 0; i < getComputerHand().size() - 1; i++) { - card = getComputerHand().get(i); - for (int j = i + 1; j < getComputerHand().size() - 1; j++) { - if (card.getRank() == getComputerHand().get(j).getRank()) { - count++; - } - } - if (count > maxCount) - - maxCount = count; - card = getComputerHand().get(i); - } - return card.getRank().getSymbol(); - }catch(Exception e){ - System.out.println("no card, sorry!"); - return ""; - } + try { + for (int i = 0; i < getComputerHand().size() - 1; i++) { + card = getComputerHand().get(i); + for (int j = i + 1; j < getComputerHand().size() - 1; j++) { + if (card.getRank() == getComputerHand().get(j).getRank()) { + count++; + } + } + if (count > maxCount) + + maxCount = count; + card = getComputerHand().get(i); + } + return card.getRank().getSymbol(); + } catch (Exception e) { + System.out.println("no card, sorry!"); + return ""; + } } @@ -183,11 +190,10 @@ public ArrayList askPlayerForACard(String rank) { cards.add(card); - } - System.out.println(goFishPlayer.getName() + " has " + rank +"." + - - "The card is added to the computer hand"); + System.out.println(goFishPlayer.getName() + " has " + rank + "." + + + "The card is added to the computer hand"); getComputerHand().addAll(cards); getPlayerHand().removeAll(cards); removeComputerBookedCard(); @@ -196,24 +202,25 @@ public ArrayList askPlayerForACard(String rank) { checkPlayerHasRequestedCardRank(rank); } } - System.out.println(goFishPlayer.getName()+ " doesnt have " + rank + ". Go Fish!!"); + System.out.println(goFishPlayer.getName() + " doesnt have " + rank + ". Go Fish!!"); return getComputerHand(); } public void goFishingComputer() { - try { - System.out.println("The computer is fishing"); - getComputerHand().add(getDeck().get(0)); - getDeck().remove(0); - }catch (Exception e){}git + try { + System.out.println("The computer is fishing"); + getComputerHand().add(getDeck().get(0)); + getDeck().remove(0); + } catch (Exception e) { + } } public Map playerHandDisplay() { - // int score = player.getScore(); + // int score = player.getScore(); Map result = getPlayerHand() .stream().map(card -> card.getRank().getSymbol()) - .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + .collect(Collectors.groupingBy(Function.identity() , Collectors.counting())); System.out.println("You have " + result); @@ -227,84 +234,89 @@ public Card checkPlayerHandForBook() { //ArrayList toBeRemoved=new ArrayList<>(); //int score = getGoFishPlayer().getScore(); - for (int i = 0; i < getPlayerHand().size() ; i++) { + for (int i = 0; i < getPlayerHand().size(); i++) { boolean found = false; for (int j = i + 1; !found && j < getPlayerHand().size(); j++) { if (getPlayerHand().get(i).equals(getPlayerHand().get(j))) found = true; - count++; + count++; - if (count == 4) - card = getPlayerHand().get(i); - } + if (count == 4) + card = getPlayerHand().get(i); } - //System.out.println("You booked " + card.getRank().getSymbol() + + } + //System.out.println("You booked " + card.getRank().getSymbol() + // ". Your score is " + score); return card; } - public void removeBookedCard(){ - String cardTobeRemoved= checkPlayerHandForBook().getRank().getSymbol(); - ArrayList tobeRemovedList = new ArrayList<>(); - Card card = null; - for(int i=0; i < getPlayerHand().size(); i++) { - card = getPlayerHand().get(i); - if(card.getRank().getSymbol().equals(cardTobeRemoved)) - tobeRemovedList.add(card); - } - - getPlayerHand().removeAll(tobeRemovedList); - int score= getGoFishPlayer().getScore()+1; - goFishPlayer.setScore(score); - System.out.println(getGoFishPlayer().getName()+ " score is "+ getGoFishPlayer().getScore()); + public void removeBookedCard() { + try { + String cardTobeRemoved = checkPlayerHandForBook().getRank().getSymbol(); + + ArrayList tobeRemovedList = new ArrayList<>(); + Card card = null; + for (int i = 0; i < getPlayerHand().size(); i++) { + card = getPlayerHand().get(i); + if (card.getRank().getSymbol().equals(cardTobeRemoved)) + tobeRemovedList.add(card); + } + + getPlayerHand().removeAll(tobeRemovedList); + int score = getGoFishPlayer().getScore() + 1; + goFishPlayer.setScore(score); + System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); + } catch (Exception e) { + } } - public Card checkComputerHandForBook() { - int count = 0; - Card card = null; - //ArrayList toBeRemoved=new ArrayList<>(); - //int score = getGoFishPlayer().getScore(); - - for (int i = 0; i < getComputerHand().size() ; i++) { - boolean found = false; - - for (int j = i + 1; !found && j < getComputerHand().size(); j++) { - if (getComputerHand().get(i).equals(getComputerHand().get(j))) - found = true; - count++; - - if (count == 4) - card = getComputerHand().get(i); - } - } - //System.out.println("You booked " + card.getRank().getSymbol() + - // ". Your score is " + score); - - return card; - } - public void removeComputerBookedCard(){ - try { - String cardTobeRemoved = checkComputerHandForBook().getRank().getSymbol(); - ArrayList tobeRemovedList = new ArrayList<>(); - Card card = null; - for (int i = 0; i < computerHand().size(); i++) { - card = getComputerHand().get(i); - if (card.getRank().getSymbol().equals(cardTobeRemoved)) - tobeRemovedList.add(card); - } + public Card checkComputerHandForBook() { + int count = 0; + Card card = null;µ + //ArrayList toBeRemoved=new ArrayList<>(); + //int score = getGoFishPlayer().getScore(); - getComputerHand().removeAll(tobeRemovedList); - int score = getComputerPlayer().getScore() + 1; - computerPlayer.setScore(score); - System.out.println("computer score is " + getComputerPlayer().getScore()); - }catch (Exception e){ - System.out.println("card cant be removed"); - } + for (int i = 0; i < getComputerHand().size(); i++) { + boolean found = false; + + for (int j = i + 1; !found && j < getComputerHand().size(); j++) { + if (getComputerHand().get(i).equals(getComputerHand().get(j))) + found = true; + count++; - } + if (count == 4) + card = getComputerHand().get(i); + } + } + //System.out.println("You booked " + card.getRank().getSymbol() + + // ". Your score is " + score); + + return card; + } + + public void removeComputerBookedCard() { + try { + String cardTobeRemoved = checkComputerHandForBook().getRank().getSymbol(); + ArrayList tobeRemovedList = new ArrayList<>(); + Card card = null; + for (int i = 0; i < computerHand().size(); i++) { + card = getComputerHand().get(i); + if (card.getRank().getSymbol().equals(cardTobeRemoved)) + tobeRemovedList.add(card); + } + + getComputerHand().removeAll(tobeRemovedList); + int score = getComputerPlayer().getScore() + 1; + computerPlayer.setScore(score); + System.out.println("computer score is " + getComputerPlayer().getScore()); + } catch (Exception e) { + System.out.println("card cant be removed"); + } + + } // public void checkPlayersCardRequestForInputBoundary(String input) { // Boolean checkResult = true; @@ -319,8 +331,8 @@ public void removeComputerBookedCard(){ // } // // } - - +// +// // public void checkPlayersCardRequestForGameRule(String input) { // // Boolean checkresult = false; // for (int i = 0; i < getPlayerHand().size(); i++) { @@ -334,7 +346,7 @@ public void removeComputerBookedCard(){ // // // } - +// // public void checkInput(String input) { // // @@ -345,7 +357,6 @@ public void removeComputerBookedCard(){ // } - public void increaseComputerScore() { int computerSameRankCardCount = 0; int computerScore = computerPlayer.getScore(); @@ -374,7 +385,7 @@ else if (computerPlayer.getScore() < goFishPlayer.getScore()) else if (computerPlayer.getScore() == goFishPlayer.getScore()) System.out.println("The game is tie! try again"); else - System.out.println("Sorry the score is not yet available. Please check again") ; + System.out.println("Sorry the score is not yet available. Please check again"); } From 1e262302cea5e90a8dacff68c3458be07528d6b0 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 09:44:18 -0500 Subject: [PATCH 20/30] merge ballet --- src/main/java/io/zipcoder/casino/Console.java | 2 +- src/main/java/io/zipcoder/casino/CrapsConsole.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 19e155d9..858b553c 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -19,7 +19,7 @@ public static void casinoHome(){ } - private static void selectGame() { + public static void selectGame() { System.out.println("Which of our fine games would you like to try first?\n" + "Enter 'blackjack' or 'b' to play BlackJack\n" + "Enter 'craps' or 'c' to play Craps\n" + diff --git a/src/main/java/io/zipcoder/casino/CrapsConsole.java b/src/main/java/io/zipcoder/casino/CrapsConsole.java index 1ffb2220..25ce0077 100644 --- a/src/main/java/io/zipcoder/casino/CrapsConsole.java +++ b/src/main/java/io/zipcoder/casino/CrapsConsole.java @@ -2,7 +2,7 @@ import java.util.Scanner; -import static io.zipcoder.casino.Console.casinoHome; +import static io.zipcoder.casino.Console.selectGame; public class CrapsConsole { @@ -30,7 +30,8 @@ public static void playCraps(){ playGame = askPlayAgain(); } - casinoHome(); + + selectGame(); } From 2de7e592477f6d9c84149a5d47a892dca7d59960 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 10:22:13 -0500 Subject: [PATCH 21/30] craps and unfinished goFish are merged --- src/main/java/io/zipcoder/casino/Console.java | 3 ++- src/main/java/io/zipcoder/casino/Game.java | 2 +- src/main/java/io/zipcoder/casino/GoFish.java | 2 +- src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java | 3 --- src/test/java/io/zipcoder/casino/CrapsTest.java | 3 --- src/test/java/io/zipcoder/casino/GoFishGameTest.java | 5 +---- 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/Console.java b/src/main/java/io/zipcoder/casino/Console.java index 881f2131..66350744 100644 --- a/src/main/java/io/zipcoder/casino/Console.java +++ b/src/main/java/io/zipcoder/casino/Console.java @@ -5,6 +5,7 @@ import java.util.WeakHashMap; import static io.zipcoder.casino.CrapsConsole.playCraps; +import static io.zipcoder.casino.GoFish.goFishRun; public class Console { @@ -49,7 +50,7 @@ else if(input.equalsIgnoreCase("craps")||input.equalsIgnoreCase("c")){ playCraps(); } else if(input.equalsIgnoreCase("gofish")||input.equalsIgnoreCase("g")){ - playCraps(); + goFishRun(); }else if(input.equalsIgnoreCase("exit")){ System.exit(0); } diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java index e046aec5..b3d37f00 100644 --- a/src/main/java/io/zipcoder/casino/Game.java +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -3,7 +3,7 @@ import java.util.ArrayList; - public abstract class Game extends Exception { + public class Game extends Exception { private int playerTurn; private ArrayList players = new ArrayList(); diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index c23ae383..14ff168a 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -105,4 +105,4 @@ public static void goFishRun() { // } while (true); // } } -*/ + diff --git a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java index ecd7822f..c5f30b90 100644 --- a/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java @@ -6,9 +6,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) public class BlackJackPlayerTest { diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java index fdc9347f..35984e4a 100644 --- a/src/test/java/io/zipcoder/casino/CrapsTest.java +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -4,12 +4,9 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; - -@RunWith(MockitoJUnitRunner.class) public class CrapsTest { @Test diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index a228b17d..85ccb516 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -5,10 +5,7 @@ import java.util.ArrayList; import java.util.Iterator; -import java.util.Map; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; /*- @@ -46,7 +43,7 @@ public void createGoFishGameTest() throws Exception { @Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenDeckIsNullStartingGame() { goFishGame.setDeck(null); - GoFishPlayer goFishPlayer = mock(GoFishPlayer.class); + GoFishPlayer goFishPlayer = new GoFishPlayer(); goFishGame.startGame(); } @Test From d9b03cebf38846900faed20bcde4b3a859d573bd Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 10:39:25 -0500 Subject: [PATCH 22/30] pom in the way --- pom.xml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pom.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..4305c82a --- /dev/null +++ b/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + io.zipcoder.threedaystodeliver + HumanResourceApp + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 1.5.7.RELEASE + + + + + junit + junit + 4.12 + + + org.springframework.boot + spring-boot-starter-web + + + + + 1.8 + 1.8 + 1.8 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + \ No newline at end of file From 6d6a89fa6c0a50dcd9d046a2322191bdb7955a45 Mon Sep 17 00:00:00 2001 From: amyaim Date: Sun, 26 Nov 2017 11:30:38 -0500 Subject: [PATCH 23/30] cleaning method on counting scores, not yet done --- src/main/java/io/zipcoder/casino/Casino.java | 2 +- src/main/java/io/zipcoder/casino/GoFish.java | 1 + .../java/io/zipcoder/casino/GoFishGame.java | 94 ++++---- .../java/io/zipcoder/casino/GoFishPlayer.java | 2 +- .../java/io/zipcoder/casino/InPutConsole.java | 25 ++- .../io/zipcoder/casino/GoFishGameTest.java | 201 +++++++++--------- .../io/zipcoder/casino/GoFishPlayerTest.java | 131 +++--------- 7 files changed, 212 insertions(+), 244 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 1795ae2c..c1b44b80 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -7,4 +7,4 @@ public class Casino { public static void main(String[] args) { GoFish.goFishRun(); } -} +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index f41fb6df..059373c3 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -29,6 +29,7 @@ public static void goFishRun() { while (!goFishGame.getDeck().isEmpty()) { System.out.println("Insert the rank of the card you want to request: "); String rank = InPutConsole.getInput(); + //goFishGame.checkPlayersCardRequestForGameRule(rank); goFishGame.askComputerHandForACard(rank); goFishGame.playerHandDisplay(); diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 4a3008d5..c45e9795 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -275,7 +275,7 @@ public void removeBookedCard() { public Card checkComputerHandForBook() { int count = 0; - Card card = null;µ + Card card = null; //ArrayList toBeRemoved=new ArrayList<>(); //int score = getGoFishPlayer().getScore(); @@ -318,43 +318,63 @@ public void removeComputerBookedCard() { } -// public void checkPlayersCardRequestForInputBoundary(String input) { -// Boolean checkResult = true; -// if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) -// || (input.toString().toUpperCase().equals("K")) -// || (input.toString().toUpperCase().equals("J")) || -// (input.toString().toUpperCase().equals("Q"))) { -// checkPlayersCardRequestForGameRule(input); -// } else { -// -// System.out.println("Insert proper value"); -// } -// -// } -// -// -// public void checkPlayersCardRequestForGameRule(String input) { -// // Boolean checkresult = false; -// for (int i = 0; i < getPlayerHand().size(); i++) { -// if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { -// askComputerHandForACard(input); -// } -// System.out.println("You cannot request for card not in hand"); -// break; -// -// } -// -// -// } -// -// public void checkInput(String input) { -// + public Boolean checkPlayersCardRequestForInputBoundary(String input) { + Boolean checkResult = false; + if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) + || (input.toString().toUpperCase().equals("K")) + || (input.toString().toUpperCase().equals("J")) || + (input.toString().toUpperCase().equals("Q"))) { + checkResult = true; + checkPlayersCardRequestForGameRule(input); + } else { + checkResult = false; + + } + + + return checkResult; + + } + + + public Boolean checkPlayersCardRequestForGameRule(String input) { + Boolean checkresult = false; + for (int i = 0; i < getPlayerHand().size(); i++) { + if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { + checkresult = true; + //askComputerHandForACard(input); + break; + + } + else { + + checkresult = false; + } + + } // -// while (checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { -// System.out.println("Insert proper value"); -// } -// askComputerHandForACard(input); -// } + return checkresult; + + + } + + public Boolean checkInput(String input) { +Boolean checkResult = false; + + while (checkResult==false) + if( checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { + checkResult = true; + askComputerHandForACard(input); + } + else{ + checkResult = false; + + + } + + return checkResult; + + } public void increaseComputerScore() { diff --git a/src/main/java/io/zipcoder/casino/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/GoFishPlayer.java index 2b002a69..c91c1d53 100644 --- a/src/main/java/io/zipcoder/casino/GoFishPlayer.java +++ b/src/main/java/io/zipcoder/casino/GoFishPlayer.java @@ -11,7 +11,7 @@ public class GoFishPlayer extends CardPlayer { private String name; private ArrayList hand; - public GoFishPlayer(){super();}; + public GoFishPlayer(){super();} @Override public int getScore() { diff --git a/src/main/java/io/zipcoder/casino/InPutConsole.java b/src/main/java/io/zipcoder/casino/InPutConsole.java index ce40ae60..ffc98070 100644 --- a/src/main/java/io/zipcoder/casino/InPutConsole.java +++ b/src/main/java/io/zipcoder/casino/InPutConsole.java @@ -6,10 +6,31 @@ public class InPutConsole { static Scanner scanner = new Scanner(System.in); - private InPutConsole(){} + private InPutConsole() { + } public static String getInput(){ - return scanner.nextLine().toUpperCase(); + return scanner.nextLine(); } + +// public static String getCardInput() { +// String input = ""; +// GoFishGame goFishGame = new GoFishGame(); +// input = scanner.nextLine().toUpperCase(); +// Boolean checkResult = false; +// while (checkResult == false) { +// if (goFishGame.checkPlayersCardRequestForGameRule(input)==true) { +// checkResult = true; +// break; +// } else { +// System.out.println("You cannot request for card not in hand. Insert the card you want "); +// input = scanner.nextLine().toUpperCase(); +// checkResult = false; +// } +// +// } +// return input; +// } } + diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index a228b17d..8bfcfd1d 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -95,57 +95,28 @@ public void deckSizeDecreaseAfterDeal() throws Exception { @Test public void playerHandDisplayTest() { -// Card card = new Card(Rank.EIGHT, Suit.SPADE); -// Card card1 = new Card(Rank.SEVEN, Suit.CLUB); -// Card card3 = new Card(Rank.SEVEN, Suit.HEART); -// Card card2 = new Card(Rank.ACE, Suit.CLUB); -// ArrayList playerHand1 = new ArrayList<>(); -// playerHand1.add(card); -// playerHand1.add(card1); -// playerHand1.add(card2); -// playerHand1.add(card3); -// -// goFishGame.setPlayerHand(playerHand1); -// -// String expected = "You have {7=1, 8=1}"; -// -// String actual = goFishGame.playerHandDisplay().toString(); -// -// // Map playerMap = goFishGame.playerHandDisplay(); -// ArrayList cards = goFishGame.playerHand(); -// // System.out.println(playerMap.values()); -// System.out.println(cards.size()); - - // String[] rank = {"7", "8","9", "10", "J"}; - - // for (int i = 0; i < goFishGame.getPlayerHand().size()-1; i++) { - // String rank = goFishGame.getComputerHand().get(i).getRank().getSymbol(); - // for (Iterator iter = cards.iterator(); iter.hasNext(); ){ - // Rank rank = iter.next().getRank(); - // for(int i =0; i cards = goFishGame.playerHand(); - while(z it = cards.iterator(); it.hasNext(); ) { + Card card = new Card(Rank.EIGHT, Suit.SPADE); + Card card1 = new Card(Rank.SEVEN, Suit.CLUB); + Card card3 = new Card(Rank.SEVEN, Suit.HEART); + Card card2 = new Card(Rank.ACE, Suit.CLUB); + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card); + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + + goFishGame.setPlayerHand(playerHand1); + + String expected = "You have {7=1, 8=1}"; - if (it.next().getRank().getSymbol().equalsIgnoreCase(rank)) { - count++; - if (count == 3) - score++; - it.remove(); + String actual = goFishGame.playerHandDisplay().toString(); + + // Map playerMap = goFishGame.playerHandDisplay(); + ArrayList cards = goFishGame.playerHand(); + // System.out.println(playerMap.values()); + System.out.println(cards.size()); - } - } - z++; - } - System.out.println("count is " + count); - System.out.println("score is " + score); - System.out.println(cards); } @@ -190,26 +161,26 @@ public void checkComputerHandForPlayerRequestedCardRank() { Assert.assertEquals(expected, actual); } - /* @Test - public void checkPlayerCanTakeCardFromComputerTest() { // tested by viewing the console and passed the test. - goFishGame.getDeck(); - goFishGame.playerHand(); - Card card0 = new Card(Rank.SIX, Suit.SPADE); - Card card = new Card(Rank.SEVEN, Suit.SPADE); - - - ArrayList computerHand1 = new ArrayList<>(); - computerHand1.add(card0); - computerHand1.add(card); - - - goFishGame.setComputerHand(computerHand1); - - String expected = " The computer has 7\nYour hand is [5♧, 10♤, 9♧, 3♧, 6♢, 9♢, J♧, 7♧]\n" + - "Insert the next card you want: "; - - goFishGame.askComputerHandForACard("7"); - }*/ +// @Test +// public void checkPlayerCanTakeCardFromComputerTest() { // tested by viewing the console and passed the test. +// goFishGame.getDeck(); +// goFishGame.playerHand(); +// Card card0 = new Card(Rank.SIX, Suit.SPADE); +// Card card = new Card(Rank.SEVEN, Suit.SPADE); +// +// +// ArrayList computerHand1 = new ArrayList<>(); +// computerHand1.add(card0); +// computerHand1.add(card); +// +// +// goFishGame.setComputerHand(computerHand1); +// +// String expected = " The computer has 7\nYour hand is [5♧, 10♤, 9♧, 3♧, 6♢, 9♢, J♧, 7♧]\n" + +// "Insert the next card you want: "; +// +// goFishGame.askComputerHandForACard("7"); +// } @Test @@ -237,43 +208,65 @@ public void computerDecisionForCardTest() { } -// @Test -// -// public void checkPlayersCardRequestForInputBoundary() { -// Card card1 = new Card(Rank.SIX, Suit.HEART); -// Card card = new Card(Rank.SEVEN, Suit.DIAMOND); -// ArrayList playerHand1 = new ArrayList<>(); -// playerHand1.add(card1); -// playerHand1.add(card); -// -// goFishGame.setPlayerHand(playerHand1); -// Boolean expected = true; -// Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); -// Assert.assertEquals(expected, actual); -// Boolean expected2 = false; -// Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); -// Assert.assertEquals(expected2, actual2); -// } + @Test -// @Test -// public void checkPlayersCardRequestForGameRuleTest(){ -// Card card1 = new Card(Rank.SIX, Suit.HEART); -// Card card = new Card(Rank.SEVEN, Suit.DIAMOND); -// -// ArrayList playerHand1 = new ArrayList<>(); -// playerHand1.add(card1); -// playerHand1.add(card); -// -// goFishGame.setPlayerHand(playerHand1); -// -// Boolean expected = false; -// Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); -// Assert.assertEquals(expected, actual); -// -// Boolean expected2 = true; -// Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); -// Assert.assertEquals(expected2, actual2); -// } + public void checkPlayersCardRequestForInputBoundary() { + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card = new Card(Rank.SEVEN, Suit.DIAMOND); + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card); + + goFishGame.setPlayerHand(playerHand1); + Boolean expected = true; + Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); + Assert.assertEquals(expected, actual); + Boolean expected2 = false; + Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); + Assert.assertEquals(expected2, actual2); + } + + @Test + public void checkPlayersCardRequestForGameRuleTest(){ + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card = new Card(Rank.SEVEN, Suit.DIAMOND); + + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card); + + goFishGame.setPlayerHand(playerHand1); + + Boolean expected = false; + Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); + Assert.assertEquals(expected, actual); + Boolean actual3 = playerHand1.get(1).getRank().getSymbol().equalsIgnoreCase("7"); + + Boolean expected2 = true; + Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); + Assert.assertEquals(expected2, actual2); + } + + @Test + public void checkInputTest(){ + Card card1 = new Card(Rank.SIX, Suit.HEART); + Card card = new Card(Rank.SEVEN, Suit.DIAMOND); + + ArrayList playerHand1 = new ArrayList<>(); + playerHand1.add(card1); + playerHand1.add(card); + + goFishGame.setPlayerHand(playerHand1); + + Boolean expected = false; + Boolean actual = goFishGame.checkInput("10"); + Assert.assertEquals(expected, actual); + Boolean actual3 = playerHand1.get(1).getRank().getSymbol().equalsIgnoreCase("7"); + + Boolean expected2 = true; + Boolean actual2 = goFishGame.checkInput("7"); + Assert.assertEquals(expected2, actual2); + } @Test diff --git a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java index ccd1848f..669d288f 100644 --- a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java @@ -1,99 +1,32 @@ -//package io.zipcoder.casino; -// -//import org.junit.Assert; -//import org.junit.Test; -//import org.junit.experimental.theories.suppliers.TestedOn; -// -//import java.util.ArrayList; -// -//import static org.junit.Assert.*; -// -//public class GoFishPlayerTest { -// @Test -// public void checkHandForCard() throws Exception { -// GoFishGame gameOn = new GoFishGame(); -// GoFishPlayer player1 = new GoFishPlayer(); -// -// String expected = ""; -// for(int i=0; i<5;i++){ -// Card card = player1.drawCard(gameOn.getGameDeck()); -// player1.addCardToHand(card); -// expected += card.getRank() + " of " +card.getSuit()+"s\n"; -// } -// -// Rank rank = player1.getHand().get(3).getRank(); -// -// System.out.println(expected); -// Assert.assertTrue(player1.checkHandForCard(rank)); -// -// } -// -// @Test -// public void giveCard() throws Exception { -// GoFishGame gameOn = new GoFishGame(); -// GoFishPlayer player1 = new GoFishPlayer(); -// -// String expected = ""; -// for(int i=0; i<5;i++){ -// Card card = player1.drawCard(gameOn.getGameDeck()); -// player1.addCardToHand(card); -// expected += card.getRank() + " of " +card.getSuit()+"s\n"; -// } -// -// System.out.println(expected); -// -// Rank rank = player1.getHand().get(3).getRank(); -// Card myCard = player1.giveCard(rank); -// -// Assert.assertEquals(myCard.getRank(), rank); -// -// } -// -// @Test -// public void drawCard() throws Exception { -// GoFishGame gameOn = new GoFishGame(); -// GoFishPlayer player1 = new GoFishPlayer(); -// -// gameOn.addPlayer(player1); -// -// for(int i = 0; i < 52; i++){ -// Card expectedCard = gameOn.getGameDeck().getCards().get(0); -// Card actualCard = player1.drawCard(gameOn.getGameDeck()); -// //System.out.println(gameOn.getGameDeck().getDeckSize()); -// Assert.assertEquals(expectedCard,actualCard); -// } -// } -// -// @Test -// public void checkFourOfAKindTest(){ -// Card someClub = new Card(Rank.EIGHT,Suit.CLUB); -// GoFishPlayer somePlayer = new GoFishPlayer(); -// -// for(int i =0; i<4;i++){ -// somePlayer.addCardToHand(someClub); -// } -// somePlayer.addCardToHand(new Card(Rank.ACE,Suit.HEART)); -// -// Assert.assertEquals(somePlayer.checkFourOfAKind(), Suit.CLUB); -// -// } -// -// @Test -// public void drawFiveCardsTest(){ -// GoFishPlayer somePlayer = new GoFishPlayer(); -// GoFishGame gameOn = new GoFishGame(); -// -// somePlayer.drawFiveCards(gameOn.getGameDeck()); -// -// ArrayList hand = somePlayer.getHand(); -// -// -// for(Card card:hand){ -// String expected = card.getRank() + " of " +card.getSuit()+"s"; -// System.out.println(expected); -// } -// -// -// } -// -//} \ No newline at end of file +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class GoFishPlayerTest { + + GoFishPlayer goFishPlayer = new GoFishPlayer(); + @Test + public void getAndSetScore() throws Exception { + + goFishPlayer.setScore(2); + + int expeted = 2; + + int actual = goFishPlayer.getScore(); + + Assert.assertEquals(expeted, actual); + } + + @Test + public void getAndSetName() throws Exception { + goFishPlayer.setName("me"); + String expected ="me"; + String actual = goFishPlayer.getName(); + Assert.assertEquals(expected,actual); + } + + +} \ No newline at end of file From b966ea829924312ef64be37d058c718784101b6b Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 12:48:34 -0500 Subject: [PATCH 24/30] added book count method --- .../java/io/zipcoder/casino/GoFishGame.java | 19 +++++++++++++++++++ .../io/zipcoder/casino/GoFishGameTest.java | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 431690ed..68ce6ab3 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -408,6 +408,25 @@ public ArrayList getComputerHand() { public GoFishPlayer getComputerPlayer() { return computerPlayer; } + + public Integer countBooksInPlayerHand() { + ArrayList hand = getPlayerHand(); + List cardsByRank = new ArrayList<>(); + + for(Card card : hand){ + cardsByRank.add(card.getRank().getSymbol()); + } + + Set uniqueSet = new HashSet<>(cardsByRank); + Integer count = 0; + + for (String rank : uniqueSet) { + if(Collections.frequency(cardsByRank,rank)>3){ + count++; + } + } + return count; + } } diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index 85ccb516..19a684c9 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -318,12 +318,12 @@ public void goFishingComputerTest(){ public void playerHandBookTest(){ Card card1 = new Card(Rank.TWO, Suit.CLUB); - Card card2 = new Card(Rank.TWO, Suit.HEART); + Card card2 = new Card(Rank.THREE, Suit.HEART); Card card3 = new Card(Rank.TWO, Suit.DIAMOND); Card card4 = new Card(Rank.TWO, Suit.SPADE); Card card5 = new Card(Rank.THREE, Suit.SPADE); Card card6 = new Card(Rank.THREE, Suit.CLUB); - Card card7 = new Card(Rank.THREE, Suit.HEART); + Card card7 = new Card(Rank.TWO, Suit.HEART); Card card8 = new Card(Rank.THREE, Suit.SPADE); ArrayList playerHand1 = new ArrayList<>(); @@ -339,8 +339,8 @@ public void playerHandBookTest(){ System.out.println(playerHand1.size()); goFishGame.setPlayerHand(playerHand1); - // goFishGame.checkPlayerHandForBook(); - goFishGame.removeBookedCard(); + System.out.println(goFishGame.countBooksInPlayerHand()); + // goFishGame.removeBookedCard(); System.out.println(playerHand1.size()); System.out.println(goFishGame.getGoFishPlayer().getScore()); From 3318843d7576d999d87e253e38edeca12ff64752 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 13:29:53 -0500 Subject: [PATCH 25/30] mod book count method to return rank --- src/main/java/io/zipcoder/casino/GoFishGame.java | 6 +++--- src/test/java/io/zipcoder/casino/GoFishGameTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 68ce6ab3..ff1114e5 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -409,7 +409,7 @@ public GoFishPlayer getComputerPlayer() { return computerPlayer; } - public Integer countBooksInPlayerHand() { + public String countBooksInPlayerHand() { ArrayList hand = getPlayerHand(); List cardsByRank = new ArrayList<>(); @@ -422,10 +422,10 @@ public Integer countBooksInPlayerHand() { for (String rank : uniqueSet) { if(Collections.frequency(cardsByRank,rank)>3){ - count++; + return rank; } } - return count; + return null; } } diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index 19a684c9..ba0cb131 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -359,10 +359,10 @@ public void playerScoreTest(){ int score =0; Card card1 = new Card(Rank.TWO, Suit.CLUB); Card card2 = new Card(Rank.TWO, Suit.HEART); - Card card3 = new Card(Rank.TWO, Suit.DIAMOND); + Card card3 = new Card(Rank.THREE, Suit.DIAMOND); Card card4 = new Card(Rank.TWO, Suit.SPADE); Card card5 = new Card(Rank.THREE, Suit.SPADE); - Card card6 = new Card(Rank.THREE, Suit.CLUB); + Card card6 = new Card(Rank.TWO, Suit.CLUB); Card card7 = new Card(Rank.THREE, Suit.HEART); Card card8 = new Card(Rank.THREE, Suit.SPADE); From af71d46f3cf9545d4e3ec9dd2f7b9c550ed5a175 Mon Sep 17 00:00:00 2001 From: amyaim Date: Sun, 26 Nov 2017 15:08:49 -0500 Subject: [PATCH 26/30] working --- src/main/java/io/zipcoder/casino/GoFish.java | 45 +++--- .../java/io/zipcoder/casino/GoFishGame.java | 137 +++++++++++++----- .../io/zipcoder/casino/GoFishGameTest.java | 89 ++++++++---- 3 files changed, 177 insertions(+), 94 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 059373c3..1380219f 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -11,51 +11,44 @@ public class GoFish extends GoFishGame { public static void goFishRun() { - - - - - - int i =0; - - do { + String response = "no"; System.out.print("Welcome to the table!\n" + "Insert nick name you want to use for the game? \n\n"); goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); - goFishGame.startGame(); - goFishGame.playerHand(); - goFishGame.computerHand(); + do{ goFishGame.startGame(); + // goFishGame.playerHand(); + // goFishGame.computerHand(); while (!goFishGame.getDeck().isEmpty()) { System.out.println("Insert the rank of the card you want to request: "); String rank = InPutConsole.getInput(); - //goFishGame.checkPlayersCardRequestForGameRule(rank); - goFishGame.askComputerHandForACard(rank); + + // goFishGame.removeBookedCard(); goFishGame.playerHandDisplay(); goFishGame.goFishingPlayer(); - // goFishGame.removeBookedCard(); goFishGame.checkIfComputerHandHasAcard(); goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); goFishGame.goFishingComputer(); + // goFishGame.countBooksInComputerHand(); + // goFishGame.removeBookedCard(); // goFishGame.removeComputerBookedCard(); + //goFishGame.checkPlayersCardRequestForGameRule(rank); + // goFishGame.removeBookedCard(); } - System.out.println("The deck has finished"); - System.out.println("Computer score is " + goFishGame.getComputerPlayer().getScore()); - System.out.println(goFishGame.getGoFishPlayer().getName() + " score is " + goFishGame.getGoFishPlayer().getScore()); + + System.out.println("The game is over. Computer score is " + + goFishGame.countBooksInComputerHand()); + System.out.println(goFishGame.getGoFishPlayer().getName() + + " score is " + goFishGame.countBooksInPlayerHand()); goFishGame.decideWiner(); System.out.println("Do you want to play again?"); - String response = InPutConsole.getInput(); - if (response.toUpperCase().equalsIgnoreCase("yes")){ - GoFish.goFishRun(); - - } + response = InPutConsole.getInput(); +// if (response.toUpperCase().equalsIgnoreCase("yes")){ +// goFishGame.startGame(); - else{ - i=1; - } - } while (i==0); + } while (response.equalsIgnoreCase("yes")); System.out.println("Bye bye, visit us again"); } diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index c45e9795..68a90381 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -26,6 +26,9 @@ public GoFishGame() { public void startGame() { + new Deck().getDeck(); + playerHand(); + computerHand(); if (goFishPlayer == null || deck == null || playerHand == null) { throw new IllegalStateException("Game tools doesnt exist"); @@ -112,7 +115,7 @@ public void askComputerHandForACard(String rank) { if (rank.equals(card.getRank().getSymbol())) cards.add(card); } getPlayerHand().addAll(cards); - removeBookedCard(); + removeBookedCard(); getComputerHand().removeAll(cards); cards = new ArrayList<>(); @@ -196,7 +199,7 @@ public ArrayList askPlayerForACard(String rank) { "The card is added to the computer hand"); getComputerHand().addAll(cards); getPlayerHand().removeAll(cards); - removeComputerBookedCard(); + // removeComputerBookedCard(); cards = new ArrayList<>(); rank = computerCardToRequest(); checkPlayerHasRequestedCardRank(rank); @@ -227,11 +230,69 @@ public Map playerHandDisplay() { return result; } + public Integer countBooksInPlayerHand() { + ArrayList hand = getPlayerHand(); + List cardsByRank = new ArrayList<>(); + + for(Card card : hand){ + cardsByRank.add(card.getRank().getSymbol()); + } + + Set uniqueSet = new HashSet<>(cardsByRank); + Integer count = 0; + + for (String rank : uniqueSet) { + if(Collections.frequency(cardsByRank,rank)>3){ + count++; + } + } + return count; + } + + public String playerHandCardToBeRemoved() { + ArrayList hand = getPlayerHand(); + List cardsByRank = new ArrayList<>(); + + for(Card card : hand){ + cardsByRank.add(card.getRank().getSymbol()); + } + + Set uniqueSet = new HashSet<>(cardsByRank); + Integer count = 0; + + for (String rank : uniqueSet) { + if(Collections.frequency(cardsByRank,rank)>3){ + return rank; + } + } + return null; + } + public Integer countBooksInComputerHand() { + Integer count = 0; + ArrayList hand = getComputerHand(); + List cardsByRank = new ArrayList<>(); + + for(Card card : hand){ + cardsByRank.add(card.getRank().getSymbol()); + } + + Set uniqueSet = new HashSet<>(cardsByRank); + + + for (String rank : uniqueSet) { + if(Collections.frequency(cardsByRank,rank)>3){ + count++; + } + } + return count; + } + + public Card checkPlayerHandForBook() { int count = 0; Card card = null; - //ArrayList toBeRemoved=new ArrayList<>(); + ArrayList toBeRemoved=new ArrayList<>(); //int score = getGoFishPlayer().getScore(); for (int i = 0; i < getPlayerHand().size(); i++) { @@ -242,19 +303,23 @@ public Card checkPlayerHandForBook() { found = true; count++; - if (count == 4) + if (count == 4) { card = getPlayerHand().get(i); + int score = getGoFishPlayer().getScore() + 1; + goFishPlayer.setScore(score); + // System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); + } } } - //System.out.println("You booked " + card.getRank().getSymbol() + - // ". Your score is " + score); + + return card; } public void removeBookedCard() { try { - String cardTobeRemoved = checkPlayerHandForBook().getRank().getSymbol(); + String cardTobeRemoved = playerHandCardToBeRemoved(); ArrayList tobeRemovedList = new ArrayList<>(); Card card = null; @@ -265,9 +330,9 @@ public void removeBookedCard() { } getPlayerHand().removeAll(tobeRemovedList); - int score = getGoFishPlayer().getScore() + 1; - goFishPlayer.setScore(score); - System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); + // int score = getGoFishPlayer().getScore() + 1; + // goFishPlayer.setScore(score); + // System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); } catch (Exception e) { } @@ -309,9 +374,9 @@ public void removeComputerBookedCard() { } getComputerHand().removeAll(tobeRemovedList); - int score = getComputerPlayer().getScore() + 1; - computerPlayer.setScore(score); - System.out.println("computer score is " + getComputerPlayer().getScore()); + // int score = getComputerPlayer().getScore() + 1; + // computerPlayer.setScore(score); + // System.out.println("computer score is " + getComputerPlayer().getScore()); } catch (Exception e) { System.out.println("card cant be removed"); } @@ -377,32 +442,32 @@ public Boolean checkInput(String input) { } - public void increaseComputerScore() { - int computerSameRankCardCount = 0; - int computerScore = computerPlayer.getScore(); - Card card = null; - - for (int i = 0; i < getComputerHand().size() - 1; i++) { - card = getComputerHand().get(i); - for (int j = i + 1; j < getComputerHand().size() - 1; j++) - if (card.getRank() == getComputerHand().get(j).getRank()) { - computerSameRankCardCount++; - if (computerSameRankCardCount == 2) - computerScore += 1; - - } - - } - System.out.println("Computer score is " + computerScore); - - } +// public void increaseComputerScore() { +// int computerSameRankCardCount = 0; +// int computerScore = computerPlayer.getScore(); +// Card card = null; +// +// for (int i = 0; i < getComputerHand().size() - 1; i++) { +// card = getComputerHand().get(i); +// for (int j = i + 1; j < getComputerHand().size() - 1; j++) +// if (card.getRank() == getComputerHand().get(j).getRank()) { +// computerSameRankCardCount++; +// if (computerSameRankCardCount == 2) +// computerScore += 1; +// +// } +// +// } +// System.out.println("Computer score is " + computerScore); +// +// } public void decideWiner() { - if (computerPlayer.getScore() > goFishPlayer.getScore()) - System.out.println("nayyy! The machine won"); - else if (computerPlayer.getScore() < goFishPlayer.getScore()) + if (countBooksInComputerHand() > countBooksInPlayerHand()) + System.out.println(" Sorry! the machine won"); + else if (countBooksInComputerHand() < countBooksInPlayerHand()) System.out.println("Wow, you won! Congrats!!!"); - else if (computerPlayer.getScore() == goFishPlayer.getScore()) + else if (countBooksInPlayerHand()== countBooksInComputerHand()) System.out.println("The game is tie! try again"); else System.out.println("Sorry the score is not yet available. Please check again"); diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index 8bfcfd1d..3e7bf695 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -310,9 +310,48 @@ public void goFishingComputerTest(){ } +// @Test +// +// public void playerHandBookTest(){ +// Card card1 = new Card(Rank.TWO, Suit.CLUB); +// Card card2 = new Card(Rank.TWO, Suit.HEART); +// Card card3 = new Card(Rank.TWO, Suit.DIAMOND); +// Card card4 = new Card(Rank.TWO, Suit.SPADE); +// Card card5 = new Card(Rank.THREE, Suit.SPADE); +// Card card6 = new Card(Rank.THREE, Suit.CLUB); +// Card card7 = new Card(Rank.THREE, Suit.HEART); +// +// +// ArrayList playerHand1 = new ArrayList<>(); +// playerHand1.add(card1); +// playerHand1.add(card2); +// playerHand1.add(card3); +// playerHand1.add(card4); +// playerHand1.add(card5); +// playerHand1.add(card6); +// playerHand1.add(card7); +// +// int actual = 7; +// int expected1= playerHand1.size(); +// goFishGame.setPlayerHand(playerHand1); +// +// // goFishGame.checkPlayerHandForBook(); +// goFishGame.removeBookedCard(); +// System.out.println(goFishGame.countBooksInPlayerHand()); +// +// int actual2= playerHand1.size(); +// int expected =3; +// +// +// +// +// } + @Test - public void playerHandBookTest(){ + public void playerScoreTest(){ + Player player = goFishGame.getGoFishPlayer(); + int score =0; Card card1 = new Card(Rank.TWO, Suit.CLUB); Card card2 = new Card(Rank.TWO, Suit.HEART); Card card3 = new Card(Rank.TWO, Suit.DIAMOND); @@ -335,32 +374,29 @@ public void playerHandBookTest(){ System.out.println(playerHand1.size()); goFishGame.setPlayerHand(playerHand1); - // goFishGame.checkPlayerHandForBook(); - goFishGame.removeBookedCard(); + // goFishGame.checkPlayerHandForBook(); + System.out.println(goFishGame.checkPlayerHandForBook()); System.out.println(playerHand1.size()); - System.out.println(goFishGame.getGoFishPlayer().getScore()); - // System.out.println(playerHand1.get(0)); - // System.out.println(playerHand1); + System.out.println(playerHand1); + System.out.println(score); + // System.out.println(playerHand1.get(0)); + // System.out.println(playerHand1); } - @Test - - public void playerScoreTest(){ - Player player = goFishGame.getGoFishPlayer(); - int score =0; - Card card1 = new Card(Rank.TWO, Suit.CLUB); - Card card2 = new Card(Rank.TWO, Suit.HEART); - Card card3 = new Card(Rank.TWO, Suit.DIAMOND); - Card card4 = new Card(Rank.TWO, Suit.SPADE); - Card card5 = new Card(Rank.THREE, Suit.SPADE); - Card card6 = new Card(Rank.THREE, Suit.CLUB); - Card card7 = new Card(Rank.THREE, Suit.HEART); - Card card8 = new Card(Rank.THREE, Suit.SPADE); + public void playerHandBookTest() { + Card card1 = new Card(Rank.TWO , Suit.CLUB); + Card card2 = new Card(Rank.THREE , Suit.HEART); + Card card3 = new Card(Rank.TWO , Suit.DIAMOND); + Card card4 = new Card(Rank.TWO , Suit.SPADE); + Card card5 = new Card(Rank.THREE , Suit.SPADE); + Card card6 = new Card(Rank.THREE , Suit.CLUB); + Card card7 = new Card(Rank.TWO , Suit.HEART); + Card card8 = new Card(Rank.THREE , Suit.SPADE); ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); @@ -375,20 +411,9 @@ public void playerScoreTest(){ System.out.println(playerHand1.size()); goFishGame.setPlayerHand(playerHand1); - // goFishGame.checkPlayerHandForBook(); - System.out.println(goFishGame.checkPlayerHandForBook()); - - System.out.println(playerHand1.size()); - System.out.println(playerHand1); - System.out.println(score); - // System.out.println(playerHand1.get(0)); - // System.out.println(playerHand1); - - - - + System.out.println(goFishGame.countBooksInPlayerHand()); + // goFishGame.removeBookedCard(); } - @Test public void decideWinnerTest() { goFishGame.getComputerPlayer().setScore(10); From a71107f0a7279bb0980976967da51f71eecab0b5 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 18:12:13 -0500 Subject: [PATCH 27/30] goFish noodling --- src/main/java/io/zipcoder/casino/GoFishGame.java | 1 + src/test/java/io/zipcoder/casino/GoFishGameTest.java | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index ff1114e5..a43d0c29 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -318,6 +318,7 @@ public void removeComputerBookedCard() { } + // public void checkPlayersCardRequestForInputBoundary(String input) { // Boolean checkResult = true; // if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index ba0cb131..b6493ed1 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -318,11 +318,11 @@ public void goFishingComputerTest(){ public void playerHandBookTest(){ Card card1 = new Card(Rank.TWO, Suit.CLUB); - Card card2 = new Card(Rank.THREE, Suit.HEART); - Card card3 = new Card(Rank.TWO, Suit.DIAMOND); - Card card4 = new Card(Rank.TWO, Suit.SPADE); Card card5 = new Card(Rank.THREE, Suit.SPADE); + Card card3 = new Card(Rank.TWO, Suit.DIAMOND); Card card6 = new Card(Rank.THREE, Suit.CLUB); + Card card4 = new Card(Rank.TWO, Suit.SPADE); + Card card2 = new Card(Rank.THREE, Suit.HEART); Card card7 = new Card(Rank.TWO, Suit.HEART); Card card8 = new Card(Rank.THREE, Suit.SPADE); @@ -340,8 +340,7 @@ public void playerHandBookTest(){ goFishGame.setPlayerHand(playerHand1); System.out.println(goFishGame.countBooksInPlayerHand()); - // goFishGame.removeBookedCard(); - + goFishGame.removeAllOfARankFromHand(Rank.THREE); System.out.println(playerHand1.size()); System.out.println(goFishGame.getGoFishPlayer().getScore()); // System.out.println(playerHand1.get(0)); From 6380ae44ef0dbb092a983d46f5bc1c1c3141216b Mon Sep 17 00:00:00 2001 From: amyaim Date: Sun, 26 Nov 2017 19:10:39 -0500 Subject: [PATCH 28/30] still need cleaning --- src/main/java/io/zipcoder/casino/GoFish.java | 122 +++------- .../java/io/zipcoder/casino/GoFishGame.java | 135 ++++------- .../io/zipcoder/casino/GoFishGameTest.java | 225 +++++++----------- .../java/io/zipcoder/casino/GoFishTest.java | 25 ++ 4 files changed, 189 insertions(+), 318 deletions(-) create mode 100644 src/test/java/io/zipcoder/casino/GoFishTest.java diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 1380219f..dd13d180 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -7,99 +7,41 @@ public class GoFish extends GoFishGame { Scanner scanner = new Scanner(System.in); - static GoFishGame goFishGame = new GoFishGame(); - public static void goFishRun() { - - String response = "no"; - System.out.print("Welcome to the table!\n" + - "Insert nick name you want to use for the game? \n\n"); - goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); - do{ goFishGame.startGame(); - // goFishGame.playerHand(); - // goFishGame.computerHand(); - - while (!goFishGame.getDeck().isEmpty()) { - System.out.println("Insert the rank of the card you want to request: "); - String rank = InPutConsole.getInput(); - goFishGame.askComputerHandForACard(rank); - - // goFishGame.removeBookedCard(); - goFishGame.playerHandDisplay(); - goFishGame.goFishingPlayer(); - goFishGame.checkIfComputerHandHasAcard(); - goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); - goFishGame.goFishingComputer(); - // goFishGame.countBooksInComputerHand(); - // goFishGame.removeBookedCard(); - // goFishGame.removeComputerBookedCard(); - //goFishGame.checkPlayersCardRequestForGameRule(rank); - // goFishGame.removeBookedCard(); - } - - System.out.println("The game is over. Computer score is " + - goFishGame.countBooksInComputerHand()); - System.out.println(goFishGame.getGoFishPlayer().getName() + - " score is " + goFishGame.countBooksInPlayerHand()); - goFishGame.decideWiner(); - System.out.println("Do you want to play again?"); - response = InPutConsole.getInput(); -// if (response.toUpperCase().equalsIgnoreCase("yes")){ -// goFishGame.startGame(); + public static void goFishRun() { - } while (response.equalsIgnoreCase("yes")); + String response = "no"; + System.out.print("Welcome to the table!\n" + + "Insert nick name you want to use for the game? \n\n"); + + do { + + GoFishGame goFishGame = new GoFishGame(); + goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); + goFishGame.startGame(); + goFishGame.playerHand(); + goFishGame.computerHand(); + + while (!goFishGame.getDeck().isEmpty()) { + System.out.println("Insert the rank of the card you want to request: "); + String rank = InPutConsole.getInput(); + goFishGame.checkInput(rank); + goFishGame.askComputerHandForACard(rank); + goFishGame.playerHandDisplay(); + goFishGame.goFishingPlayer(); + goFishGame.checkIfComputerHandHasAcard(); + goFishGame.askPlayerForACard(goFishGame.computerCardToRequest()); + goFishGame.goFishingComputer(); + + } + + System.out.println("The game is over"); + goFishGame.decideWiner(); + System.out.println("Do you want to play again?"); + response = InPutConsole.getInput(); + } while (response.equalsIgnoreCase("yes")); System.out.println("Bye bye, visit us again"); } - /* public void playGoFish( - - do { - - game.player1turn(); - - player1.askForCard(); - if player2hascard - getCard - player1turn; - check for pairs - checkdeckempty - else player2doesnthave card - GOFISH. player1 draws card - - player2turn(); - - player1.askForCard(); - if player2hascard - getCard - player2turn; - check for pairs - checkdeckempty - else player2doesnthave card - GOFISH. player1 draws card - } - */ - -// public void playerTurn(ArrayList players){ -// System.out.println(players.get(0).getName()+ " your turn."); -// -// Rank rank = getRankInput(); -// -// System.out.println(rank); -// } -// -// -// public Rank getRankInput(){ -// Scanner scan = new Scanner(System.in); -// -// do { -// String stringInput = scan.nextLine(); -// for (Rank rank : Rank.values()) { -// if (rank.toString().equalsIgnoreCase(stringInput)) { -// return rank; -// } -// } -// System.out.println("Please enter a valid card."); -// } while (true); -// } -} +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 68a90381..6f6731ea 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -26,9 +26,7 @@ public GoFishGame() { public void startGame() { - new Deck().getDeck(); - playerHand(); - computerHand(); + if (goFishPlayer == null || deck == null || playerHand == null) { throw new IllegalStateException("Game tools doesnt exist"); @@ -106,8 +104,6 @@ public Boolean checkComputerHandForPlayerRequestedCard(String rank) { public void askComputerHandForACard(String rank) { ArrayList cards = new ArrayList<>(); - // if (checkComputerHandForPlayerRequestedCard(rank)) { - // System.out.println("The computer has " + rank + ". The card is being added to your hand..."); Card card = null; while (checkComputerHandForPlayerRequestedCard(rank)) { for (int i = 0; i < getComputerHand().size(); i++) { @@ -115,7 +111,7 @@ public void askComputerHandForACard(String rank) { if (rank.equals(card.getRank().getSymbol())) cards.add(card); } getPlayerHand().addAll(cards); - removeBookedCard(); + removeBookedCard(); getComputerHand().removeAll(cards); cards = new ArrayList<>(); @@ -129,8 +125,6 @@ public void askComputerHandForACard(String rank) { System.out.println("The computer doesnt have the card. Go Fish!!"); } - //// } - public void goFishingPlayer() { System.out.println(goFishPlayer.getName() + " is fishing"); @@ -199,7 +193,7 @@ public ArrayList askPlayerForACard(String rank) { "The card is added to the computer hand"); getComputerHand().addAll(cards); getPlayerHand().removeAll(cards); - // removeComputerBookedCard(); + removeComputerBookedCard(); cards = new ArrayList<>(); rank = computerCardToRequest(); checkPlayerHasRequestedCardRank(rank); @@ -230,11 +224,12 @@ public Map playerHandDisplay() { return result; } + public Integer countBooksInPlayerHand() { ArrayList hand = getPlayerHand(); List cardsByRank = new ArrayList<>(); - for(Card card : hand){ + for (Card card : hand) { cardsByRank.add(card.getRank().getSymbol()); } @@ -242,7 +237,7 @@ public Integer countBooksInPlayerHand() { Integer count = 0; for (String rank : uniqueSet) { - if(Collections.frequency(cardsByRank,rank)>3){ + if (Collections.frequency(cardsByRank , rank) > 3) { count++; } } @@ -253,7 +248,7 @@ public String playerHandCardToBeRemoved() { ArrayList hand = getPlayerHand(); List cardsByRank = new ArrayList<>(); - for(Card card : hand){ + for (Card card : hand) { cardsByRank.add(card.getRank().getSymbol()); } @@ -261,18 +256,19 @@ public String playerHandCardToBeRemoved() { Integer count = 0; for (String rank : uniqueSet) { - if(Collections.frequency(cardsByRank,rank)>3){ + if (Collections.frequency(cardsByRank , rank) > 3) { return rank; } } return null; } + public Integer countBooksInComputerHand() { - Integer count = 0; + Integer count = 0; ArrayList hand = getComputerHand(); List cardsByRank = new ArrayList<>(); - for(Card card : hand){ + for (Card card : hand) { cardsByRank.add(card.getRank().getSymbol()); } @@ -280,7 +276,7 @@ public Integer countBooksInComputerHand() { for (String rank : uniqueSet) { - if(Collections.frequency(cardsByRank,rank)>3){ + if (Collections.frequency(cardsByRank , rank) > 3) { count++; } } @@ -288,12 +284,10 @@ public Integer countBooksInComputerHand() { } - public Card checkPlayerHandForBook() { int count = 0; Card card = null; - ArrayList toBeRemoved=new ArrayList<>(); - //int score = getGoFishPlayer().getScore(); + ArrayList toBeRemoved = new ArrayList<>(); for (int i = 0; i < getPlayerHand().size(); i++) { boolean found = false; @@ -307,13 +301,11 @@ public Card checkPlayerHandForBook() { card = getPlayerHand().get(i); int score = getGoFishPlayer().getScore() + 1; goFishPlayer.setScore(score); - // System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); } } } - return card; } @@ -330,9 +322,6 @@ public void removeBookedCard() { } getPlayerHand().removeAll(tobeRemovedList); - // int score = getGoFishPlayer().getScore() + 1; - // goFishPlayer.setScore(score); - // System.out.println(getGoFishPlayer().getName() + " score is " + getGoFishPlayer().getScore()); } catch (Exception e) { } @@ -341,8 +330,6 @@ public void removeBookedCard() { public Card checkComputerHandForBook() { int count = 0; Card card = null; - //ArrayList toBeRemoved=new ArrayList<>(); - //int score = getGoFishPlayer().getScore(); for (int i = 0; i < getComputerHand().size(); i++) { boolean found = false; @@ -356,8 +343,6 @@ public Card checkComputerHandForBook() { card = getComputerHand().get(i); } } - //System.out.println("You booked " + card.getRank().getSymbol() + - // ". Your score is " + score); return card; } @@ -374,100 +359,70 @@ public void removeComputerBookedCard() { } getComputerHand().removeAll(tobeRemovedList); - // int score = getComputerPlayer().getScore() + 1; - // computerPlayer.setScore(score); - // System.out.println("computer score is " + getComputerPlayer().getScore()); } catch (Exception e) { System.out.println("card cant be removed"); } } - public Boolean checkPlayersCardRequestForInputBoundary(String input) { - Boolean checkResult = false; - if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) - || (input.toString().toUpperCase().equals("K")) - || (input.toString().toUpperCase().equals("J")) || - (input.toString().toUpperCase().equals("Q"))) { - checkResult = true; - checkPlayersCardRequestForGameRule(input); - } else { - checkResult = false; - - } - - - return checkResult; - - } +// public Boolean checkPlayersCardRequestForInputBoundary(String input) { +// Boolean checkResult = false; +// if ((Integer.parseInt(input) > 2 && Integer.parseInt(input) < 12) +// || (input.toString().toUpperCase().equals("K")) +// || (input.toString().toUpperCase().equals("J")) || +// (input.toString().toUpperCase().equals("Q"))) { +// checkResult = true; +// checkPlayersCardRequestForGameRule(input); +// } else { +// checkResult = false; +// +// } +// +// +// return checkResult; +// +// } public Boolean checkPlayersCardRequestForGameRule(String input) { Boolean checkresult = false; for (int i = 0; i < getPlayerHand().size(); i++) { - if (input.equals(getPlayerHand().get(i).getRank().getSymbol())) { + if (input.toUpperCase().equals(getPlayerHand().get(i).getRank().getSymbol())) { checkresult = true; - //askComputerHandForACard(input); break; - } - else { + } else { checkresult = false; } } -// - return checkresult; + return checkresult; } - public Boolean checkInput(String input) { -Boolean checkResult = false; - - while (checkResult==false) - if( checkPlayersCardRequestForInputBoundary(input) && checkPlayersCardRequestForGameRule(input)) { - checkResult = true; - askComputerHandForACard(input); - } - else{ - checkResult = false; - + public String checkInput(String input) { + Boolean checkResult = false; + while (!checkPlayersCardRequestForGameRule(input)) { + System.out.println("Game rule: Insert card same rank as you have on your hand"); + input = InPutConsole.getInput(); } - return checkResult; + return input; } -// public void increaseComputerScore() { -// int computerSameRankCardCount = 0; -// int computerScore = computerPlayer.getScore(); -// Card card = null; -// -// for (int i = 0; i < getComputerHand().size() - 1; i++) { -// card = getComputerHand().get(i); -// for (int j = i + 1; j < getComputerHand().size() - 1; j++) -// if (card.getRank() == getComputerHand().get(j).getRank()) { -// computerSameRankCardCount++; -// if (computerSameRankCardCount == 2) -// computerScore += 1; -// -// } -// -// } -// System.out.println("Computer score is " + computerScore); -// -// } - public void decideWiner() { + System.out.println("Computer score is " +countBooksInComputerHand() ); + System.out.println("Player score is " +countBooksInPlayerHand() ); if (countBooksInComputerHand() > countBooksInPlayerHand()) - System.out.println(" Sorry! the machine won"); + System.out.println(" The computer won"); else if (countBooksInComputerHand() < countBooksInPlayerHand()) System.out.println("Wow, you won! Congrats!!!"); - else if (countBooksInPlayerHand()== countBooksInComputerHand()) + else if (countBooksInPlayerHand() == countBooksInComputerHand()) System.out.println("The game is tie! try again"); else System.out.println("Sorry the score is not yet available. Please check again"); @@ -482,10 +437,6 @@ public void setComputerHand(ArrayList computerHand) { this.computerHand = computerHand; } - public void setGoFishPlayer(GoFishPlayer goFishPlayer) { - this.goFishPlayer = goFishPlayer; - } - public ArrayList getComputerHand() { return computerHand; } diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index 3e7bf695..5331b711 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -9,25 +9,23 @@ import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; -/*- +public class GoFishGameTest { + GoFishGame goFishGame = new GoFishGame(); + Card card1 = new Card(Rank.TWO, Suit.CLUB); + Card card3 = new Card(Rank.THREE, Suit.SPADE); + Card card2 = new Card(Rank.TWO, Suit.SPADE); + Card card4 = new Card(Rank.THREE, Suit.CLUB); + Card card5 = new Card(Rank.TWO, Suit.HEART); + Card card6 = new Card(Rank.TWO, Suit.DIAMOND); + Card card7 = new Card(Rank.THREE, Suit.HEART); + Card card8 = new Card(Rank.THREE, Suit.SPADE); + ArrayList playerHand1 = new ArrayList<>(); + ArrayList computerHand1 = new ArrayList<>(); --As a gofish player I would like to score a point when I have a book to lay down. - test for the number of cards of the same rank in the player hand - test I have 4 cards of the same Rank, I remove the cards from my hand - test my score incremented one point. - - --As a gofish player I would like to see the final score when the deck is empty. - test which player has the biggest amount of points - - -*/ -public class GoFishGameTest { - GoFishGame goFishGame = new GoFishGame(); @Test public void createGoFishGameTest() throws Exception { @@ -74,7 +72,26 @@ public void computerHandget7CardStartOfGame() { Assert.assertEquals(expectedComputerHandSize, actualComputerhandSize); } + @Test + public void getAndSetPlayerHandTest(){ + playerHand1.add(card1); + playerHand1.add(card2); + goFishGame.setPlayerHand(playerHand1); + int expected = 2; + int actual = goFishGame.getPlayerHand().size(); + } + + @Test + + public void getAndSetComputerHand(){ + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + goFishGame.setComputerHand(playerHand1); + int expected = 3; + int actual = goFishGame.getComputerHand().size(); + } @Test public void deckSizeDecreaseAfterDeal() throws Exception { @@ -94,48 +111,30 @@ public void deckSizeDecreaseAfterDeal() throws Exception { } @Test - public void playerHandDisplayTest() { - Card card = new Card(Rank.EIGHT, Suit.SPADE); - Card card1 = new Card(Rank.SEVEN, Suit.CLUB); - Card card3 = new Card(Rank.SEVEN, Suit.HEART); - Card card2 = new Card(Rank.ACE, Suit.CLUB); + public void playerHandDisplayAndSetPlayerHandTest() { + ArrayList playerHand1 = new ArrayList<>(); - playerHand1.add(card); playerHand1.add(card1); playerHand1.add(card2); - playerHand1.add(card3); goFishGame.setPlayerHand(playerHand1); - String expected = "You have {7=1, 8=1}"; - + String expected = "You have {2=1, 3=1}"; String actual = goFishGame.playerHandDisplay().toString(); - // Map playerMap = goFishGame.playerHandDisplay(); - ArrayList cards = goFishGame.playerHand(); - // System.out.println(playerMap.values()); - System.out.println(cards.size()); - - - - } @Test public void passingCardFromPlayerToComputerTest() { - Card card = new Card(Rank.EIGHT, Suit.SPADE); - Card card1 = new Card(Rank.SEVEN, Suit.CLUB); - Card card2 = new Card(Rank.ACE, Suit.CLUB); - ArrayList computerHand1 = new ArrayList<>(); - computerHand1.add(card); computerHand1.add(card1); + computerHand1.add(card2); goFishGame.setComputerHand(computerHand1); Boolean expected = true; - Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("7"); + Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("2"); Boolean expected2 = false; - Boolean actual2 = goFishGame.checkPlayerHasRequestedCardRank("6"); + Boolean actual2 = goFishGame.checkPlayerHasRequestedCardRank("4"); Assert.assertEquals(expected, actual); Assert.assertEquals(expected2, actual2); } @@ -143,20 +142,14 @@ public void passingCardFromPlayerToComputerTest() { @Test public void checkComputerHandForPlayerRequestedCardRank() { - goFishGame.playerHand(); - Card card0 = new Card(Rank.SIX, Suit.SPADE); - Card card = new Card(Rank.SEVEN, Suit.SPADE); - Card card1 = new Card(Rank.SEVEN, Suit.CLUB); - - ArrayList computerHand1 = new ArrayList<>(); - computerHand1.add(card0); - computerHand1.add(card); computerHand1.add(card1); + computerHand1.add(card2); + computerHand1.add(card3); goFishGame.setComputerHand(computerHand1); Boolean expected = true; - Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("7"); + Boolean actual = goFishGame.checkComputerHandForPlayerRequestedCard("2"); Assert.assertEquals(expected, actual); } @@ -186,21 +179,14 @@ public void checkComputerHandForPlayerRequestedCardRank() { @Test public void computerDecisionForCardTest() { - Card card0 = new Card(Rank.SIX, Suit.SPADE); - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card2 = new Card(Rank.SEVEN, Suit.SPADE); - Card card3 = new Card(Rank.SEVEN, Suit.HEART); - Card card4 = new Card(Rank.SEVEN, Suit.SPADE); - - ArrayList computerHand1 = new ArrayList<>(); - computerHand1.add(card0); + computerHand1.add(card5); computerHand1.add(card1); - computerHand1.add(card2); + computerHand1.add(card6); computerHand1.add(card3); computerHand1.add(card4); goFishGame.setComputerHand(computerHand1); - String expected = "7"; + String expected = "3"; String actual = goFishGame.computerCardToRequest(); @@ -208,63 +194,55 @@ public void computerDecisionForCardTest() { } - @Test - - public void checkPlayersCardRequestForInputBoundary() { - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card = new Card(Rank.SEVEN, Suit.DIAMOND); - ArrayList playerHand1 = new ArrayList<>(); - playerHand1.add(card1); - playerHand1.add(card); +// @Test - goFishGame.setPlayerHand(playerHand1); - Boolean expected = true; - Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); - Assert.assertEquals(expected, actual); - Boolean expected2 = false; - Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); - Assert.assertEquals(expected2, actual2); - } +// public void checkPlayersCardRequestForInputBoundary() { +// Card card1 = new Card(Rank.SIX, Suit.HEART); +// Card card = new Card(Rank.SEVEN, Suit.DIAMOND); +// ArrayList playerHand1 = new ArrayList<>(); +// playerHand1.add(card1); +// playerHand1.add(card); +// +// goFishGame.setPlayerHand(playerHand1); +// Boolean expected = true; +// Boolean actual = goFishGame.checkPlayersCardRequestForInputBoundary("9"); +// Assert.assertEquals(expected, actual); +// Boolean expected2 = false; +// Boolean actual2 = goFishGame.checkPlayersCardRequestForInputBoundary("12"); +// Assert.assertEquals(expected2, actual2); +// } @Test public void checkPlayersCardRequestForGameRuleTest(){ - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card = new Card(Rank.SEVEN, Suit.DIAMOND); - ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); - playerHand1.add(card); + playerHand1.add(card2); goFishGame.setPlayerHand(playerHand1); Boolean expected = false; Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); Assert.assertEquals(expected, actual); - Boolean actual3 = playerHand1.get(1).getRank().getSymbol().equalsIgnoreCase("7"); Boolean expected2 = true; - Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("7"); + Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("2"); Assert.assertEquals(expected2, actual2); } @Test public void checkInputTest(){ - Card card1 = new Card(Rank.SIX, Suit.HEART); - Card card = new Card(Rank.SEVEN, Suit.DIAMOND); - ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); - playerHand1.add(card); + playerHand1.add(card3); goFishGame.setPlayerHand(playerHand1); - Boolean expected = false; - Boolean actual = goFishGame.checkInput("10"); - Assert.assertEquals(expected, actual); - Boolean actual3 = playerHand1.get(1).getRank().getSymbol().equalsIgnoreCase("7"); +// String expected = ""; +// String actual = goFishGame.checkInput("10"); // this test works but looping because the card isnt in the hand. +// Assert.assertEquals(expected, actual); - Boolean expected2 = true; - Boolean actual2 = goFishGame.checkInput("7"); + String expected2 = "2"; + String actual2 = goFishGame.checkInput("2"); Assert.assertEquals(expected2, actual2); } @@ -313,16 +291,7 @@ public void goFishingComputerTest(){ // @Test // // public void playerHandBookTest(){ -// Card card1 = new Card(Rank.TWO, Suit.CLUB); -// Card card2 = new Card(Rank.TWO, Suit.HEART); -// Card card3 = new Card(Rank.TWO, Suit.DIAMOND); -// Card card4 = new Card(Rank.TWO, Suit.SPADE); -// Card card5 = new Card(Rank.THREE, Suit.SPADE); -// Card card6 = new Card(Rank.THREE, Suit.CLUB); -// Card card7 = new Card(Rank.THREE, Suit.HEART); -// // -// ArrayList playerHand1 = new ArrayList<>(); // playerHand1.add(card1); // playerHand1.add(card2); // playerHand1.add(card3); @@ -349,19 +318,10 @@ public void goFishingComputerTest(){ @Test - public void playerScoreTest(){ + public void countPlayerScoreTest(){ Player player = goFishGame.getGoFishPlayer(); int score =0; - Card card1 = new Card(Rank.TWO, Suit.CLUB); - Card card2 = new Card(Rank.TWO, Suit.HEART); - Card card3 = new Card(Rank.TWO, Suit.DIAMOND); - Card card4 = new Card(Rank.TWO, Suit.SPADE); - Card card5 = new Card(Rank.THREE, Suit.SPADE); - Card card6 = new Card(Rank.THREE, Suit.CLUB); - Card card7 = new Card(Rank.THREE, Suit.HEART); - Card card8 = new Card(Rank.THREE, Suit.SPADE); - ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); playerHand1.add(card2); playerHand1.add(card3); @@ -371,34 +331,18 @@ public void playerScoreTest(){ playerHand1.add(card7); playerHand1.add(card8); - System.out.println(playerHand1.size()); goFishGame.setPlayerHand(playerHand1); - // goFishGame.checkPlayerHandForBook(); - System.out.println(goFishGame.checkPlayerHandForBook()); - - System.out.println(playerHand1.size()); - System.out.println(playerHand1); - System.out.println(score); - // System.out.println(playerHand1.get(0)); - // System.out.println(playerHand1); - + int expected = 2; + int actual = goFishGame.countBooksInPlayerHand(); + Assert.assertEquals(expected, actual); } @Test - public void playerHandBookTest() { - Card card1 = new Card(Rank.TWO , Suit.CLUB); - Card card2 = new Card(Rank.THREE , Suit.HEART); - Card card3 = new Card(Rank.TWO , Suit.DIAMOND); - Card card4 = new Card(Rank.TWO , Suit.SPADE); - Card card5 = new Card(Rank.THREE , Suit.SPADE); - Card card6 = new Card(Rank.THREE , Suit.CLUB); - Card card7 = new Card(Rank.TWO , Suit.HEART); - Card card8 = new Card(Rank.THREE , Suit.SPADE); + public void countComputerScoreTest() { - ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); playerHand1.add(card2); playerHand1.add(card3); @@ -408,19 +352,28 @@ public void playerHandBookTest() { playerHand1.add(card7); playerHand1.add(card8); - System.out.println(playerHand1.size()); - goFishGame.setPlayerHand(playerHand1); - - System.out.println(goFishGame.countBooksInPlayerHand()); - // goFishGame.removeBookedCard(); + goFishGame.setComputerHand(playerHand1); + int expected = 2; + int actual = goFishGame.countBooksInComputerHand(); + Assert.assertEquals(expected, actual); } @Test public void decideWinnerTest() { - goFishGame.getComputerPlayer().setScore(10); - goFishGame.getGoFishPlayer().setScore(2); + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + playerHand1.add(card4); + playerHand1.add(card5); + playerHand1.add(card6); + playerHand1.add(card7); + playerHand1.add(card8); + goFishGame.setComputerHand(playerHand1); + goFishGame.countBooksInComputerHand(); + goFishGame.countBooksInPlayerHand(); - goFishGame.decideWiner(); + goFishGame.decideWiner(); // should pop the machine won because the computer has 2 + // books(cards added to the computer hand) while the player hand is empty } diff --git a/src/test/java/io/zipcoder/casino/GoFishTest.java b/src/test/java/io/zipcoder/casino/GoFishTest.java new file mode 100644 index 00000000..7db5be4f --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GoFishTest.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class GoFishTest { + + GoFish goFish = new GoFish(); + @Test + + public void goFishObjectTest(){ + + Assert.assertTrue(goFish instanceof GoFishGame); + } + + @Test + public void goFishRun() throws Exception { + + goFish.goFishRun(); // should pop out Welcome to the table! insert nick name you want to use for the game? + // tested visually + } + +} \ No newline at end of file From b7cad488c2b9a85f57d19f7449ad5cb2a7c6f150 Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 22:00:07 -0500 Subject: [PATCH 29/30] fix crossed pom --- .DS_Store | Bin 6148 -> 6148 bytes pom.xml | 14 ++------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.DS_Store b/.DS_Store index 9a874b5768f336915163bb88cd434575b859f936..feca8613504bcd7430524202412f605a970dd548 100644 GIT binary patch delta 24 gcmZoMXfc>z$H*|zUVdZZGWN;3BJ7*FIezj30AOtgj{pDw delta 26 icmZoMXfc>z$H+L*UY?P0W8yOQ$$BDeo4GlD@&f>7?FW(o diff --git a/pom.xml b/pom.xml index 4305c82a..5afa7e8d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,15 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.zipcoder.threedaystodeliver - HumanResourceApp + io.zipcoder.casino + casino 1.0-SNAPSHOT - - org.springframework.boot - spring-boot-starter-parent - 1.5.7.RELEASE - @@ -20,10 +15,6 @@ junit 4.12 - - org.springframework.boot - spring-boot-starter-web - @@ -36,7 +27,6 @@ - org.springframework.boot spring-boot-maven-plugin From ecc628987d788f26d3b763fb34c938d401c565cc Mon Sep 17 00:00:00 2001 From: gpatelos Date: Sun, 26 Nov 2017 23:27:24 -0500 Subject: [PATCH 30/30] add return to main menu. fix conflicts --- src/main/java/io/zipcoder/casino/GoFish.java | 7 +- .../java/io/zipcoder/casino/GoFishGame.java | 17 -- src/main/java/io/zipcoder/casino/Main.java | 5 +- .../io/zipcoder/casino/GoFishGameTest.java | 148 +++++++++--------- 4 files changed, 83 insertions(+), 94 deletions(-) diff --git a/src/main/java/io/zipcoder/casino/GoFish.java b/src/main/java/io/zipcoder/casino/GoFish.java index 0ccc5e19..7fc1b5d8 100644 --- a/src/main/java/io/zipcoder/casino/GoFish.java +++ b/src/main/java/io/zipcoder/casino/GoFish.java @@ -2,6 +2,8 @@ import java.util.Scanner; +import static io.zipcoder.casino.Console.casinoHome; + public class GoFish extends GoFishGame { @@ -17,7 +19,7 @@ public static void goFishRun() { do { GoFishGame goFishGame = new GoFishGame(); - goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); + goFishGame.getGoFishPlayer().setName(InPutConsole.getInput()); goFishGame.startGame(); goFishGame.playerHand(); goFishGame.computerHand(); @@ -40,5 +42,6 @@ public static void goFishRun() { System.out.println("Do you want to play again?"); response = InPutConsole.getInput(); } while (response.equalsIgnoreCase("yes")); - System.out.println("Bye bye, visit us again"); + casinoHome(); } +} diff --git a/src/main/java/io/zipcoder/casino/GoFishGame.java b/src/main/java/io/zipcoder/casino/GoFishGame.java index 50f63107..5141fa91 100644 --- a/src/main/java/io/zipcoder/casino/GoFishGame.java +++ b/src/main/java/io/zipcoder/casino/GoFishGame.java @@ -448,24 +448,7 @@ public GoFishPlayer getComputerPlayer() { return computerPlayer; } - public String countBooksInPlayerHand() { - ArrayList hand = getPlayerHand(); - List cardsByRank = new ArrayList<>(); - - for(Card card : hand){ - cardsByRank.add(card.getRank().getSymbol()); - } - - Set uniqueSet = new HashSet<>(cardsByRank); - Integer count = 0; - for (String rank : uniqueSet) { - if(Collections.frequency(cardsByRank,rank)>3){ - return rank; - } - } - return null; - } } diff --git a/src/main/java/io/zipcoder/casino/Main.java b/src/main/java/io/zipcoder/casino/Main.java index 85fa4208..17589489 100644 --- a/src/main/java/io/zipcoder/casino/Main.java +++ b/src/main/java/io/zipcoder/casino/Main.java @@ -1,13 +1,14 @@ package io.zipcoder.casino; +import static io.zipcoder.casino.Console.casinoHome; + public class Main { public static void main(String[] args) { - CrapsConsole crapsConsole = new CrapsConsole(); - crapsConsole.playCraps(); + casinoHome(); } } diff --git a/src/test/java/io/zipcoder/casino/GoFishGameTest.java b/src/test/java/io/zipcoder/casino/GoFishGameTest.java index c00daff7..7bb1594a 100644 --- a/src/test/java/io/zipcoder/casino/GoFishGameTest.java +++ b/src/test/java/io/zipcoder/casino/GoFishGameTest.java @@ -6,11 +6,6 @@ import java.util.ArrayList; import java.util.Iterator; - -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; - - public class GoFishGameTest { GoFishGame goFishGame = new GoFishGame(); @@ -26,8 +21,6 @@ public class GoFishGameTest { ArrayList computerHand1 = new ArrayList<>(); - - @Test public void createGoFishGameTest() throws Exception { @@ -48,6 +41,7 @@ public void shouldThrowExceptionWhenDeckIsNullStartingGame() { GoFishPlayer goFishPlayer = new GoFishPlayer(); goFishGame.startGame(); } + @Test public void playerHandget7CardStartOfGame() { @@ -59,6 +53,7 @@ public void playerHandget7CardStartOfGame() { Assert.assertEquals(expectedBeforeMethodCall, actualBeforeMethodCall); Assert.assertEquals(expectedPlayerHandSize, actualPlayerHandSize); } + @Test public void computerHandget7CardStartOfGame() { @@ -73,9 +68,10 @@ public void computerHandget7CardStartOfGame() { Assert.assertEquals(expectedComputerHandSize, actualComputerhandSize); } + @Test - public void getAndSetPlayerHandTest(){ + public void getAndSetPlayerHandTest() { playerHand1.add(card1); playerHand1.add(card2); goFishGame.setPlayerHand(playerHand1); @@ -85,7 +81,7 @@ public void getAndSetPlayerHandTest(){ @Test - public void getAndSetComputerHand(){ + public void getAndSetComputerHand() { playerHand1.add(card1); playerHand1.add(card2); playerHand1.add(card3); @@ -110,6 +106,7 @@ public void deckSizeDecreaseAfterDeal() throws Exception { Assert.assertEquals(expectedBeforeDealing, actualBeforeDealing); Assert.assertEquals(expectedAfterDealing, actualAfterDealing); } + @Test public void playerHandDisplayAndSetPlayerHandTest() { @@ -214,7 +211,7 @@ public void computerDecisionForCardTest() { // } @Test - public void checkPlayersCardRequestForGameRuleTest(){ + public void checkPlayersCardRequestForGameRuleTest() { ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); playerHand1.add(card2); @@ -222,16 +219,16 @@ public void checkPlayersCardRequestForGameRuleTest(){ goFishGame.setPlayerHand(playerHand1); Boolean expected = false; - Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); + Boolean actual = goFishGame.checkPlayersCardRequestForGameRule("10"); Assert.assertEquals(expected, actual); Boolean expected2 = true; - Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("2"); - Assert.assertEquals(expected2, actual2); + Boolean actual2 = goFishGame.checkPlayersCardRequestForGameRule("2"); + Assert.assertEquals(expected2, actual2); } @Test - public void checkInputTest(){ + public void checkInputTest() { ArrayList playerHand1 = new ArrayList<>(); playerHand1.add(card1); playerHand1.add(card3); @@ -249,39 +246,40 @@ public void checkInputTest(){ @Test - public void goFishingPlayerTest(){ + public void goFishingPlayerTest() { ArrayList deck = goFishGame.getDeck(); goFishGame.getPlayerHand(); Card card = deck.get(0); - int expectSizeOfHandIncreaseBy1AfterGoFish = goFishGame.getPlayerHand().size() +1; + int expectSizeOfHandIncreaseBy1AfterGoFish = goFishGame.getPlayerHand().size() + 1; Boolean expectedDeckTopCardToBeAvailable = true; - Boolean actualDeckTopcardAvaialble = deck.contains(card); + Boolean actualDeckTopcardAvaialble = deck.contains(card); goFishGame.goFishingPlayer(); int actualSizeOfPlayerHandIncreaseAfterGoFish = goFishGame.getPlayerHand().size(); - Boolean expectedDeckTopCardNotToBeAvailable= false; + Boolean expectedDeckTopCardNotToBeAvailable = false; Boolean actualDeckTopCardNotToBeAvailable = deck.contains(card); - Assert.assertEquals(expectedDeckTopCardNotToBeAvailable, actualDeckTopCardNotToBeAvailable); + Assert.assertEquals(expectedDeckTopCardNotToBeAvailable, actualDeckTopCardNotToBeAvailable); Assert.assertEquals(expectedDeckTopCardToBeAvailable, actualDeckTopcardAvaialble); Assert.assertEquals(expectSizeOfHandIncreaseBy1AfterGoFish, actualSizeOfPlayerHandIncreaseAfterGoFish); } + @Test - public void goFishingComputerTest(){ + public void goFishingComputerTest() { ArrayList deck = goFishGame.getDeck(); goFishGame.getComputerHand(); Card card = deck.get(0); - int expectSizeOfComouterHandIncreaseBy1AfterGoFish = goFishGame.getComputerHand().size() +1; + int expectSizeOfComouterHandIncreaseBy1AfterGoFish = goFishGame.getComputerHand().size() + 1; Boolean expectedDeckTopCardToBeAvailable = true; Boolean actualDeckTopcardAvaialble = deck.contains(card); goFishGame.goFishingComputer(); int actualSizeOfComputerHandIncreaseAfterGoFish = goFishGame.getComputerHand().size(); - Boolean expectedDeckTopCardNotToBeAvailable= false; + Boolean expectedDeckTopCardNotToBeAvailable = false; Boolean actualDeckTopCardNotToBeAvailable = deck.contains(card); Assert.assertEquals(expectedDeckTopCardNotToBeAvailable, actualDeckTopCardNotToBeAvailable); Assert.assertEquals(expectedDeckTopCardToBeAvailable, actualDeckTopcardAvaialble); @@ -318,9 +316,9 @@ public void goFishingComputerTest(){ // } @Test - public void countPlayerScoreTest(){ + public void countPlayerScoreTest() { Player player = goFishGame.getGoFishPlayer(); - int score =0; + int score = 0; Card card1 = new Card(Rank.TWO, Suit.CLUB); Card card5 = new Card(Rank.THREE, Suit.SPADE); Card card3 = new Card(Rank.TWO, Suit.DIAMOND); @@ -342,63 +340,67 @@ public void countPlayerScoreTest(){ goFishGame.setPlayerHand(playerHand1); - int expected = 2; - int actual = goFishGame.countBooksInPlayerHand(); - Assert.assertEquals(expected, actual); - } - - @Test - public void countComputerScoreTest() { - - - public void playerScoreTest(){ - Player player = goFishGame.getGoFishPlayer(); - int score =0; - Card card1 = new Card(Rank.TWO, Suit.CLUB); - Card card2 = new Card(Rank.TWO, Suit.HEART); - Card card3 = new Card(Rank.THREE, Suit.DIAMOND); - Card card4 = new Card(Rank.TWO, Suit.SPADE); - Card card5 = new Card(Rank.THREE, Suit.SPADE); - Card card6 = new Card(Rank.TWO, Suit.CLUB); - Card card7 = new Card(Rank.THREE, Suit.HEART); - Card card8 = new Card(Rank.THREE, Suit.SPADE); - - ArrayList playerHand1 = new ArrayList<>(); - - playerHand1.add(card1); - playerHand1.add(card2); - playerHand1.add(card3); - playerHand1.add(card4); - playerHand1.add(card5); - playerHand1.add(card6); - playerHand1.add(card7); - playerHand1.add(card8); - - goFishGame.setComputerHand(playerHand1); int expected = 2; - int actual = goFishGame.countBooksInComputerHand(); + int actual = goFishGame.countBooksInPlayerHand(); Assert.assertEquals(expected, actual); } + @Test - public void decideWinnerTest() { - playerHand1.add(card1); - playerHand1.add(card2); - playerHand1.add(card3); - playerHand1.add(card4); - playerHand1.add(card5); - playerHand1.add(card6); - playerHand1.add(card7); - playerHand1.add(card8); - goFishGame.setComputerHand(playerHand1); + public void countComputerScoreTest() { - goFishGame.countBooksInComputerHand(); - goFishGame.countBooksInPlayerHand(); + } - goFishGame.decideWiner(); // should pop the machine won because the computer has 2 - // books(cards added to the computer hand) while the player hand is empty + @Test + public void playerScoreTest () { + Player player = goFishGame.getGoFishPlayer(); + int score = 0; + Card card1 = new Card(Rank.TWO, Suit.CLUB); + Card card2 = new Card(Rank.TWO, Suit.HEART); + Card card3 = new Card(Rank.THREE, Suit.DIAMOND); + Card card4 = new Card(Rank.TWO, Suit.SPADE); + Card card5 = new Card(Rank.THREE, Suit.SPADE); + Card card6 = new Card(Rank.TWO, Suit.CLUB); + Card card7 = new Card(Rank.THREE, Suit.HEART); + Card card8 = new Card(Rank.THREE, Suit.SPADE); + + ArrayList playerHand1 = new ArrayList<>(); + + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + playerHand1.add(card4); + playerHand1.add(card5); + playerHand1.add(card6); + playerHand1.add(card7); + playerHand1.add(card8); + + goFishGame.setComputerHand(playerHand1); + int expected = 2; + int actual = goFishGame.countBooksInComputerHand(); + Assert.assertEquals(expected, actual); + } + @Test + public void decideWinnerTest () { + playerHand1.add(card1); + playerHand1.add(card2); + playerHand1.add(card3); + playerHand1.add(card4); + playerHand1.add(card5); + playerHand1.add(card6); + playerHand1.add(card7); + playerHand1.add(card8); + goFishGame.setComputerHand(playerHand1); + + goFishGame.countBooksInComputerHand(); + goFishGame.countBooksInPlayerHand(); + + goFishGame.decideWiner(); // should pop the machine won because the computer has 2 + // books(cards added to the computer hand) while the player hand is empty + + } } -} \ No newline at end of file +