Akeem Cherry 6 年前
父节点
当前提交
2872e4cf00

+ 42
- 0
src/main/java/io/zipcoder/casino/BlackjackDealer.java 查看文件

@@ -0,0 +1,42 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.*;
4
+
5
+public class BlackjackDealer extends blackjackPlayer {
6
+    private blackjackPlayer player;
7
+    private Hand hand;
8
+    private Deck deck;
9
+
10
+    private BlackjackDealer(Hand hand, Deck deck) {
11
+        this.hand = hand;
12
+        this.deck = deck;
13
+    }
14
+
15
+
16
+//        public Card hit(){
17
+//            Card c = dealCards();
18
+//            hand.add(c);
19
+//            return c;
20
+//        }
21
+//
22
+//        public Card dealCards() {
23
+//            Card c = deck.remove();
24
+//            return c;
25
+//        }
26
+//
27
+//        public void newDeck(){
28
+//        if (deck.isEmpty()){
29
+//            deck = Deck.createDeck();
30
+//            }
31
+//        }
32
+
33
+
34
+        public Hand viewHand(){
35
+        return hand;
36
+        }
37
+
38
+        public void takeBet(Player player,double money){
39
+
40
+        }
41
+    }
42
+

+ 10
- 0
src/main/java/io/zipcoder/casino/BlackjackPlayer.java 查看文件

@@ -0,0 +1,10 @@
1
+package io.zipcoder.casino;
2
+
3
+public class BlackjackPlayer extends Player{
4
+
5
+
6
+    public BlackjackPlayer(String name, double moneyStartedWith) {
7
+
8
+        super(name, moneyStartedWith);
9
+    }
10
+}

+ 1
- 1
src/main/java/io/zipcoder/casino/Card.java 查看文件

@@ -1,4 +1,4 @@
1
-package io.zipcoder.casino;
1
+git package io.zipcoder.casino;
2 2
 
3 3
 public class Card {
4 4
     private Suit suit;

+ 0
- 0
src/main/java/io/zipcoder/casino/Casino.java 查看文件


+ 16
- 0
src/main/java/io/zipcoder/casino/Dealer.java 查看文件

@@ -0,0 +1,16 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Dealer extends Player {
4
+
5
+    public Dealer(String name, double moneyStartedWith) {
6
+        super(name, moneyStartedWith);
7
+    }
8
+
9
+    public void dealCards(Player player, Card card){
10
+
11
+    }
12
+
13
+    public void takeBet(Player player, double money){
14
+
15
+    }
16
+}

+ 0
- 0
src/main/java/io/zipcoder/casino/Deck.java 查看文件


+ 41
- 0
src/main/java/io/zipcoder/casino/Hand.java 查看文件

@@ -0,0 +1,41 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
6
+public class Hand {
7
+    private  List<Card> cards = new ArrayList<Card>();
8
+
9
+    public void clear(){
10
+        cards.clear();
11
+    }
12
+
13
+    public void add(Card c){
14
+        if(cards == null)
15
+            throw new NullPointerException ("no cards in hand, add new card");
16
+            cards.add(c);
17
+    }
18
+
19
+
20
+    public Integer getValue(){
21
+       Integer sum = 0;
22
+       for(Card card: cards){
23
+        sum+= card.getValue();
24
+       }
25
+        return sum;
26
+    }
27
+
28
+
29
+    public List<Card> getCards() {
30
+        return cards;
31
+    }
32
+
33
+    public void setCards(List<Card> cards) {
34
+
35
+        this.cards = cards;
36
+    }
37
+
38
+    public boolean contains(Card card){
39
+        return this.cards.contains(card);
40
+    }
41
+}

+ 55
- 0
src/main/java/io/zipcoder/casino/Player.java 查看文件

@@ -0,0 +1,55 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Player {
4
+
5
+    private String name;
6
+
7
+    private Hand hand;
8
+
9
+    private Wallet wallet;
10
+    private double wager;
11
+
12
+    public Player(String name, double moneyStartedWith) {
13
+
14
+        this.hand = new Hand();
15
+
16
+        this.name = name;
17
+
18
+        this.wallet = new Wallet(moneyStartedWith);
19
+    }
20
+
21
+    public void addCard(Card card) {
22
+
23
+        hand.add(card);
24
+    }
25
+
26
+    public Hand getHand() {
27
+
28
+        return hand;
29
+    }
30
+
31
+    public void setHand(Hand hand) {
32
+
33
+        this.hand = hand;
34
+    }
35
+
36
+    public String getName() {
37
+
38
+        return name;
39
+    }
40
+
41
+    public void setWager(double money) {
42
+        this.wager = money;
43
+        wallet.takeMoney(money);
44
+    }
45
+
46
+    public double getWalletAmount() {
47
+        return wallet.getCurrentAmount();
48
+    }
49
+
50
+    public double getWager() {
51
+
52
+        return wager;
53
+    }
54
+
55
+}

+ 0
- 0
src/main/java/io/zipcoder/casino/Rank.java 查看文件


+ 0
- 0
src/main/java/io/zipcoder/casino/Suit.java 查看文件


+ 0
- 0
src/main/java/io/zipcoder/casino/Wallet.java 查看文件


+ 0
- 28
src/main/java/io/zipcoder/casino/blackjackPlayer.java 查看文件

@@ -1,28 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class BlackjackPlayer {
4
-
5
-    private double wager;
6
-
7
-    private double money;
8
-
9
-
10
-    public void blackjackPlayer(double money) {
11
-
12
-    }
13
-
14
-    public double setBet(double money) {
15
-
16
-        this.wager = money;
17
-
18
-        return money;
19
-    }
20
-
21
-    public double getBet(double money) {
22
-
23
-        this.wager = money;
24
-
25
-        return money;
26
-
27
-    }
28
-}

+ 26
- 0
src/test/java/io/zipcoder/casino/BlackjackDealerTest.java 查看文件

@@ -0,0 +1,26 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class BlackjackDealerTest {
6
+
7
+    @Test
8
+    public void testDealCard(){
9
+        //Given
10
+
11
+        //When
12
+
13
+        //Then
14
+
15
+    }
16
+
17
+    @Test
18
+    public void testTakeBet(){
19
+        //given
20
+        Player play = new Player();
21
+
22
+        //When
23
+
24
+        //Then
25
+    }
26
+}

+ 45
- 0
src/test/java/io/zipcoder/casino/BlackjackPlayerTest.java 查看文件

@@ -0,0 +1,45 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.BlackjackPlayer;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class BlackjackPlayerTest {
9
+
10
+    BlackjackPlayer blackjackPlayer;
11
+
12
+
13
+    @Before
14
+    public void setup(){
15
+
16
+        blackjackPlayer  = new BlackjackPlayer("Xzavia", 200.00);
17
+
18
+    }
19
+
20
+    @Test
21
+    public void setWagerTest() {
22
+
23
+        //When
24
+        double actual = 100.00;
25
+
26
+        blackjackPlayer.setWager(100.00);
27
+
28
+        double expected = blackjackPlayer.getWager();
29
+
30
+        //Then
31
+        Assert.assertEquals(expected, actual, 0);
32
+    }
33
+
34
+    @Test
35
+    public void getNameTest() {
36
+
37
+        String expected = "Tommy";
38
+
39
+        String actual = blackjackPlayer.getName();
40
+
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+
45
+}

+ 0
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java 查看文件


+ 76
- 0
src/test/java/io/zipcoder/casino/HandTest.java 查看文件

@@ -0,0 +1,76 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.util.ArrayList;
7
+import java.util.List;
8
+
9
+public class HandTest {
10
+
11
+    @Test
12
+    public void testAdd(){
13
+
14
+        //Given
15
+        Card expected = new Card(Suit.Diamond, Rank.Ace);
16
+        Hand hand = new Hand();
17
+
18
+        //When
19
+        hand.add(expected);
20
+        //Then
21
+        Assert.assertTrue(hand.contains(expected));
22
+    }
23
+
24
+    @Test
25
+    public void testGetValue(){
26
+
27
+        //Given
28
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
29
+        Card card2 = new Card(Suit.Spade, Rank.King);
30
+        Hand hand = new Hand();
31
+        hand.add(card1);
32
+        hand.add(card2);
33
+        Integer expectedValue = 11;
34
+
35
+        //when
36
+        Integer actual = hand.getValue();
37
+        //then
38
+        Assert.assertEquals(expectedValue, actual);
39
+    }
40
+
41
+    @Test
42
+    public void testGetCards(){
43
+    //Given
44
+        Hand hand= new Hand();
45
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
46
+        Card card2 = new Card(Suit.Spade, Rank.King);
47
+        hand.add(card1);
48
+        hand.add(card2);
49
+
50
+        //When
51
+        List<Card> s = hand.getCards();
52
+
53
+        Assert.assertNotNull(s);
54
+        Assert.assertTrue(s.size() == 2);
55
+
56
+
57
+
58
+
59
+    }
60
+
61
+    @Test
62
+    public void testContains(){
63
+        //Given
64
+        Hand hand = new Hand();
65
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
66
+        hand.add(card1);
67
+
68
+        //When
69
+        Boolean b = hand.contains(card1);
70
+
71
+        //Then
72
+        Assert.assertTrue(b);
73
+    }
74
+
75
+
76
+}

+ 83
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java 查看文件

@@ -0,0 +1,83 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.*;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import java.util.List;
9
+
10
+public class PlayerTest {
11
+
12
+    Player xzavia;
13
+
14
+    @Before
15
+    public void setup(){
16
+
17
+        xzavia = new Player("Xzavia", 10_000.00);
18
+    }
19
+
20
+    @Test
21
+    public void addCardTest() {
22
+
23
+        //Given
24
+
25
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
26
+
27
+        //When
28
+        xzavia.addCard(expected);
29
+        Card actual = xzavia.getHand().getCards().get(0);
30
+
31
+        //Then
32
+        Assert.assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+
37
+    public void getHandTest() {
38
+
39
+        //Given
40
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
41
+        Hand hand = new Hand();
42
+
43
+        //When
44
+        hand.add(expected);
45
+        List<Card> cards = hand.getCards();
46
+
47
+        //Then
48
+        Assert.assertTrue(cards.contains(expected));
49
+
50
+    }
51
+
52
+    @Test
53
+
54
+    public void setHandTest() {
55
+
56
+        //Given
57
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
58
+
59
+        Hand hand = new Hand();
60
+
61
+        //When
62
+
63
+
64
+        //Then
65
+
66
+    }
67
+
68
+    @Test
69
+    public void getWalletAmountAfterWager(){
70
+
71
+        //When
72
+        xzavia.setWager(1000.00);
73
+
74
+        double expected = 9000.00;
75
+
76
+        double actual = xzavia.getWalletAmount();
77
+
78
+        //Then
79
+        Assert.assertEquals(expected,actual,0);
80
+
81
+
82
+    }
83
+}

+ 0
- 0
src/test/java/io/zipcoder/casino/TestCard.java 查看文件


+ 1
- 0
src/test/java/io/zipcoder/casino/TestDeck.java 查看文件

@@ -11,6 +11,7 @@ public class TestDeck {
11 11
     public void testDeckSize(){
12 12
         //Given
13 13
         Stack<Card> deckSize = new Stack<Card>();
14
+        Integer expectedSize = deckSize
14 15
         //When
15 16
 
16 17
         //Then

+ 0
- 0
src/test/java/io/zipcoder/casino/TestWallet.java 查看文件