diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5172429 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4efe025..17e107a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,8 @@ - - + + @@ -23,52 +23,38 @@ - - + + - - - - - - - - - - - - - - - + - - + + - - + + - - + + - - + + @@ -84,41 +70,53 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + @@ -136,6 +134,7 @@ scanner + in pl @@ -151,14 +150,14 @@ @@ -177,10 +176,10 @@ - @@ -197,6 +196,7 @@ + @@ -209,20 +209,6 @@ - - - - - - - - - - + @@ -823,9 +808,9 @@ - - - + + + @@ -846,14 +831,13 @@ - + + + - - - @@ -869,6 +853,9 @@ + + + @@ -883,10 +870,10 @@ - - + @@ -898,19 +885,19 @@ - + - + - + @@ -928,7 +915,7 @@ - @@ -997,10 +984,7 @@ - - - - + @@ -1080,10 +1064,7 @@ - - - - + @@ -1163,10 +1144,7 @@ - - - - + @@ -1191,9 +1169,8 @@ - - - + + @@ -1204,6 +1181,8 @@ + + @@ -1256,113 +1235,108 @@ - + - - + + - + - - + + - + - - - - - - + + + - + - + - - + + - + - - + + - + - + - + - - - - - - - + + + - - + + - + - - - + + + + + - + - - + + - + - - + + - + - - + + diff --git a/CardGame UML.xml b/CardGame UML.xml deleted file mode 100644 index b52beea..0000000 --- a/CardGame UML.xml +++ /dev/null @@ -1 +0,0 @@ -7Vtbb+o4EP41SN2HVnECgT4WejladaVqqbR7Hk1iEm+dGDmmlPPrd5zY5GYoLaFHezYVVe3J+Dbf3DykA2+WvD0IvIr/4CFhA9cJ3wbe7cB1ket68EdRtgXFn2hCJGiomUrCnP4gmuho6pqGJKsxSs6ZpKs6MeBpSgJZo2Eh+KbOtuSsvuoKR6RFmAeYtal/0VDGBXUyckr6N0Kj2KyMHP1kgYOXSPB1qtcbuN4y/ykeJ9jMpfmzGId8UyF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Ec8xeyupE7zL15JqKVXgZy8Ufm3IoO0it53zQRnF9vKI9X9rkf9Q6Tcai+M15Ir1HbrPvLckNFOtmp7h30jnIavRUDqUgINjsg7AAjCsKSv9flPMqh2of+B39Ms7gPhVwfCIWqnPrvSftWsrjv4cq4v737GLX64Om/Fr4M46I1/da/omdd9foZX9NqlK9Cz4OV3+O0d47kdo990jJaypd2wOnCMnq3G0TvGw3h6ewD9CY7Rdr9TFwTIvE0xB2SXmlKO7ZswWKPK0t8kzqcZlpuEVTM6uUm0Ux7Uwpak4Y16b1QF0VUuwWqcTM0rqsg1rtdwhxQnPA2fY5o2vDIaGoLymWaqd6P1O7qy0E55F7zRlYNq4fvKmZj+ExEU5KViTjOsO+64GtgvnSt07RpKc9wnLzjtSD4+GABgE+AMrutBQN/8j471evYnpfDl1AjVY4uPGnXEYuN6VKlcrYl2L2Ptm6g4bmuivARdYdMGuXfD3qS5zsFtHWaHRrG+ffCl59YGo0Y85ctlRuSgaXM7AI8zw/a7Cb+EGZYm5Xtuw6Qcxz+7Se2rqxtsUQ1a7/9pTW7jlWtTtjp2Xx/nv95vf+8bD3TLfwEo2Mv/s/Du/gU= \ No newline at end of file diff --git a/CardGameUML.pdf b/CardGameUML.pdf deleted file mode 100644 index 6fd1df7..0000000 Binary files a/CardGameUML.pdf and /dev/null differ diff --git a/CardGameUML.xml b/CardGameUML.xml new file mode 100644 index 0000000..a0d77ae --- /dev/null +++ b/CardGameUML.xml @@ -0,0 +1 @@ +7Vttc5s4EP41nkk/JIPAxvbH2Hnp3OSmmbpzd/2ogGx0Fcgj5Djur78VSGBArnGC07semWSCltXbPrurh8UeePP45V7gdfQ7DwkbuE74MvBuBq6LHM+Bf0qyyyW+qwUrQUOtVAoW9DsxPbV0Q0OSVhQl50zSdVUY8CQhgazIsBB8W1VbcladdY1XpCFYBJg1pX/SUEa5dDJySvlHQleRmRk5+s4TDr6tBN8ker6B6y2zn/x2jM1YWj+NcMi3eyLvduDNBecyv4pf5oQp2xqz5f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ZG4FkaCbIzEG3UAeV+YPz1i8zg5iT/YAOziADpUmc8CpfpI26focwHutYzYTgij30CShCtiEi/sNOIrnmB2W0pn2YcPSKittwc5eaHyLyUGa+Wtr1oJ9i52e7dU86vu9TeRcqezMN5IrlAr5n3gWSCjwrZqeRXLpnwjAiPSJTVw1xWpWLtVDhWEYUmfq+O/ybzNEt89v6Np1B+E730QjpyWeRRNuuA+tvJgfxAeAXTczUHYwQcMLC9rypKtfuS5xUH0yPCOCPMYA+ZMzEOMrQAMs+6r/KBmW1WbrSBdfALrnTBo6/JwbarySTH9tFzAvNm76ew1PFiteL2trvP6orl6/dJ6KnGukEHI8rxni5lOypHTX4pLmDr9v4VLuM1qLyTn4Ntv8NfTiXPTCX94nE4UzKHyWZEOWLrbl3Vf8VEfxw7oYTZhxa+LD7wdqusqMvElyg/bs3MIkoQwl8oUF0WpeF7Wjfvj+ycc30d81FIJsProqIsc06zWoga24EPX6rsP6jhfZxbcP7ET8zUL5JpDwGiHFMdcOSBNaucDGhqByt5mqKO84YivPOnjoaAR6MpBFSJx5UxM+5EICvZSp1+dYDjueJ9iXDpXaOoaSb1fG1LR5BT+qUcRLALS0rRyHA115a4169CjP/KM2Zuhp9VDbuzUHCvfiu5U+lZjnOKdwqGBcgM0BspeIO2p6Xg8uF7Pr86DRuMfruuIPlzkK7D3vvTcau/agyZfLlMiB/WgKxBsF4fNEvovEYdlTPmeW4spx/G7janpyTGFKsh6/8tocmvfGvL0PG3XdbK+ft9gjb7joQPN8ltsuXr5VUHv9h8= \ No newline at end of file diff --git a/CardGameUMLpdf.pdf b/CardGameUMLpdf.pdf new file mode 100644 index 0000000..ff0b172 Binary files /dev/null and b/CardGameUMLpdf.pdf differ diff --git a/src/main/java/reynoldstitko/gillian/App.java b/src/main/java/reynoldstitko/gillian/App.java index 48dcb3e..2b098b8 100644 --- a/src/main/java/reynoldstitko/gillian/App.java +++ b/src/main/java/reynoldstitko/gillian/App.java @@ -18,7 +18,7 @@ public static void main(String[] args) { switch (chooseGame) { case 1: { theGame = new BlackJackGame(); //Using polymorphism - System.out.print("You chose to play no-bet BlackJack!\n"); + System.out.print("You chose to play no-bet BlackJack (where Aces = 1)!\n"); break; } diff --git a/src/main/java/reynoldstitko/gillian/BlackJackGame.java b/src/main/java/reynoldstitko/gillian/BlackJackGame.java index 560948a..3f5fec3 100644 --- a/src/main/java/reynoldstitko/gillian/BlackJackGame.java +++ b/src/main/java/reynoldstitko/gillian/BlackJackGame.java @@ -6,22 +6,20 @@ * Created by gillianreynolds-titko on 1/27/17. */ public class BlackJackGame extends Game { - public void start() { + Scanner scanner = new Scanner(System.in); + Hand playerOneHand = new Hand(); + Hand playerTwoHand = new Hand(); + int playerOneTotal = 0; + int playerTwoTotal = 0; - Scanner scanner = new Scanner(System.in); - Hand playerOneHand = new Hand(); - Hand playerTwoHand = new Hand(); - int playerOneTotal = 0; - int playerTwoTotal = 0; + Deck cardDeck = new Deck(); - Deck cardDeck = new Deck(); + public void start() { //Shuffle the deck cardDeck.shuffle(); - //Deal 2 cards to each player, including the dealer - playerOneHand.addCardsToHand(cardDeck.deal(2)); - playerTwoHand.addCardsToHand(cardDeck.deal(2)); + dealTheCards(); //Show player1 their cards System.out.println("Player 1, you have the following cards:"); @@ -35,7 +33,7 @@ public void start() { boolean playerTwoPlaying = false; String response = scanner.next(); - while (response.equalsIgnoreCase("Hit") && playerOnePlaying == true) { + if (response.equalsIgnoreCase("Hit") && playerOnePlaying == true) { playerOneHand.addCardsToHand(cardDeck.deal(1)); System.out.println("Player 1, you have the following cards:"); for (int i = 0; i < playerOneHand.getTheHand().size(); i++) { @@ -48,8 +46,13 @@ public void start() { playerOnePlaying = false; playerTwoPlaying = true; playerOneTotal = playerOneHand.sumRankValues(playerOneHand.getTheHand()); - break; + //break; } + //Account for player staying in the first move + } if(response.equalsIgnoreCase("Stay") && playerOnePlaying == true){ + playerOnePlaying = false; + playerTwoPlaying = true; + playerOneTotal = playerOneHand.sumRankValues(playerOneHand.getTheHand()); } System.out.println("Player 2, you have the following cards:"); @@ -60,7 +63,7 @@ public void start() { System.out.println("Player 2, do you want to Hit or Stay?"); response = scanner.next(); - while (response.equalsIgnoreCase("Hit") && playerTwoPlaying == true) { + if (response.equalsIgnoreCase("Hit") && playerTwoPlaying == true) { //Show player2 their cards playerTwoHand.addCardsToHand(cardDeck.deal(1)); System.out.println("Player 2, you have the following cards:"); @@ -72,20 +75,34 @@ public void start() { if (response.equalsIgnoreCase("Stay")) { playerTwoPlaying = false; + playerOnePlaying = false; playerTwoTotal = playerTwoHand.sumRankValues(playerTwoHand.getTheHand()); - break; + //break; } + } if(response.equalsIgnoreCase("Stay") && playerTwoPlaying == true){ + playerTwoPlaying = false; + playerOnePlaying = false; + playerTwoTotal = playerTwoHand.sumRankValues(playerTwoHand.getTheHand()); } + endTheGame(false, false); + + } + + //--Refactor and add a few helper methods + public void dealTheCards(){ + //Deal 2 cards to each player, including the dealer + playerOneHand.addCardsToHand(cardDeck.deal(2)); + playerTwoHand.addCardsToHand(cardDeck.deal(2)); + } + + public void endTheGame(boolean playerOnePlaying, boolean playerTwoPlaying){ if (playerOnePlaying == false && playerTwoPlaying == false) { //Show game results here System.out.print("Player 1 you got " + playerOneTotal + " points\n"); System.out.print("Player 2 you got " + playerTwoTotal + " points\n"); System.out.println("Game over!"); } - } -} - - +} \ No newline at end of file diff --git a/src/main/java/reynoldstitko/gillian/GoFishGame.java b/src/main/java/reynoldstitko/gillian/GoFishGame.java index cd41ae4..cd49d09 100644 --- a/src/main/java/reynoldstitko/gillian/GoFishGame.java +++ b/src/main/java/reynoldstitko/gillian/GoFishGame.java @@ -6,20 +6,19 @@ * Created by gillianreynolds-titko on 1/27/17. */ public class GoFishGame extends Game { - public void start(){ - Scanner scanner = new Scanner(System.in); - Hand playerOneHand = new Hand(); - Hand playerTwoHand = new Hand(); + Scanner scanner = new Scanner(System.in); + Hand playerOneHand = new Hand(); + Hand playerTwoHand = new Hand(); + Deck cardDeck = new Deck(); - Deck cardDeck = new Deck(); + public void start(){ //Shuffle the deck cardDeck.shuffle(); //Deal 5 cards to each player - playerOneHand.addCardsToHand(cardDeck.deal(5)); - playerTwoHand.addCardsToHand(cardDeck.deal(5)); + dealCardsToEachPlayer(); boolean isGameOver = false; @@ -58,13 +57,7 @@ public void start(){ //Get the number of cards of the same rank and remove that number int removedCards = playerTwoHand.countCardsInHandOfRank(playerTwoHand.getTheHand(), rank); - for(int i = 1; i <= removedCards; i++){ - Card temp = playerTwoHand.removeCardFromHand(rank); - if(temp == null){ - - }else playerOneHand.addCardToHand(temp); - playerTwoHand.getTheHand().trimToSize(); - } + removeCardsOfSameRank(removedCards, rank, playerTwoHand, playerOneHand); } else { //If no, then respond "Go fish" and deal one card to player from the deck @@ -93,7 +86,6 @@ public void start(){ while (playerTwoStillPlaying && (playerTwoHand.getTheHand().size() !=0)){ System.out.println("Player 2, what rank card do you want to check for (Ace, Two, Three, etc to King)?"); - //Get the player response for the rank String rank = scanner.next(); //String suit = scanner.next(); @@ -103,16 +95,9 @@ public void start(){ //If yes, then move all the cards with that rank from player1 to player2, // reducing player2's cards and increasing player 1's cards - //Get the number of cards of the same rank and remove that number int removedCards = playerOneHand.countCardsInHandOfRank(playerOneHand.getTheHand(), rank); - for(int i = 1; i <= removedCards; i++){ - Card temp = playerOneHand.removeCardFromHand(rank); - if (temp == null) { - } else playerTwoHand.addCardToHand(temp); - playerOneHand.getTheHand().trimToSize(); - - } + removeCardsOfSameRank(removedCards, rank, playerOneHand, playerTwoHand); //Show the player1 list of cards System.out.println("Player 1, you have the following cards:"); @@ -139,9 +124,29 @@ public void start(){ } } + gameOver(); + } + + //---Refactor to create some helper methods + public void dealCardsToEachPlayer(){ + //Deal 5 cards to each player + playerOneHand.addCardsToHand(cardDeck.deal(5)); + playerTwoHand.addCardsToHand(cardDeck.deal(5)); + } + + public void gameOver(){ System.out.print("Player 1, you had "+ playerOneHand.getTheHand().size()+" cards left\n"); System.out.print("Player 2, you had "+ playerTwoHand.getTheHand().size()+" cards left\n"); System.out.print("Game over!"); scanner.close(); } + + public void removeCardsOfSameRank(int removedCards, String rank, Hand firstPlayer, Hand otherPlayer){ + for(int i = 1; i <= removedCards; i++){ + Card temp = firstPlayer.removeCardFromHand(rank); + if (temp == null) { + } else otherPlayer.addCardToHand(temp); + firstPlayer.getTheHand().trimToSize(); + } + } } diff --git a/src/test/java/reynoldstitko/gillian/CardTest.java b/src/test/java/reynoldstitko/gillian/CardTest.java index 4b96c6c..d2b0ce3 100644 --- a/src/test/java/reynoldstitko/gillian/CardTest.java +++ b/src/test/java/reynoldstitko/gillian/CardTest.java @@ -25,13 +25,4 @@ public void getRankValueTest(){ assertEquals("I expect to return a 4", expected, actual); } - @Test - public void sumValuesTest(){ - int expected = 3; - ArrayList cards = new ArrayList<>(); - cards.add(new Card("Three", "Spades")); - cards.add(new Card("Three", "Hearts")); - //int actual = cards.sumRankValues(); - //assertEquals("I expect a sum of 3", expected, actual); - } } diff --git a/target/classes/reynoldstitko/gillian/App.class b/target/classes/reynoldstitko/gillian/App.class index 586590a..9daf5c1 100644 Binary files a/target/classes/reynoldstitko/gillian/App.class and b/target/classes/reynoldstitko/gillian/App.class differ diff --git a/target/classes/reynoldstitko/gillian/BlackJackGame.class b/target/classes/reynoldstitko/gillian/BlackJackGame.class index bc3f51e..8e6ac6c 100644 Binary files a/target/classes/reynoldstitko/gillian/BlackJackGame.class and b/target/classes/reynoldstitko/gillian/BlackJackGame.class differ diff --git a/target/classes/reynoldstitko/gillian/GoFishGame.class b/target/classes/reynoldstitko/gillian/GoFishGame.class index 18eb5c6..c0aad54 100644 Binary files a/target/classes/reynoldstitko/gillian/GoFishGame.class and b/target/classes/reynoldstitko/gillian/GoFishGame.class differ diff --git a/target/test-classes/reynoldstitko/gillian/CardTest.class b/target/test-classes/reynoldstitko/gillian/CardTest.class index 181a7fd..7be5f1e 100644 Binary files a/target/test-classes/reynoldstitko/gillian/CardTest.class and b/target/test-classes/reynoldstitko/gillian/CardTest.class differ