Sfoglia il codice sorgente

fixed merge conflict

Vincent Sima 6 anni fa
parent
commit
07f1441a90

+ 47
- 0
src/main/java/io/zipcoder/casino/Card.java Vedi File

@@ -0,0 +1,47 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Card {
4
+
5
+    private Suit suit;
6
+    private Rank rank;
7
+    private int x;
8
+
9
+
10
+    public Card(Suit suit, Rank rank) {
11
+        this.suit = suit;
12
+        this.rank = rank;
13
+        x = 0;
14
+    }
15
+
16
+    public Rank getRank() {
17
+        return rank;
18
+    }
19
+
20
+    public Suit getSuit() {
21
+        return suit;
22
+    }
23
+
24
+    public void setRank(Rank rank) {
25
+        this.rank = rank;
26
+    }
27
+
28
+    public void setSuit(Suit suit) {
29
+        this.suit = suit;
30
+    }
31
+
32
+    @Override
33
+    public String toString() {
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;
46
+    }
47
+}

+ 44
- 0
src/main/java/io/zipcoder/casino/CardDeck.java Vedi File

@@ -0,0 +1,44 @@
1
+package io.zipcoder.casino;
2
+import java.util.Collections;
3
+import java.util.List;
4
+import java.util.ArrayList;
5
+import java.util.Random;
6
+
7
+public class CardDeck {
8
+
9
+    private Card card;
10
+    private List<Card> deck = new ArrayList<Card>(52);
11
+    private Random rand = new Random();
12
+
13
+    public CardDeck() {
14
+
15
+        for (Suit s : Suit.values()) {
16
+            for (Rank r : Rank.values()) {
17
+                deck.add(new Card(s, r));
18
+            }
19
+        }
20
+    }
21
+
22
+    public List<Card> getDeck() {
23
+        System.out.println(deck.toString());
24
+        return deck;
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
+    }
44
+}

+ 45
- 0
src/main/java/io/zipcoder/casino/CardGame.java Vedi File

@@ -0,0 +1,45 @@
1
+package io.zipcoder.casino;
2
+
3
+public abstract class CardGame implements Game, Gamble {
4
+
5
+//    int playerHand;
6
+//    int dealerHand;
7
+//    int currentBet;
8
+//    Player player;
9
+//    CardDeck deck;
10
+//
11
+//    public CardGame(Player player) {
12
+//
13
+//        this.player = player;
14
+//        this.deck = new deck();
15
+//
16
+//    }
17
+//
18
+//
19
+//    public int drawCard() {
20
+//
21
+//
22
+//    }
23
+//
24
+//    public void stand() {
25
+//
26
+//    }
27
+//
28
+//    void startGame();
29
+//
30
+//    void endGame();
31
+//
32
+//    void declareWinner();
33
+//
34
+//    void bet(int currentBet) {
35
+//
36
+//    }
37
+//    void winBet() {
38
+//
39
+//    }
40
+//    void loseBet(Player player) {
41
+
42
+    }
43
+
44
+
45
+

+ 34
- 0
src/main/java/io/zipcoder/casino/Casino.java Vedi File

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

+ 1
- 7
src/main/java/io/zipcoder/casino/Gamble.java Vedi File

@@ -1,15 +1,9 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public interface Gamble {
4
-
5
-
6
-
7 4
      int currentBet = 0;
8 5
      void bet(int bet);
9 6
      void winBet(int currentBet);
10 7
      void loseBet(int currentBet);
11
-
12
-
13
-
14
-
8
+     
15 9
 }

+ 1
- 1
src/main/java/io/zipcoder/casino/Game.java Vedi File

@@ -2,7 +2,7 @@ package io.zipcoder.casino;
2 2
 
3 3
 public interface Game {
4 4
    // variable of Player type
5
-    Player player;
5
+   // Player player;
6 6
 
7 7
     void startGame();
8 8
 

+ 4
- 4
src/main/java/io/zipcoder/casino/Main.java Vedi File

@@ -1,11 +1,11 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public class Main {
4
-    public static void main(String[] args){
5
-        Casino casino =  new Casino();
6
-        casino.start();
4
+//    public static void main(String[] args){
5
+//        Casino casino =  new Casino();
6
+//        casino.start();
7 7
 
8
-    }
8
+//    }
9 9
 
10 10
 
11 11
 }

+ 43
- 0
src/main/java/io/zipcoder/casino/Player.java Vedi File

@@ -0,0 +1,43 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Player {
4
+
5
+    private String name;
6
+    private int bankroll;
7
+    private int score;
8
+
9
+    public Player(String name) {
10
+        this.name = name;
11
+        bankroll = 1000;
12
+    }
13
+
14
+    public void setName(String name) {
15
+        this.name = name;
16
+    }
17
+
18
+    public String getName() {
19
+        return name;
20
+    }
21
+
22
+    public int getBankroll() {
23
+        return bankroll;
24
+    }
25
+
26
+    public void addToBankroll(int winnings) {
27
+        bankroll += winnings;
28
+    }
29
+
30
+    public void subtractFromBankroll(int losings) {
31
+        bankroll -= losings;
32
+    }
33
+
34
+    public void setScore(int value) {
35
+        score += value;
36
+    }
37
+
38
+    public int getScore() {
39
+        return score;
40
+    }
41
+
42
+
43
+}

+ 7
- 0
src/main/java/io/zipcoder/casino/Rank.java Vedi File

@@ -0,0 +1,7 @@
1
+package io.zipcoder.casino;
2
+
3
+public enum Rank {
4
+
5
+    TWO, THREE, FOUR, FIVE, SIX, SEVEN,
6
+    EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE;
7
+}

+ 6
- 0
src/main/java/io/zipcoder/casino/Suit.java Vedi File

@@ -0,0 +1,6 @@
1
+package io.zipcoder.casino;
2
+
3
+public enum Suit {
4
+
5
+    SPADES, HEARTS, DIAMONDS, CLUBS;
6
+}