Pārlūkot izejas kodu

made some changes

ThuyKhong 6 gadus atpakaļ
vecāks
revīzija
3f9e4f8e37

+ 69
- 48
src/main/java/io/zipcoder/casino/BlackJack.java Parādīt failu

9
 
9
 
10
     private Deck deck = new Deck();
10
     private Deck deck = new Deck();
11
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
11
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
12
-    BlackJackPlayer blackJackPlayer = new BlackJackPlayer();
13
-    ArrayList<CardHand> cardHands;
12
+    CardHand playerHand = new CardHand();
13
+    CardHand dealerHand = new CardHand();
14
+    long bet;
15
+
14
 
16
 
15
     public BlackJack(){
17
     public BlackJack(){
18
+
16
         readyPlayers();
19
         readyPlayers();
20
+        placeBet();
21
+        run();
17
     }
22
     }
18
 
23
 
19
     public void readyPlayers() {
24
     public void readyPlayers() {
22
         }
27
         }
23
     }
28
     }
24
 
29
 
30
+    public void run(){
31
+        for(int i = 0; i < blackJackPlayers.size(); i++){
32
+            play(blackJackPlayers.get(i),blackJackPlayers.get(i).getBet());
33
+        }
34
+    }
35
+
36
+    public void play(BlackJackPlayer currentPlayer, long bet) {
37
+
38
+        this.bet = bet;
39
+
40
+        dealCards();
41
+
42
+        if (getSum(dealerHand) == 21){
43
+            Console.println("Dealer has " + dealerHand.cardHand.get(0)) + " and " + dealerHand.cardHand.get(1));
44
+            Console.println(("You have " + playerHand.cardHand.get(0)) + " and " + playerHand.cardHand.get(1));
45
+            Console.println("Dealer wins.");
46
+        }
47
+
48
+        if (getSum(playerHand) == 21){
49
+            Console.println("Dealer has " + dealerHand.cardHand.get(0)) + " and " + dealerHand.cardHand.get(1));
50
+            Console.println(("You have " + playerHand.cardHand.get(0)) + " and " + playerHand.cardHand.get(1));
51
+            Console.println("You wins.");
52
+        }
53
+
54
+        while(true) {
55
+
56
+            Console.println("You have: ");
57
+            for (int i = 0; i < playerHand.size(); i++) {
58
+                Console.println(" " + playerHand.getVardValue(i) + playerHand.getSuit(i));
59
+            }
60
+            Console.println("Dealer is showing a " + dealerHand.getCardValue(0) + " of " + dealerHand.getSuit(0));
61
+            Console.println("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
62
+            Console.getStringInput();
63
+
64
+            while (getSum(playerHand) < 21){
65
+            if (userInput.equals("H")) {
66
+                dealCards();
67
+            } else if (userInput.equals("S")){
68
+                break;
69
+            }else {
70
+                Console.println("Invalid input. Please enter H for Hit or S for Stand");
71
+            }
72
+            Console.println("You have: ");
73
+                for (int i = 0; i < playerHand.size(); i++) {
74
+                    Console.println(" " + playerHand.getVardValue(i) + playerHand.getSuit(i));
75
+                }
76
+                Console.println("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
77
+                }
78
+                return false;
79
+            }
80
+}
81
+
25
     public void dealCards(BlackJackPlayer player, int numberOfCards) {
82
     public void dealCards(BlackJackPlayer player, int numberOfCards) {
26
-        dealerHand.cardHand.add(); //deals 2 cards for dealer
27
 
83
 
28
         for(BlackJackPlayer p: blackJackPlayers){ //deal 2 cards to each player
84
         for(BlackJackPlayer p: blackJackPlayers){ //deal 2 cards to each player
29
             super.dealCards(p, 2);
85
             super.dealCards(p, 2);
86
+
30
         }
87
         }
31
     }
88
     }
32
 
89
 
90
+    public void placeBet() {
91
+        Console.println("Please enter your bet.");
92
+        bet = Console.getLongInput();
93
+    }
94
+
95
+
33
     public void drawCard() {
96
     public void drawCard() {
34
         // draws card from deck and adds it to "upcard" total
97
         // draws card from deck and adds it to "upcard" total
35
         dealerHand.cardHand.add(deck.deckOfCards.get(0));
98
         dealerHand.cardHand.add(deck.deckOfCards.get(0));
36
         deck.deckOfCards.remove(0);
99
         deck.deckOfCards.remove(0);
37
 
100
 
38
         upcardsValue += dealerHand.cardHand.(0);
101
         upcardsValue += dealerHand.cardHand.(0);
39
-//        System.out.println("You have the following cards");
40
-//        for(CardHand c:cardHands){
41
-//            System.out.println(c);
42
-//        }
43
     }
102
     }
44
 
103
 
45
     public void evaluateDealerHand() {
104
     public void evaluateDealerHand() {
59
         }
118
         }
60
     }
119
     }
61
 
120
 
62
-    public long placeBet(long currentBet) {
63
-        return blackJackPlayer.getChipBalance() - currentBet;
64
-    }
65
-
66
 
121
 
67
-    public void getSum(ArrayList<CardHand> cardHands) {
122
+    public int  getSum(CardHand cardHands) {
68
         int cardSum = 0;
123
         int cardSum = 0;
69
         boolean ace = false;
124
         boolean ace = false;
70
 
125
 
82
         if (ace == true && cardSum + 10 <= 21) {
137
         if (ace == true && cardSum + 10 <= 21) {
83
             cardSum = cardSum + 10;
138
             cardSum = cardSum + 10;
84
         }
139
         }
85
-
140
+        return cardSum;
86
     }
141
     }
87
 
142
 
88
     public void evaluateBet(BlackJackPlayer player, long payout){
143
     public void evaluateBet(BlackJackPlayer player, long payout){
89
 
144
 
90
     }
145
     }
91
 
146
 
92
-    public int revealCard(CardHand cardHand, int index){
93
-        return cardHand.getCardValue(index);
94
-    }
95
-
96
-    public void evaluatePlayerHand(){
97
-
98
-        while (true){
99
-            System.out.println("You have:");
100
-            for (int i = 0; i < cardHands.size(); i++) {
101
-                System.out.println(" " + revealCard(cardHand, i));
102
-            }
103
-            System.out.println("The dealer is showing a " + revealCard(dealerHand,0));
104
-            System.out.println("Would you like to Hit (H) or Stand (S)?");
105
-        }
106
-        // print player's cardHands and sum
107
-        //if player has blackjack (ace + face)
108
-        //show dealer's card, player win or tie?
109
-
110
-        //while player's sum is <21
111
-        //prompt player to "Stand" or "Hit"
112
-
113
-
114
-
115
-
116
-    }
117
-
118
-    public void run(){
119
-        boolean quit = false;
120
-        while (quit == false) {
121
-            drawCard();
122
-
123
-
147
+    public void revealCard(){
124
 
148
 
125
-            // at the end of each loop, ask players if they would like to continue
126
-        }
127
     }
149
     }
128
 
150
 
129
-
130
 }
151
 }

+ 2
- 2
src/main/java/io/zipcoder/casino/Console.java Parādīt failu

100
         print(output + "\n", args);
100
         print(output + "\n", args);
101
     }
101
     }
102
 
102
 
103
-    public String getStringInput(String prompt){
103
+    public static String getStringInput(String prompt){
104
         Scanner scanner = new Scanner(System.in);
104
         Scanner scanner = new Scanner(System.in);
105
         println(prompt);
105
         println(prompt);
106
         String userInput = scanner.nextLine();
106
         String userInput = scanner.nextLine();
113
          return userInput;
113
          return userInput;
114
 
114
 
115
      }
115
      }
116
-     public  Long getLongInput(String prompt) {
116
+     public  static Long getLongInput(String prompt) {
117
          Scanner scanner = new Scanner(System.in);
117
          Scanner scanner = new Scanner(System.in);
118
          println(prompt);
118
          println(prompt);
119
          Long userInput = scanner.nextLong();
119
          Long userInput = scanner.nextLong();

+ 13
- 0
src/test/java/io/zipcoder/casino/BlackJackTest.java Parādīt failu

1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class BlackJackTest {
6
+    CardHand playerHand = new CardHand();
7
+
8
+    @Test
9
+    public void testDealCards(){
10
+
11
+        playerHand.
12
+    }
13
+}