ソースを参照

Merge branch 'master' of demetrm/Casino into master

JenniferChao4 6 年 前
コミット
87902aed5f

+ 45
- 3
src/main/java/io/zipcoder/casino/CardGame/Card.java ファイルの表示

@@ -2,15 +2,57 @@ package io.zipcoder.casino.CardGame;
2 2
 
3 3
 public class Card {
4 4
 
5
-    private String suit;
6
-    private String color;
7
-    private String face;
5
+    private Suit suit;
6
+    private boolean isBlack;
7
+    private Face face;
8 8
     private boolean covered;
9 9
 
10
+    public Card(Suit suit, Face face){
11
+        this.suit = suit;
12
+        this.face = face;
13
+    }
14
+
15
+    public Suit getSuit() {
16
+        return suit;
17
+    }
18
+
19
+    public void setSuit(Suit suit) {
20
+        this.suit = suit;
21
+    }
22
+
23
+    public boolean isBlack() {
24
+        return isBlack;
25
+    }
26
+
27
+    public void setBlack(boolean black) {
28
+        isBlack = black;
29
+    }
30
+
31
+    public Face getFace() {
32
+        return face;
33
+    }
34
+
35
+    public void setFace(Face face) {
36
+        this.face = face;
37
+    }
38
+
39
+    public boolean isCovered() {
40
+        return covered;
41
+    }
42
+
43
+    public void setCovered(boolean covered) {
44
+        this.covered = covered;
45
+    }
46
+
10 47
     public Card drawCard() {
11 48
         return null;
12 49
     }
13 50
 
14 51
     public void shuffleDeck() {
15 52
     }
53
+
54
+    @Override
55
+    public String toString(){
56
+        return suit + "-" + face;
57
+    }
16 58
 }

+ 27
- 4
src/main/java/io/zipcoder/casino/CardGame/Deck.java ファイルの表示

@@ -1,10 +1,33 @@
1 1
 package io.zipcoder.casino.CardGame;
2 2
 
3
+import java.util.Collections;
4
+import java.util.Stack;
5
+
3 6
 public class Deck {
4 7
 
5
-        private Card[] deckOfCards = new Card[52];
6
-        // needs 1-13 of each suit
7
-        // assign each index to a specific card,
8
-        // e.g. 0-12 = spades; 13-25 = clubs; 26-38 = hearts; 39-51 = diamonds
8
+    public Stack<Card> deckOfCards = new Stack<Card>();
9
+
10
+    public void shuffle(){
11
+        Collections.shuffle(deckOfCards);
12
+    }
13
+
14
+    public Card draw(){
15
+       return deckOfCards.pop();
16
+    }
17
+
18
+    public Card flip(){
19
+        return deckOfCards.peek();
20
+    }
21
+
22
+    // needs 1-13 of each suit
23
+    // assign each index to a specific card,
24
+    // e.g. 0-12 = spades; 13-25 = clubs; 26-38 = hearts; 39-51 = diamonds
9 25
 
26
+    public Deck() {
27
+        for (Suit suit : Suit.values()) {
28
+            for (Face face : Face.values()) {
29
+                deckOfCards.push(new Card(suit, face));
30
+            }
31
+        }
32
+    }
10 33
 }

+ 24
- 0
src/main/java/io/zipcoder/casino/CardGame/Face.java ファイルの表示

@@ -0,0 +1,24 @@
1
+package io.zipcoder.casino.CardGame;
2
+
3
+public enum Face {
4
+
5
+    ACE(1),
6
+    TWO(2),
7
+    THREE(3),
8
+    FOUR(4),
9
+    FIVE(5),
10
+    SIX(6),
11
+    SEVEN(7),
12
+    EIGHT(8),
13
+    NINE(9),
14
+    TEN(10),
15
+    JACK(11),
16
+    QUEEN(12),
17
+    KING(13);
18
+
19
+    private int value;
20
+
21
+    private Face(int value) {
22
+        this.value = value;
23
+    }
24
+}

+ 29
- 29
src/main/java/io/zipcoder/casino/CardGame/Solitaire/Solitaire.java ファイルの表示

@@ -3,32 +3,32 @@ package io.zipcoder.casino.CardGame.Solitaire;
3 3
 import io.zipcoder.casino.CardGame.Card;
4 4
 import io.zipcoder.casino.CardGame.CardGame;
5 5
 import io.zipcoder.casino.Player;
6
-
7
-public class Solitaire extends CardGame {
8
-
9
-    private Player player;
10
-    private Tableau tableau;
11
-    private Foundation foundation;
12
-    private java.util.Stack wastepile;
13
-
14
-
15
-    public Solitaire(Player player) {
16
-        this.player = player;
17
-    }
18
-
19
-    public void moveable() {
20
-    }
21
-
22
-    public void receivable() {
23
-    }
24
-
25
-    public Card draw() {
26
-        return null;
27
-    }
28
-
29
-    public void flip() {
30
-        // shoulder technically be card.setCovered(false); or something like that
31
-        boolean covered = false;
32
-    }
33
-
34
-}
6
+//
7
+//public class Solitaire extends CardGame {
8
+//
9
+//    private Player player;
10
+//    private Tableau tableau;
11
+//    private Foundation foundation;
12
+//    private java.util.Stack wastepile;
13
+//
14
+//
15
+//    public Solitaire(Player player) {
16
+//        this.player = player;
17
+//    }
18
+//
19
+//    public void moveable() {
20
+//    }
21
+//
22
+//    public void receivable() {
23
+//    }
24
+//
25
+//    public Card draw() {
26
+//        return null;
27
+//    }
28
+//
29
+//    public void flip() {
30
+//        // shoulder technically be card.setCovered(false); or something like that
31
+//        boolean covered = false;
32
+//    }
33
+//
34
+//}

+ 11
- 0
src/main/java/io/zipcoder/casino/CardGame/Suit.java ファイルの表示

@@ -0,0 +1,11 @@
1
+package io.zipcoder.casino.CardGame;
2
+
3
+public enum Suit {
4
+    HEARTS,
5
+    SPADES,
6
+    DIAMONDS,
7
+    CLUBS;
8
+
9
+    private Suit() {
10
+    }
11
+}

+ 39
- 39
src/main/java/io/zipcoder/casino/Casino.java ファイルの表示

@@ -7,42 +7,42 @@ package io.zipcoder.casino;
7 7
 // Slot Machine?
8 8
 
9 9
 // Jackpot option? Low chance but player wins $1mil
10
-
11
-import io.zipcoder.casino.CardGame.BlackJack.BlackJack;
12
-import io.zipcoder.casino.DiceGame.Craps.Craps;
13
-import io.zipcoder.casino.CardGame.Solitaire.Solitaire;
14
-import io.zipcoder.casino.Interfaces.Game;
15
-
16
-public class Casino {
17
-
18
-    private int money;
19
-    private String casinoName;
20
-    private Game game;
21
-    private Player player;
22
-    private String currentGame;
23
-
24
-    public void selectGame(int gameNum) {
25
-
26
-        switch (gameNum) {
27
-            case 1:
28
-                Game blackJack = new BlackJack(player);
29
-                break;
30
-            case 2:
31
-                Game solitaire = new Solitaire(player);
32
-                break;
33
-            case 3:
34
-                Game craps = new Craps(player);
35
-                break;
36
-            case 4:
37
-                leaveCasino();
38
-                break;
39
-            default:
40
-                System.out.println("Input unknown, please pick again.");
41
-                break;
42
-        }
43
-    }
44
-
45
-    public void leaveCasino() {
46
-    }
47
-
48
-}
10
+//
11
+//import io.zipcoder.casino.CardGame.BlackJack.BlackJack;
12
+//import io.zipcoder.casino.DiceGame.Craps.Craps;
13
+//import io.zipcoder.casino.CardGame.Solitaire.Solitaire;
14
+//import io.zipcoder.casino.Interfaces.Game;
15
+//
16
+//public class Casino {
17
+//
18
+//    private int money;
19
+//    private String casinoName;
20
+//    private Game game;
21
+//    private Player player;
22
+//    private String currentGame;
23
+//
24
+//    public void selectGame(int gameNum) {
25
+//
26
+//        switch (gameNum) {
27
+//            case 1:
28
+//                Game blackJack = new BlackJack(player);
29
+//                break;
30
+//            case 2:
31
+//                Game solitaire = new Solitaire(player);
32
+//                break;
33
+//            case 3:
34
+//                Game craps = new Craps(player);
35
+//                break;
36
+//            case 4:
37
+//                leaveCasino();
38
+//                break;
39
+//            default:
40
+//                System.out.println("Input unknown, please pick again.");
41
+//                break;
42
+//        }
43
+//    }
44
+//
45
+//    public void leaveCasino() {
46
+//    }
47
+//
48
+//}

+ 47
- 0
src/test/java/io/zipcoder/casino/CardGame/DeckTest.java ファイルの表示

@@ -0,0 +1,47 @@
1
+package io.zipcoder.casino.CardGame;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class DeckTest {
9
+
10
+    Deck deck = new Deck();
11
+
12
+    @Test
13
+    public void testDeck() {
14
+        String actual = deck.deckOfCards.get(0).toString();
15
+        String expected = "HEARTS-ACE";
16
+
17
+        Assert.assertEquals(expected, actual);
18
+    }
19
+
20
+    @Test
21
+    public void testShuffle() {
22
+        deck.shuffle();
23
+        String actual = deck.deckOfCards.get(0).toString();
24
+        String expected = "HEARTS-ACE";
25
+
26
+        Assert.assertNotEquals(expected, actual);
27
+
28
+        String actual1 = deck.deckOfCards.get(1).toString();
29
+        String expected1 = "HEARTS-TWO";
30
+
31
+        Assert.assertNotEquals(expected1, actual1);
32
+    }
33
+
34
+    @Test
35
+    public void testDeck3() {
36
+        Deck deck2 = new Deck();
37
+        for (Card c : deck2.deckOfCards) {
38
+            System.out.println(c.toString());
39
+        }
40
+
41
+        deck2.shuffle();
42
+        System.out.println("*******");
43
+        for (Card c : deck2.deckOfCards) {
44
+            System.out.println(c.toString());
45
+        }
46
+    }
47
+}