Przeglądaj źródła

Merge branch 'Working' of https://git.zipcode.rocks/nedredmond/ZCW-OOP-Casino into Working

Yesoda Sanka 6 lat temu
rodzic
commit
8f65ea28f3

+ 34
- 24
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java Wyświetl plik

@@ -1,21 +1,17 @@
1 1
 package io.zipcoder.casino.cardgames;
2 2
 
3
-import io.zipcoder.casino.cardgames.cards.Card;
4
-import io.zipcoder.casino.cardgames.cards.CardHand;
5
-import io.zipcoder.casino.cardgames.cards.CardValue;
6
-import io.zipcoder.casino.cardgames.cards.Deck;
3
+import io.zipcoder.casino.utilities.Card;
4
+import io.zipcoder.casino.utilities.containers.CardHand;
5
+import io.zipcoder.casino.utilities.containers.Deck;
7 6
 import io.zipcoder.casino.utilities.Console;
8 7
 import io.zipcoder.casino.utilities.Gamble;
9 8
 import io.zipcoder.casino.player.BlackJackPlayer;
10 9
 import io.zipcoder.casino.player.Player;
11 10
 import io.zipcoder.casino.player.Players;
12 11
 
13
-import java.sql.SQLOutput;
14 12
 import java.util.ArrayList;
15
-import java.util.Vector;
16 13
 
17 14
 public class BlackJack extends CardGame implements Gamble {
18
-    long upcardsValue = 0;
19 15
 
20 16
     private Deck deck = new Deck();
21 17
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
@@ -25,7 +21,7 @@ public class BlackJack extends CardGame implements Gamble {
25 21
 
26 22
     public BlackJack(){
27 23
         readyPlayers();
28
-        placeBet();
24
+        dealCards(2);
29 25
         run();
30 26
     }
31 27
 
@@ -42,35 +38,41 @@ public class BlackJack extends CardGame implements Gamble {
42 38
     }
43 39
 
44 40
     public boolean play(BlackJackPlayer currentPlayer, long bet) {
41
+        placeBet();
42
+        // this.bet = bet;
45 43
 
46
-        this.bet = bet;
44
+        Console.println("The dealer is dealing cards to the players.");
47 45
 
48
-        dealCards(2);
49 46
         dealerHand.add(deck.removeFirst());
50 47
         dealerHand.add(deck.removeFirst());
51 48
 
49
+        Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
50
+
52 51
         if (getSum(dealerHand) == 21){
53 52
             Console.println("Dealer has +," +  dealerHand.display());
54 53
             Console.println("You have " + currentPlayer.getHand().display());
55
-            Console.println("Dealer win.");
54
+            Console.println("Dealer has blackjack. Dealer wins.");
56 55
         }
57 56
 
57
+
58
+        Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
59
+
58 60
         if (getSum(currentPlayer.getHand()) == 21){
59 61
             Console.println("Dealer has " + dealerHand.display());
60 62
             Console.println("You have " + currentPlayer.getHand().display());
61
-            Console.println("You win.");
63
+            Console.println("You have blackjack. You win.");
62 64
         }
63
-
65
+        
64 66
         while(true) {
65 67
 
66
-            Console.println("You have: " + currentPlayer.getHand().display());
67
-            Console.println("Dealer is showing a " + dealerHand.get(0).getCard());
68
+            Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
69
+
68 70
             String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
69 71
 
70 72
             while (getSum(currentPlayer.getHand()) < 21) {
71
-                if (hitOrStand.equals("H")) {
73
+                if (hitOrStand.equalsIgnoreCase("H")) {
72 74
                     dealCard(currentPlayer,1);
73
-                } else if (hitOrStand.equals("S")) {
75
+                } else if (hitOrStand.equalsIgnoreCase("S")) {
74 76
                     break;
75 77
                 } else {
76 78
                     hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
@@ -78,15 +80,24 @@ public class BlackJack extends CardGame implements Gamble {
78 80
             }
79 81
 
80 82
             Console.println("You have: " + currentPlayer.getHand().display());
83
+            Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
84
+
85
+            if (getSum(currentPlayer.getHand()) > 21){
86
+                Console.println("You busted. House wins.");
87
+                return false;
88
+            }
89
+
81 90
             Console.println("Dealer's card are: " + dealerHand.display());
91
+            Console.println("The sum of dealer's cards is " + getSum(dealerHand));
82 92
 
83 93
             while (getSum(dealerHand) < 17) {
84
-                dealerHand.add(deck.removeFirst());
85 94
                 revealCard();
86 95
                 Console.println("Dealer's sum is " + getSum(dealerHand));
87 96
             }
97
+
88 98
             if (getSum(dealerHand) > 21) {
89 99
                 Console.println("Dealer busted. You win.");
100
+                return false;
90 101
             }
91 102
 
92 103
             if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
@@ -122,7 +133,7 @@ public class BlackJack extends CardGame implements Gamble {
122 133
     }
123 134
 
124 135
     public void placeBet() {
125
-        bet = Console.getLongInput("Please enter your bet.");
136
+        this.bet = Console.getLongInput("Please enter your bet.");
126 137
     }
127 138
 
128 139
 
@@ -138,12 +149,12 @@ public class BlackJack extends CardGame implements Gamble {
138 149
     }
139 150
 
140 151
 
141
-    public int  getSum(CardHand cardHands) {
152
+    public int  getSum(CardHand cardHand) {
142 153
         int cardSum = 0;
143 154
         boolean ace = false;
144 155
 
145
-        for (int i = 0; i < cardHands.size(); i++) {
146
-            int cardValue = cardHands.get(i).getCardValue().getCardValue();
156
+        for (int i = 0; i < cardHand.size(); i++) {
157
+            int cardValue = cardHand.get(i).getCardValue().getCardValue();
147 158
 
148 159
             if (cardValue > 10) {
149 160
                 cardValue = 10;   // For a Jack, Queen, or King.
@@ -153,13 +164,12 @@ public class BlackJack extends CardGame implements Gamble {
153 164
             }
154 165
             cardSum = cardSum + cardValue;
155 166
         }
156
-        if (ace == true && cardSum + 10 <= 21) {
167
+        if (cardHand.size() == 2 && ace == true && cardSum + 10 == 21) {
157 168
             cardSum = cardSum + 10;
158 169
         }
159 170
         return cardSum;
160 171
     }
161 172
 
162
-
163 173
     public void revealCard(){
164 174
         Card newCard = drawCard();
165 175
         Console.println("Dealer drew a " + newCard.getCardValue() + " of " + newCard.getSuit());

+ 1
- 2
src/main/java/io/zipcoder/casino/cardgames/CardGame.java Wyświetl plik

@@ -1,7 +1,6 @@
1 1
 package io.zipcoder.casino.cardgames;
2 2
 
3
-import io.zipcoder.casino.cardgames.cards.CardHand;
4
-import io.zipcoder.casino.cardgames.cards.Deck;
3
+import io.zipcoder.casino.utilities.containers.Deck;
5 4
 import io.zipcoder.casino.utilities.Game;
6 5
 import io.zipcoder.casino.player.Player;
7 6
 

+ 1
- 1
src/main/java/io/zipcoder/casino/cardgames/GoFish.java Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino.cardgames;
2 2
 
3
-import io.zipcoder.casino.cardgames.cards.Deck;
3
+import io.zipcoder.casino.utilities.containers.Deck;
4 4
 import io.zipcoder.casino.player.GoFishPlayer;
5 5
 import io.zipcoder.casino.player.Player;
6 6
 import io.zipcoder.casino.player.Players;

+ 0
- 53
src/main/java/io/zipcoder/casino/cardgames/cards/Deck.java Wyświetl plik

@@ -1,53 +0,0 @@
1
-package io.zipcoder.casino.cardgames.cards;
2
-
3
-import io.zipcoder.casino.utilities.Console;
4
-
5
-
6
-import java.util.ArrayDeque;
7
-import java.util.ArrayList;
8
-import java.util.Collections;
9
-import java.util.Deque;
10
-
11
-public class Deck extends ArrayDeque<Card> {
12
-    // private ArrayList<Card> deck;
13
-
14
-    public Deck(){
15
-        ArrayList<Card> freshDeck = new ArrayList<>();
16
-        for (int i = 0; i < 13; i++){
17
-            CardValue value = CardValue.values()[i];
18
-
19
-            for (int j =0; j < 4;j++){
20
-                Card card = new Card (value, CardSuit.values()[j]);
21
-                freshDeck.add(card);
22
-            }
23
-        }
24
-
25
-        Collections.shuffle(freshDeck);
26
-
27
-        this.addAll(freshDeck);
28
-
29
-//        for (Card aCard : this) {
30
-//            Card oneCard = aCard;
31
-//
32
-////            Console.println(oneCard.getCardValue() + " of " + oneCard.getSuit());
33
-////            CardValue.values();
34
-//
35
-//        }
36
-    }
37
-
38
-    public static void main(String[] args) {
39
-//        CardValue[] cards = CardValue.values();
40
-//        for (CardValue value : cards) {
41
-//            System.out.println(value.getCardValue());
42
-//        }
43
-        Deck deck = new Deck();
44
-        int cardCount = 0;
45
-        for (Card card : deck) {
46
-            cardCount++;
47
-//            System.out.println(card.getCardValue() + " " + card.getSuit());
48
-        }
49
-
50
-    }
51
-
52
-
53
-}

+ 1
- 1
src/main/java/io/zipcoder/casino/dicegames/DiceGame.java Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino.dicegames;
2 2
 
3
-import io.zipcoder.casino.dicegames.dice.Dice;
3
+import io.zipcoder.casino.utilities.Dice;
4 4
 import io.zipcoder.casino.utilities.Game;
5 5
 
6 6
 public class DiceGame extends Game {

+ 1
- 1
src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino.player;
2 2
 
3
-import io.zipcoder.casino.cardgames.cards.CardHand;
3
+import io.zipcoder.casino.utilities.containers.CardHand;
4 4
 
5 5
 public class BlackJackPlayer{
6 6
     private CardHand hand;

+ 1
- 1
src/main/java/io/zipcoder/casino/player/GoFishPlayer.java Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino.player;
2 2
 
3
-import io.zipcoder.casino.cardgames.cards.CardHand;
3
+import io.zipcoder.casino.utilities.containers.CardHand;
4 4
 
5 5
 public class GoFishPlayer {
6 6
     private CardHand hand;

src/main/java/io/zipcoder/casino/cardgames/cards/Card.java → src/main/java/io/zipcoder/casino/utilities/Card.java Wyświetl plik

@@ -1,4 +1,7 @@
1
-package io.zipcoder.casino.cardgames.cards;
1
+package io.zipcoder.casino.utilities;
2
+
3
+import io.zipcoder.casino.utilities.enums.CardSuit;
4
+import io.zipcoder.casino.utilities.enums.CardValue;
2 5
 
3 6
 public final class Card {
4 7
 

src/main/java/io/zipcoder/casino/dicegames/dice/Dice.java → src/main/java/io/zipcoder/casino/utilities/Dice.java Wyświetl plik

@@ -1,8 +1,7 @@
1
-package io.zipcoder.casino.dicegames.dice;
1
+package io.zipcoder.casino.utilities;
2 2
 
3 3
     import java.util.ArrayList;
4 4
     import java.util.HashMap;
5
-    import java.util.List;
6 5
     import java.util.Random;
7 6
 
8 7
     public class Dice {
@@ -30,8 +29,6 @@ package io.zipcoder.casino.dicegames.dice;
30 29
             return lastRollGraphic;
31 30
         }
32 31
 
33
-        //        Dice(){ this.dieCount = 1; }
34
-
35 32
         public Dice(int dieCount) {
36 33
             this.dieCount = dieCount;
37 34
         }

+ 4
- 10
src/main/java/io/zipcoder/casino/utilities/Game.java Wyświetl plik

@@ -1,17 +1,11 @@
1 1
 package io.zipcoder.casino.utilities;
2 2
 
3
-public class Game {
4
-    public void promptContinue() {
5
-        // REMATCH (runGame), NEXT GAME (return to casino), EXIT CASINO (quit)
6
-    }
3
+public abstract class Game {
4
+    abstract void promptContinue();
7 5
 
8
-    public void runGame() {
9
-        //initializes game
10
-    }
6
+    abstract void runGame();
11 7
 
12
-    public void endGame() {
13
-        //ends game, returns to Casino prompt loop
14
-    }
8
+    abstract void endGame();
15 9
 
16 10
 
17 11
 }

src/main/java/io/zipcoder/casino/cardgames/cards/CardHand.java → src/main/java/io/zipcoder/casino/utilities/containers/CardHand.java Wyświetl plik

@@ -1,6 +1,6 @@
1
-package io.zipcoder.casino.cardgames.cards;
1
+package io.zipcoder.casino.utilities.containers;
2 2
 
3
-import io.zipcoder.casino.utilities.Console;
3
+import io.zipcoder.casino.utilities.Card;
4 4
 
5 5
 import java.util.ArrayList;
6 6
 

+ 24
- 0
src/main/java/io/zipcoder/casino/utilities/containers/Deck.java Wyświetl plik

@@ -0,0 +1,24 @@
1
+package io.zipcoder.casino.utilities.containers;
2
+
3
+import io.zipcoder.casino.utilities.Card;
4
+import io.zipcoder.casino.utilities.enums.CardSuit;
5
+import io.zipcoder.casino.utilities.enums.CardValue;
6
+
7
+import java.util.ArrayDeque;
8
+import java.util.ArrayList;
9
+import java.util.Collections;
10
+
11
+public class Deck extends ArrayDeque<Card> {
12
+    public Deck(){
13
+        ArrayList<Card> freshDeck = new ArrayList<>();
14
+        for (int i = 0; i < 13; i++){
15
+            CardValue value = CardValue.values()[i];
16
+            for (int j =0; j < 4;j++){
17
+                Card card = new Card (value, CardSuit.values()[j]);
18
+                freshDeck.add(card);
19
+            }
20
+        }
21
+        Collections.shuffle(freshDeck);
22
+        this.addAll(freshDeck);
23
+    }
24
+}

src/main/java/io/zipcoder/casino/cardgames/cards/CardSuit.java → src/main/java/io/zipcoder/casino/utilities/enums/CardSuit.java Wyświetl plik

@@ -1,4 +1,4 @@
1
-package io.zipcoder.casino.cardgames.cards;
1
+package io.zipcoder.casino.utilities.enums;
2 2
 
3 3
 public enum CardSuit {
4 4
     HEARTS('♥'),

src/main/java/io/zipcoder/casino/cardgames/cards/CardValue.java → src/main/java/io/zipcoder/casino/utilities/enums/CardValue.java Wyświetl plik

@@ -1,4 +1,4 @@
1
-package io.zipcoder.casino.cardgames.cards;
1
+package io.zipcoder.casino.utilities.enums;
2 2
 
3 3
 public enum CardValue {
4 4
     ACE(1),

+ 12
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java Wyświetl plik

@@ -1,5 +1,17 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import io.zipcoder.casino.utilities.Dice;
5
+import org.junit.Test;
6
+
4 7
 public class CasinoTest {
8
+
9
+    @Test public void graphicTest() {
10
+        Dice dice = new Dice();
11
+
12
+        for (int i = 1; i <= 6; i++) {
13
+            System.out.println(dice.getDieGraphic(i));
14
+        }
15
+    }
16
+
5 17
 }