Przeglądaj źródła

merge for war card win method

Nick Satinover 6 lat temu
rodzic
commit
ecd1604823

+ 4
- 0
src/main/java/io/zipcoder/casino/CardPlayer.java Wyświetl plik

@@ -15,6 +15,10 @@ public class CardPlayer {
15 15
         return hand;
16 16
     }
17 17
 
18
+    public void setHand(ArrayList<Card> hand) {
19
+        this.hand = hand;
20
+    }
21
+
18 22
     public Player getPlayer() {
19 23
         return player;
20 24
     }

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

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public interface Gamble {
4
-     void Bet(int betAmount);
4
+     void Bet(Player player, int betAmount);
5 5
      int Payout(int payoutAmount);
6 6
 }

+ 8
- 0
src/main/java/io/zipcoder/casino/Printer.java Wyświetl plik

@@ -25,4 +25,12 @@ public class Printer {
25 25
     public static void unacceptableMinBet(){
26 26
         System.out.println("Your bet must be above $0");
27 27
     }
28
+
29
+    public static void studHandsDealt(){
30
+        System.out.println("Each player Dealt 3 cards");
31
+    }
32
+
33
+    public static void showCard(Player player, Card card){
34
+        System.out.println(player.getName() + " shows a " + card.getName());
35
+    }
28 36
 }

+ 75
- 46
src/main/java/io/zipcoder/casino/Stud.java Wyświetl plik

@@ -1,26 +1,36 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
-import java.util.ArrayList;
3
+import java.util.Scanner;
4 4
 
5 5
 public class Stud extends CardGame implements Gamble, Game {
6 6
     // ArrayList<Card> playerHand = new ArrayList<>(3);
7
+    Scanner scanner = new Scanner(System.in);
7 8
 
8 9
     public Stud(int minBet, int maxBet, int ante) {
9 10
         super(minBet, maxBet, ante);
10 11
 
11 12
     }
12
-
13
-
14
-    public void playCard(){
15
-        //turn card faceUp
13
+    
14
+    public void playCard(Player player, Card card){
15
+        card.setVisibility(true);               //CARD isVISIBLE
16
+        Printer.showCard(player, card);         //PRINT card name to CONSOLE
16 17
     }
17 18
 
18
-    public Player determineWinner(){
19
-        return null;
19
+    /**
20
+     * Need method to determine what hand wins first
21
+     */
22
+    public void determineWinner(){
23
+        CardPlayer winningPlayer = super.getPlayers().get(0); // 0 index must be dealer in case of a tie
24
+        for(int i = 0; i < super.getPlayers().size(); i ++)
25
+        {
26
+            CardPlayer player = super.getPlayers().get(i);
27
+            player.getHand().get(i);
28
+        }
20 29
     }
21 30
 
22
-    public void Bet(int betAmount) {
31
+    public void Bet(Player player, int betAmount) {
23 32
         super.changeTablePot(betAmount);
33
+        player.changeBalance(betAmount * -1);
24 34
     }
25 35
 
26 36
     public int Payout(int payoutAmount) {
@@ -45,56 +55,75 @@ public class Stud extends CardGame implements Gamble, Game {
45 55
     }
46 56
 
47 57
     public void StartGame() {
48
-        Deck deck = new Deck();
49
-        // Set Hand Size for game
50
-        setHandSize(3);
51
-        //Player(s) pay ante
52
-        payAnte();
53
-        //Dealer deals 3 cards in turn to each player(and dealer)
54
-        Deal();
58
+        Deck deck = new Deck();     //CREATE deck for game       
59
+        setHandSize(3);             //SET Hand Size for game
60
+        payAnte();                  //PAY ante (all players)
61
+        Deal();                     //DEALS hands to each player
62
+        StartRound();               //METHOD called
63
+        Printer.studHandsDealt();   //CONSOLE dealt msg
55 64
     }
56 65
 
66
+    /**
67
+     * Game played in this method
68
+     */
57 69
     public void StartRound() {
70
+        for (int i = 0; i < getHandSize() - 1; i++){    //Each player turns a card in hand to face up
71
+            gameRound();
72
+        }
73
+        lastGameRound();
74
+        determineWinner();
75
+    }
58 76
 
59
-        //Each player turns a card1 in hand to face up
60
-        //player(s) bets or folds
61
-            //if bet, players turn card2 face up
62
-        //player(s) bets or folds
63
-            //if bet, players turn card3 face up
64
-        //determinewinner
65
-        //add all table cards to table deck face down
77
+    /**
78
+     * Plays through rounds that includes flipping cards face up and then betting or folding
79
+     */
80
+    public void gameRound(){
81
+        for (int j = 0; j < getPlayers().size(); j++) {
82
+            CardPlayer player = super.getPlayers().get(j);              //GET a player
83
+            playCard(player.getPlayer(), player.getHand().get(j));      //SHOW-PRINT players first CARD
84
+        }
85
+        for (int j = 0; j < getPlayers().size(); j++) {                 //Betting round or fold
86
+            CardPlayer player = super.getPlayers().get(j);
87
+            int bet;
88
+            //ask player to bet and pass amount to Bet(betAmount
89
+            System.out.println("Enter a bet, if 0 is entered you fold");
90
+            bet = scanner.nextInt();
91
+            if (bet == 0){
92
+                System.out.println(player.getPlayer().getName() + " folds.");
93
+                //if fold, player is removed from game
94
+                //if only 1 player (dealer) game ends
95
+            } else {
96
+                //wants a cardplayer but bet method is updating balance on a 'player' - casted CardPlayer to Player
97
+                Bet(super.getPlayers().get(j).getPlayer(), bet);
98
+                System.out.println(player.getPlayer().getName() + " bets: " + bet);
99
+            }
100
+        }
101
+    }
66 102
 
103
+    /**
104
+     * PreCondition: Betting rounds already played
105
+     * Plays through round that include flipping last card face up
106
+     * PostCondtion: tablePot is now at max value
107
+     * DetermineWinner() expected to be called after this method
108
+     */
109
+    public void lastGameRound(){
110
+        for (int j = 0; j < getPlayers().size(); j++) {
111
+            CardPlayer player = super.getPlayers().get(j);              //GET a player
112
+            playCard(player.getPlayer(), player.getHand().get(j));      //SHOW-PRINT players first CARD
113
+        }
67 114
     }
68 115
 
69
-    //public void
70 116
 
71 117
     /**
72 118
      * Deal each player(and dealer) 3 face down cards in turn
73 119
      */
74 120
     public void Deal() {
75
-        for(int i = 0; i < getHandSize() * getPlayers().size(); i ++)
76
-        {
77
-            //grab the card from the top (last added) to the deck
78
-            Card card = super.getDeck().pullCard();
79
-            //get the player whos hand we are adding the card to
80
-            CardPlayer player = super.getPlayers().get(i);
81
-            //add the card to their hand
82
-            player.getHand().add(card);
121
+        for(int i = 0; i < getHandSize(); i ++){                        //OUTER loop - run 3 times as there are 3 cards per hand
122
+            for (int j = 0; j < getPlayers().size(); j++) {             //INNER loop through each player
123
+                Card card = super.getDeck().pullCard();                     //PULL card from deck (removed from deck)
124
+                CardPlayer player = super.getPlayers().get(j);              //GET a player
125
+                player.getHand().add(card);                                 //ADD card to player hand
126
+            }
83 127
         }
84 128
     }
85 129
 }
86
-/*
87
-    public void Deal() {
88
-        for(int i = 0; i < getHandSize() * getPlayers().size(); i ++)
89
-        {
90
-            //grab the card from the top (last added) to the deck
91
-            Card card = deck.pullCard();
92
-            //get the player whos hand we are adding the card to
93
-            CardPlayer player = super.getPlayers().get(i);
94
-            //add the card to their hand
95
-            player.getHand().add(card);
96
-            //remove the card from the deck
97
-            super.getDeck().remove(card);
98
-        }
99
-    }
100
-    */

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

@@ -97,7 +97,8 @@ public class War extends CardGame implements Gamble, Game {
97 97
                 super.getDeck().remove(card);
98 98
             }
99 99
         }
100
-        System.out.println(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
100
+        System.out.println(super.getPlayersTurn().getPlayer().getName() +
101
+                "has: " + super.getPlayersTurn().getHand().size() + " cards.");
101 102
     }
102 103
 
103 104
 }