Browse Source

resolved merge conf

Connor Dunnigan 6 years ago
parent
commit
d03bfd337b

+ 16
- 46
src/main/java/io/zipcoder/casino/Casino.java View File

49
     }
49
     }
50
 
50
 
51
     public void chooseTable() {
51
     public void chooseTable() {
52
-
53
-      console.println("GAME LIST\n");
54
-      console.println("1. CRAPS\n");
55
-      console.println("2. BLACK JACK\n");
56
-      console.println("3. GO FISH\n");
57
-      console.println("CHOOSE TABLE\n");
58
-      Integer number=console.getIntegerInput("") ;
59
-       switch(number){
60
-         case 1:
61
-             runGame(new Craps());
62
-             break;
63
-        case 2:
64
-             runGame(new BlackJack());
65
-             break;
66
-        case 3:
67
-             runGame(new GoFish());
68
-             break;
69
-       }        
52
+        Game game = null;
53
+
54
+        Integer gameChoice = console.getGameChoice();
55
+
56
+        switch(gameChoice){
57
+            case 1:
58
+                game = new Craps();
59
+                break;
60
+            case 2:
61
+                game = new BlackJack();
62
+                break;
63
+            case 3:
64
+                game = new GoFish();
65
+                break;
66
+        }
67
+        runGame(game);
70
      }
68
      }
71
 
69
 
72
     private void runGame(Game game) {
70
     private void runGame(Game game) {
73
-        console.println("WELCOME TO %s", game.getClassName());
74
         this.game = game;
71
         this.game = game;
75
     }
72
     }
76
 
73
 
77
-    public void confirmPlayers() {
78
-      boolean isConfirmed = false;
79
-      while(!isConfirmed){
80
-        console.println("Current Players: ");
81
-        for(Player player : players.getPlayers()){
82
-          console.println(player.getName());
83
-        }
84
-        Integer choice = console.getIntegerInput("Choose option:\n (1)Confirm Players\n (2)Add Player\n (3)Remove Player\n");
85
-        String name;
86
-        switch(choice){
87
-          case 1: isConfirmed = true;
88
-            break;
89
-          case 2: name = console.getStringInput("Enter name of player to add: ");
90
-                    players.addPlayer(new Player(name));
91
-            break;
92
-          case 3: name = console.getStringInput("Enter name of player to remove: ");
93
-                  for(Player player : players.getPlayers()){
94
-                    if(player.getName() == name)
95
-                      players.removePlayer(player);
96
-                  }
97
-            break;
98
-          default: break;
99
-        }
100
-      }
101
-    }
102
-
103
     public void bootPlayer() {
74
     public void bootPlayer() {
104
         // If player balance is 0, player game over
75
         // If player balance is 0, player game over
105
         for (int i = 0; i < players.getPlayers().size(); i++) {
76
         for (int i = 0; i < players.getPlayers().size(); i++) {
111
     }
82
     }
112
 
83
 
113
     public void printBalance() {
84
     public void printBalance() {
114
-      console.println("FYI guys:\n");
115
       for (Player player : players.getPlayers()){
85
       for (Player player : players.getPlayers()){
116
         console.println(String.format(player.getName() + " has " + player.getChipBalance() + " chips.\n"));
86
         console.println(String.format(player.getName() + " has " + player.getChipBalance() + " chips.\n"));
117
       }
87
       }

+ 112
- 56
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java View File

17
     private Deck deck = new Deck();
17
     private Deck deck = new Deck();
18
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
18
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
19
     CardHand dealerHand = new CardHand();
19
     CardHand dealerHand = new CardHand();
20
-    long bet;
21
-
22
 
20
 
23
     public BlackJack(){
21
     public BlackJack(){
22
+        announceGameChoice();
24
         readyPlayers();
23
         readyPlayers();
24
+        placePlayerBets();
25
         dealCards(2);
25
         dealCards(2);
26
         runGame();
26
         runGame();
27
     }
27
     }
39
         }
39
         }
40
     }
40
     }
41
 
41
 
42
-    public boolean play(BlackJackPlayer currentPlayer, long bet) {
43
-        // this.bet = bet;
42
+    boolean continueGame = true;
43
+    public void play(BlackJackPlayer currentPlayer, long bet) {
44
+        boolean dealerWins = false;
44
 
45
 
45
-        Console.println("The dealer is dealing cards to the players.");
46
+        evalBlackjack(); // all players evaluate hand for blackjack. Winners are paid out and removed.
47
+        dealerWins = dealerCheck(); //TO ADD: if both player and dealer have blackjack, player keeps bet
48
+        if (dealerWins == true) continueGame = false; // all players lose
46
 
49
 
47
-        for (BlackJackPlayer p: this.blackJackPlayers){ //gets bet from each player
48
-            placeBet(p);
49
-        }
50
+        while (continueGame == true) {
51
+            dealerDraw();
50
 
52
 
51
-        dealerHand.add(deck.removeFirst());
52
-        dealerHand.add(deck.removeFirst());
53
+            Console.println("Dealer is showing a " + dealerHand.get(0).getCard()); // dealer reveals upcard
54
+
55
+            playersTurn();
56
+
57
+            if (blackJackPlayers.size() < 1) continueGame = false;
58
+
59
+            continueGame = dealersTurn(); // IMPLEMENT: if dealer loses, all players should receive payout
60
+
61
+            evalWinner();
62
+
63
+            continueGame = false;
64
+        }
53
 
65
 
54
-        Console.println("Dealer is showing a " + dealerHand.get(0).getCard()); // dealer reveals upcard
66
+        if (dealerWins == true) {
67
+            dealerCollectAll();
68
+        }
55
 
69
 
70
+    }
56
 
71
 
72
+    public boolean dealerCheck() {
57
         if (getSum(dealerHand) == 21){
73
         if (getSum(dealerHand) == 21){
58
-            Console.println("Dealer has +," +  dealerHand.display());
59
-            Console.println("You have " + currentPlayer.getHand().display());
74
+            Console.println("Dealer has " +  dealerHand.display());
60
             Console.println("Dealer has blackjack. Dealer wins.");
75
             Console.println("Dealer has blackjack. Dealer wins.");
61
-            for (BlackJackPlayer p: this.blackJackPlayers){ // collects bet from all players
62
-                evaluateBet(p.getP(), bet);
63
-            }
76
+            return true;
64
         }
77
         }
65
-            evalBlackjack();
78
+        return false;
79
+    }
66
 
80
 
67
-            playersTurn();
81
+    public void dealerCollectAll() {
82
+        for (BlackJackPlayer p: this.blackJackPlayers){ // collects bet from all players
83
+            evaluateBet(p, -p.getBet());
84
+        }
85
+    }
68
 
86
 
87
+    public void payoutAll() {
88
+        for (BlackJackPlayer p: this.blackJackPlayers){ // collects bet from all players
89
+            long winnings = p.getBet()*2;
90
+            evaluateBet(p, winnings);
91
+        }
92
+    }
69
 
93
 
70
-        if (dealersTurn()) return false;
94
+    public void dealerCollect(BlackJackPlayer p) {
95
+        evaluateBet(p, -p.getBet());
96
+    }
71
 
97
 
72
-        return evalWinner(currentPlayer, bet);
98
+    public void placePlayerBets() {
99
+        for (BlackJackPlayer p: this.blackJackPlayers){ //gets bet from each player
100
+            Console.println(p.getName());
101
+            placeBet(p);
102
+        }
103
+    }
73
 
104
 
105
+    public void dealerDraw() {
106
+        dealerHand.add(deck.removeFirst());
107
+        dealerHand.add(deck.removeFirst());
74
     }
108
     }
75
 
109
 
76
-    public boolean evalWinner(BlackJackPlayer currentPlayer, long bet) {
77
-        if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
78
-            Console.println("Dealer wins on a tie.");
79
-            evaluateBet(currentPlayer.getP(), -bet);
80
-            return false;
81
-        } else if (getSum(dealerHand) <=21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
82
-            Console.println("Dealer wins.");
83
-            evaluateBet(currentPlayer.getP(), -bet);
84
-            return false;
85
-        } else {
86
-            Console.println("You win!");
87
-            evaluateBet(currentPlayer.getP(), bet);
88
-            return false;
110
+    public boolean evalWinner() {
111
+        for (BlackJackPlayer currentPlayer : blackJackPlayers) {
112
+            if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
113
+                Console.println(String.format("Against %s's hand, dealer wins on a tie.", currentPlayer.getP().getName()));
114
+                evaluateBet(currentPlayer, -currentPlayer.getBet());
115
+                return false;
116
+            } else if (getSum(dealerHand) <= 21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
117
+                Console.println(String.format("Against %s's hand, dealer wins."), currentPlayer.getP().getName());
118
+                evaluateBet(currentPlayer, -currentPlayer.getBet());
119
+                return false;
120
+            } else {
121
+                Console.println(String.format("%s, you win!", currentPlayer.getP().getName()));
122
+                evaluateBet(currentPlayer, currentPlayer.getBet());
123
+                return false;
124
+            }
89
         }
125
         }
126
+        return true;
90
     }
127
     }
91
 
128
 
92
     public boolean dealersTurn() {
129
     public boolean dealersTurn() {
100
 
137
 
101
         if (getSum(dealerHand) > 21) {
138
         if (getSum(dealerHand) > 21) {
102
             Console.println("Dealer busted. You win.");
139
             Console.println("Dealer busted. You win.");
103
-            return true;
140
+            payoutAll();
141
+            return false;
104
         }
142
         }
105
-        return false;
143
+
144
+        return true;
106
     }
145
     }
107
 
146
 
108
     public void playersTurn() {
147
     public void playersTurn() {
148
+        BlackJackPlayer currentPlayer;
109
 
149
 
110
-        for (BlackJackPlayer currentPlayer : this.blackJackPlayers) {
150
+        for (int i = 0; i < blackJackPlayers.size(); i++) {
151
+            currentPlayer = blackJackPlayers.get(i);
111
 
152
 
112
             Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
153
             Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
113
-
114
-            Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
154
+            displaySumPlayerHand(currentPlayer);
115
 
155
 
116
             hitOrStand(currentPlayer);
156
             hitOrStand(currentPlayer);
157
+        }
158
+    }
117
 
159
 
118
-            Console.println("You have: " + currentPlayer.getHand().display());
119
-            Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
120
-
121
-            if (getSum(currentPlayer.getHand()) > 21){
122
-                Console.println("You busted. House wins.");
123
-            }
160
+    private boolean playerBust(BlackJackPlayer currentPlayer) {
161
+        if (getSum(currentPlayer.getHand()) > 21){
162
+            Console.println(currentPlayer.getP().getName() + " busted. House wins.");
163
+            dealerCollect(currentPlayer);
164
+            blackJackPlayers.remove(currentPlayer);
165
+            return false;
124
         }
166
         }
167
+        return true;
168
+    }
169
+
170
+    private void displaySumPlayerHand(BlackJackPlayer currentPlayer) {
171
+        Console.println(currentPlayer.getP().getName() + ", you have: " + currentPlayer.getHand().display() + "\nThis hand is worth " + getSum(currentPlayer.getHand()));
125
     }
172
     }
126
 
173
 
127
     public void hitOrStand(BlackJackPlayer currentPlayer) {
174
     public void hitOrStand(BlackJackPlayer currentPlayer) {
128
-        String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
129
 
175
 
130
         while (getSum(currentPlayer.getHand()) < 21) {
176
         while (getSum(currentPlayer.getHand()) < 21) {
177
+            String hitOrStand = Console.getStringInput(currentPlayer.getP().getName() + ", do you want to Hit or Stand?\nEnter H for Hit or S for Stand");
178
+
131
             if (hitOrStand.equalsIgnoreCase("H")) {
179
             if (hitOrStand.equalsIgnoreCase("H")) {
132
                 dealCards(currentPlayer, 1);
180
                 dealCards(currentPlayer, 1);
181
+                Console.println(currentPlayer.getP().getName() + ", you have been dealt %s.", currentPlayer.getHand().get(currentPlayer.getHand().size()-1).getCard());
182
+                displaySumPlayerHand(currentPlayer);
183
+                continueGame = playerBust(currentPlayer);
133
             } else if (hitOrStand.equalsIgnoreCase("S")) {
184
             } else if (hitOrStand.equalsIgnoreCase("S")) {
134
                 break;
185
                 break;
135
             } else {
186
             } else {
139
     }
190
     }
140
 
191
 
141
     public void evalBlackjack() {
192
     public void evalBlackjack() {
142
-        for (BlackJackPlayer p: this.blackJackPlayers)
143
-        if (getSum(p.getHand()) == 21){
144
-            Console.println("Dealer has " + dealerHand.display());
145
-            Console.println("You have " + p.getHand().display());
146
-            Console.println("You have blackjack. You win.");
193
+        BlackJackPlayer p;
194
+        for (int i = 0; i < blackJackPlayers.size(); i++) {
195
+            p = blackJackPlayers.get(i);
196
+            if (getSum(p.getHand()) == 21) {
197
+                Console.println(p.getP().getName() + ", you have " + p.getHand().display());
198
+                Console.println(p.getP().getName() + ", you have blackjack. You win!");
199
+                evaluateBet(p, p.getBet());
200
+                blackJackPlayers.remove(i);
201
+            }
147
         }
202
         }
148
     }
203
     }
149
 
204
 
150
     @Override
205
     @Override
151
     public void dealCards(int numberOfCards) {
206
     public void dealCards(int numberOfCards) {
152
-
207
+        Console.println("The dealer is dealing cards to the players.");
153
         for(BlackJackPlayer p: blackJackPlayers){ //deal 2 cards to each player
208
         for(BlackJackPlayer p: blackJackPlayers){ //deal 2 cards to each player
154
             for (int i = 0; i < numberOfCards; i++) {
209
             for (int i = 0; i < numberOfCards; i++) {
155
                 Card card = deck.removeFirst();
210
                 Card card = deck.removeFirst();
167
         }
222
         }
168
     }
223
     }
169
 
224
 
225
+    @Override
170
     public void placeBet(Player player) {
226
     public void placeBet(Player player) {
171
-        this.bet = Console.getLongInput("Please enter your bet.");
227
+        BlackJackPlayer blackJackPlayer = (BlackJackPlayer) player;
228
+        long bet = Console.getLongInput(String.format("%s, please enter your bet.", ((BlackJackPlayer) player).getP().getName()));
229
+        blackJackPlayer.setBet(bet);
172
     }
230
     }
173
 
231
 
174
-
175
     public void evaluateBet(Player player, long payout) {
232
     public void evaluateBet(Player player, long payout) {
176
         player.setChipBalance(player.getChipBalance()+payout);
233
         player.setChipBalance(player.getChipBalance()+payout);
177
     }
234
     }
183
         return card;
240
         return card;
184
     }
241
     }
185
 
242
 
186
-
187
     public int  getSum(CardHand cardHand) {
243
     public int  getSum(CardHand cardHand) {
188
         int cardSum = 0;
244
         int cardSum = 0;
189
         boolean ace = false;
245
         boolean ace = false;
199
             }
255
             }
200
             cardSum = cardSum + cardValue;
256
             cardSum = cardSum + cardValue;
201
         }
257
         }
202
-        if (cardHand.size() == 2 && ace == true && cardSum + 10 == 21) {
258
+        if (cardHand.size() == 2 && ace && cardSum + 10 == 21) {
203
             cardSum = cardSum + 10;
259
             cardSum = cardSum + 10;
204
         }
260
         }
205
         return cardSum;
261
         return cardSum;
207
 
263
 
208
     public void revealCard(){
264
     public void revealCard(){
209
         Card newCard = drawCard();
265
         Card newCard = drawCard();
210
-        Console.println("Dealer drew a " + newCard.getCardValue() + " of " + newCard.getSuit());
266
+        Console.println("Dealer drew a " + newCard.getCardValue() + " of " + newCard.getSuit().getCardGraphic());
211
         dealerHand.add(newCard);
267
         dealerHand.add(newCard);
212
     }
268
     }
213
 
269
 

+ 2
- 0
src/main/java/io/zipcoder/casino/dicegames/Craps.java View File

1
 package io.zipcoder.casino.dicegames;
1
 package io.zipcoder.casino.dicegames;
2
 
2
 
3
+import io.zipcoder.casino.player.BlackJackPlayer;
3
 import io.zipcoder.casino.utilities.Console;
4
 import io.zipcoder.casino.utilities.Console;
4
 import io.zipcoder.casino.utilities.interfaces.Gamble;
5
 import io.zipcoder.casino.utilities.interfaces.Gamble;
5
 import io.zipcoder.casino.player.CrapsPlayer;
6
 import io.zipcoder.casino.player.CrapsPlayer;
15
     long bet;
16
     long bet;
16
 
17
 
17
     public Craps() {
18
     public Craps() {
19
+        announceGameChoice();
18
         readyPlayers();
20
         readyPlayers();
19
         //promptBets();
21
         //promptBets();
20
         runGame();
22
         runGame();

+ 0
- 9
src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java View File

26
     public void hit(Player player) {
26
     public void hit(Player player) {
27
     }
27
     }
28
 
28
 
29
-    public void stay(Player player) {
30
-    }
31
-
32
     public Player getP() {
29
     public Player getP() {
33
         return blackJackPlayer;
30
         return blackJackPlayer;
34
     }
31
     }
37
         return hand;
34
         return hand;
38
     }
35
     }
39
 
36
 
40
-    public void setHand(CardHand hand) {
41
-        this.hand = hand;
42
-    }
43
-
44
-
45
-
46
 }
37
 }

+ 11
- 0
src/main/java/io/zipcoder/casino/utilities/Console.java View File

1
 package io.zipcoder.casino.utilities;
1
 package io.zipcoder.casino.utilities;
2
 
2
 
3
+import io.zipcoder.casino.Casino;
4
+
3
 import java.awt.peer.SystemTrayPeer;
5
 import java.awt.peer.SystemTrayPeer;
4
 import java.util.Scanner;
6
 import java.util.Scanner;
5
 
7
 
137
         return userInput;
139
         return userInput;
138
     }
140
     }
139
 
141
 
142
+    public Integer getGameChoice() {
143
+        println("GAME LIST\n");
144
+        println("1. CRAPS\n");
145
+        println("2. BLACK JACK\n");
146
+        println("3. GO FISH\n");
147
+        println("CHOOSE TABLE\n");
148
+        return getIntegerInput("");
149
+    }
150
+
140
 
151
 
141
 //
152
 //
142
 //    public Integer getPlayersInput(String prompt){
153
 //    public Integer getPlayersInput(String prompt){

+ 0
- 44
src/main/java/io/zipcoder/casino/utilities/Pot.java View File

1
-package io.zipcoder.casino.utilities;
2
-
3
-public class Pot {
4
-
5
-    private static final Pot INSTANCE = new Pot();
6
-
7
-    private long bettingPool;
8
-    private long currentBet;
9
-    private long currentAmount;
10
-
11
-    private Pot(){}
12
-
13
-    public static Pot getInstance(){
14
-        return INSTANCE;
15
-    }
16
-
17
-    public static Pot getINSTANCE() {
18
-        return INSTANCE;
19
-    }
20
-
21
-    public long getBettingPool() {
22
-        return bettingPool;
23
-    }
24
-
25
-    public void setBettingPool(long bettingPool) {
26
-        this.bettingPool = bettingPool;
27
-    }
28
-
29
-    public long getCurrentBet() {
30
-        return currentBet;
31
-    }
32
-
33
-    public void setCurrentBet(long currentBet) {
34
-        this.currentBet = currentBet;
35
-    }
36
-
37
-    public long getCurrentAmount() {
38
-        return currentAmount;
39
-    }
40
-
41
-    public void setCurrentAmount(long currentAmount) {
42
-        this.currentAmount = currentAmount;
43
-    }
44
-}

+ 11
- 2
src/main/java/io/zipcoder/casino/utilities/abstracts/Game.java View File

1
 package io.zipcoder.casino.utilities.abstracts;
1
 package io.zipcoder.casino.utilities.abstracts;
2
 
2
 
3
+import io.zipcoder.casino.utilities.Console;
4
+
5
+import java.sql.DriverManager;
6
+
3
 public abstract class Game {
7
 public abstract class Game {
4
-    String className = this.getClass().getName();
8
+    String className = this.getClass().getSimpleName();
5
 
9
 
6
     public abstract void promptContinue();
10
     public abstract void promptContinue();
7
 
11
 
8
     public abstract void runGame();
12
     public abstract void runGame();
9
 
13
 
10
-    public String getClassName() {
14
+    private String getClassName() {
11
         return className;
15
         return className;
12
     }
16
     }
17
+
18
+    protected void announceGameChoice() {
19
+        Console console = new Console();
20
+        console.println("Welcome to %s\n", this.getClassName());
21
+    }
13
 }
22
 }

+ 2
- 1
src/main/java/io/zipcoder/casino/utilities/interfaces/Gamble.java View File

3
 import io.zipcoder.casino.player.Player;
3
 import io.zipcoder.casino.player.Player;
4
 
4
 
5
 public interface Gamble {
5
 public interface Gamble {
6
-    public void placeBet(Player player);
6
+
7
+    void placeBet(Player player);
7
 
8
 
8
     void evaluateBet(Player player, long payout);
9
     void evaluateBet(Player player, long payout);
9
 }
10
 }