Browse Source

deckclass

Jason Gibbs 6 years ago
parent
commit
8c1de97a74

+ 15
- 1
src/main/java/io/zipcoder/casino/Card.java View File

@@ -4,10 +4,13 @@ public class Card {
4 4
 
5 5
     private Suit suit;
6 6
     private Rank rank;
7
+    private int x;
8
+
7 9
 
8 10
     public Card(Suit suit, Rank rank) {
9 11
         this.suit = suit;
10 12
         this.rank = rank;
13
+        x = 0;
11 14
     }
12 15
 
13 16
     public Rank getRank() {
@@ -28,6 +31,17 @@ public class Card {
28 31
 
29 32
     @Override
30 33
     public String toString() {
31
-        return rank + " of " + suit;
34
+        String describe = "";
35
+        int x = 5;
36
+        if (suit.equals(Suit.SPADES)) {
37
+            describe = rank + "\u2660 of " + suit + "\n";
38
+        } else if (suit.equals(Suit.CLUBS)) {
39
+            describe = rank + "\u2663 of " + suit + "\n";
40
+        } else if (suit.equals(Suit.DIAMONDS)) {
41
+            describe = rank + "\u2666 of " + suit + "\n";
42
+        } else if (suit.equals(Suit.HEARTS)) {
43
+            describe = rank + "\u2665 of " + suit + "\n";
44
+        }
45
+        return describe + x;
32 46
     }
33 47
 }

+ 19
- 0
src/main/java/io/zipcoder/casino/CardDeck.java View File

@@ -1,4 +1,5 @@
1 1
 package io.zipcoder.casino;
2
+import java.util.Collections;
2 3
 import java.util.List;
3 4
 import java.util.ArrayList;
4 5
 import java.util.Random;
@@ -22,4 +23,22 @@ public class CardDeck {
22 23
         System.out.println(deck.toString());
23 24
         return deck;
24 25
     }
26
+
27
+    public void shuffle() {
28
+        Collections.shuffle(deck, rand);
29
+    }
30
+
31
+    public void deal(int numOfCards) {
32
+        Collections.shuffle(deck, rand);
33
+        for (int i = 0; i < numOfCards; i++) {
34
+            System.out.println(deck.remove(0));
35
+        }
36
+    }
37
+
38
+    public Card draw() {
39
+        if (deck.isEmpty()) {
40
+            new CardDeck();
41
+        }
42
+        return deck.remove(0);
43
+    }
25 44
 }

+ 22
- 0
src/main/java/io/zipcoder/casino/Casino.java View File

@@ -3,9 +3,31 @@ package io.zipcoder.casino;
3 3
 
4 4
 public class Casino {
5 5
 
6
+    private Player player;
7
+    private String choice;
8
+    //GameFactory gf;
9
+
10
+//    public void startCasino() {
11
+//        do {
12
+//            System.out.println("Welcome to the Zip Code Casino!");
13
+//            System.out.println("Which game would you like to play? :");
14
+//            System.out.println("1: BlackJack");
15
+//            System.out.println("2: Baccarat");
16
+//            System.out.println("3: Craps");
17
+//
18
+//            if () {
19
+//
20
+//            }
21
+//        }
22
+//    }
23
+
6 24
     public static void main(String[] args) {
7 25
 
8 26
         CardDeck cardDeck = new CardDeck();
9 27
         cardDeck.getDeck();
28
+        cardDeck.shuffle();
29
+        cardDeck.getDeck();
30
+        System.out.println(cardDeck.draw());
31
+        cardDeck.deal(2);
10 32
     }
11 33
 }