Parcourir la source

Merge branch 'master' of https://git.zipcode.rocks/jonathan-hinds/ZCW-OOP-Casino

Lauren Green il y a 6 ans
Parent
révision
65214b596b

BIN
.DS_Store Voir le fichier


BIN
src/.DS_Store Voir le fichier


BIN
src/main/.DS_Store Voir le fichier


BIN
src/main/java/.DS_Store Voir le fichier


BIN
src/main/java/io/.DS_Store Voir le fichier


BIN
src/main/java/io/zipcoder/.DS_Store Voir le fichier


+ 93
- 2
src/main/java/io/zipcoder/casino/Card.java Voir le fichier

@@ -1,13 +1,104 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public class Card {
4
-    private String suit;
4
+    private Suit suit;
5
+    private CardValue cardValue;
5 6
     private boolean isVisible;
6
-    private int value;
7 7
     private String name;
8 8
 
9
+    public Card (CardValue cardValue, Suit suit)
10
+    {
11
+        this.cardValue = cardValue;
12
+        this.suit = suit;
13
+        this.isVisible = false;
14
+        this.name = cardValue + " of " + suit;
15
+    }
16
+
17
+    public String getName() {
18
+        return name;
19
+    }
20
+
21
+    public void setName(String name) {
22
+        this.name = name;
23
+    }
24
+
25
+    public boolean isVisible() {
26
+        return isVisible;
27
+    }
28
+
29
+    public void setVisible(boolean visible) {
30
+        isVisible = visible;
31
+    }
32
+
9 33
     public void setVisibility(boolean visibility){
10 34
         isVisible = visibility;
11 35
     }
12 36
 
37
+    public Suit getSuit()
38
+    {
39
+        return suit;
40
+    }
41
+
42
+    public void setSuit(Suit suit)
43
+    {
44
+        this.suit = suit;
45
+    }
46
+
47
+    public CardValue getCardValue()
48
+    {
49
+        return cardValue;
50
+    }
51
+
52
+    public void setCardValue(CardValue cardValue)
53
+    {
54
+        this.cardValue = cardValue;
55
+    }
56
+
57
+    public enum CardValue
58
+    {
59
+        TWO(2),
60
+        THREE(3),
61
+        FOUR(4),
62
+        FIVE(5),
63
+        SIX(6),
64
+        SEVEN(7),
65
+        EIGHT(8),
66
+        NINE(9),
67
+        TEN(10),
68
+        JACK(11),
69
+        QUEEN(12),
70
+        KING(13),
71
+        ACE(14);
72
+
73
+        private int cardValue;
74
+
75
+        CardValue (int cardValue)
76
+        {
77
+            this.cardValue = cardValue;
78
+        }
79
+
80
+        public int getCardValue() {
81
+            return cardValue;
82
+        }
83
+    }
84
+
85
+    public enum Suit
86
+    {
87
+        HEARTS("HEARTS"),
88
+        SPADES("SPADES"),
89
+        CLUBS("CLUBS"),
90
+        DIAMONDS("DIAMONDS");
91
+
92
+        private String suitValue;
93
+
94
+        Suit (String suitValue)
95
+        {
96
+            this.suitValue = suitValue;
97
+        }
98
+
99
+        public String getSuitValue(){
100
+            return suitValue;
101
+        }
102
+
103
+    }
13 104
 }

+ 25
- 2
src/main/java/io/zipcoder/casino/CardGame.java Voir le fichier

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import java.lang.reflect.Array;
4
+import java.util.ArrayList;
3 5
 import java.util.HashMap;
4 6
 
5 7
 public abstract class CardGame {
@@ -7,13 +9,16 @@ public abstract class CardGame {
7 9
     private int minBet;
8 10
     private int maxBet;
9 11
     private int handSize;
12
+    private int ante;
10 13
     private Player playersTurn;
11
-    private Player[] players;
14
+    private ArrayList<CardPlayer> players;
15
+    private ArrayList<Card> deck = new ArrayList<>();
12 16
 
13 17
 
14
-    CardGame(int minBet, int maxBet){
18
+    CardGame(int minBet, int maxBet, int ante){
15 19
         this.minBet = minBet;
16 20
         this.maxBet = maxBet;
21
+        this.ante = ante;
17 22
     }
18 23
 
19 24
     //use hand size to determine dealing
@@ -21,6 +26,8 @@ public abstract class CardGame {
21 26
 
22 27
     public void Shuffle(){
23 28
 
29
+        //shuffle the card stack
30
+
24 31
     }
25 32
 
26 33
     public void faceDown(Card card){
@@ -30,4 +37,20 @@ public abstract class CardGame {
30 37
     public void faceUp(Card card){
31 38
         card.setVisibility(true);
32 39
     }
40
+
41
+    public ArrayList<Card> getDeck() {
42
+        return deck;
43
+    }
44
+
45
+    public ArrayList<CardPlayer> getPlayers() {
46
+        return players;
47
+    }
48
+
49
+    public void setDeck(ArrayList<Card> deck) {
50
+        this.deck = deck;
51
+    }
52
+
53
+    public int getAnte(){
54
+        return ante;
55
+    }
33 56
 }

+ 8
- 0
src/main/java/io/zipcoder/casino/CardPlayer.java Voir le fichier

@@ -6,4 +6,12 @@ public class CardPlayer {
6 6
     private Player player;
7 7
     private ArrayList<Card> hand = new ArrayList<>();
8 8
     private ArrayList<Card> discard = new ArrayList<>();
9
+
10
+    public ArrayList<Card> getHand(){
11
+        return hand;
12
+    }
13
+
14
+    public Player getPlayer() {
15
+        return player;
16
+    }
9 17
 }

+ 10
- 3
src/main/java/io/zipcoder/casino/Console.java Voir le fichier

@@ -2,14 +2,21 @@ package io.zipcoder.casino;
2 2
 
3 3
 public class Console {
4 4
     private Game[] games;
5
+    private Player player;
5 6
 
6 7
     Console(){}
7 8
 
8
-    public void createAccount(){
9
-
9
+    public void createAccount()
10
+    {
11
+        /*
12
+            ask the player for their name.
13
+            ask the player for their starting balance
14
+            create the player.
15
+         */
10 16
     }
11 17
 
12
-    public void chooseGame(String gameName){
18
+    public void chooseGame(String gameName)
19
+    {
13 20
         /*
14 21
             ask the user for min max bet at the table
15 22
             ask the user which game they would like to play

+ 51
- 1
src/main/java/io/zipcoder/casino/Deck.java Voir le fichier

@@ -4,5 +4,55 @@ import java.util.ArrayList;
4 4
 import java.util.Collections;
5 5
 
6 6
 public class Deck {
7
-    ArrayList<Card> cards = new ArrayList<Card>();
7
+    ArrayList<Card> deck;
8
+
9
+    /**
10
+     * Deck constructor will create an array of all 52 @Card 's
11
+     * Then, they are shuffled
12
+     */
13
+    public Deck(){
14
+        createDeck();
15
+    }
16
+
17
+    public void createDeck(){
18
+        this.deck = new ArrayList<>();
19
+
20
+        for (int i = 0; i < 13; i++){
21
+            Card.CardValue value = Card.CardValue.values()[i];
22
+
23
+            for (int j = 0; j < 4; j++){
24
+                Card card = new Card(value, Card.Suit.values()[j]);
25
+                this.deck.add(card);
26
+            }
27
+        }
28
+        Collections.shuffle(deck);
29
+    }
30
+
31
+    /**
32
+     * Will retrieve a card at requested index, but will NOT REMOVE
33
+     * Likely just for testing
34
+     * @param index
35
+     * @return
36
+     */
37
+    public Card getCard(int index){
38
+        return this.deck.get(index);
39
+    }
40
+
41
+    /**
42
+     * Will retrieve AND REMOVE card from ZERO INDEX
43
+     * @return
44
+     */
45
+    public Card pullCard(){
46
+        Card tempCard = this.deck.remove(0);
47
+        return tempCard;
48
+    }
49
+
50
+    /**
51
+     * Used to retrieve the array with instantiated deck shuffled
52
+     * Will RETURN DECK
53
+     * @return
54
+     */
55
+    public ArrayList<Card> getDeck() {
56
+        return this.deck;
57
+    }
8 58
 }

+ 8
- 2
src/main/java/io/zipcoder/casino/Dice.java Voir le fichier

@@ -1,11 +1,17 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public class Dice {
4
-    private int sides;
4
+
5
+
5 6
     private int value;
6 7
 
7
-    public void Roll(){
8
+    public void roll(){
9
+        value = (int) (Math.random()*6+1);
10
+    }
8 11
 
12
+    public int getValue()
13
+    {
14
+        return value;
9 15
     }
10 16
 
11 17
     public int getValue() {

+ 4
- 0
src/main/java/io/zipcoder/casino/DicePlayer.java Voir le fichier

@@ -6,4 +6,8 @@ public class DicePlayer {
6 6
     private Player player;
7 7
     Dice[] cup = new Dice[5];
8 8
     ScoreSheet scoreSheet = new ScoreSheet();
9
+
10
+    public DicePlayer(Player player){
11
+        this.player = player;
12
+    }
9 13
 }

+ 0
- 1
src/main/java/io/zipcoder/casino/Gamble.java Voir le fichier

@@ -3,5 +3,4 @@ package io.zipcoder.casino;
3 3
 public interface Gamble {
4 4
      void Bet(int betAmount);
5 5
      int Payout(int payoutAmount);
6
-     void Ante(int anteAmount);
7 6
 }

+ 43
- 12
src/main/java/io/zipcoder/casino/War.java Voir le fichier

@@ -7,26 +7,25 @@ public class War extends CardGame implements Gamble, Game {
7 7
 
8 8
     private ArrayList<Card> tableCards = new ArrayList<Card>();
9 9
 
10
-    War(int minBet, int maxBet) {
11
-        super(minBet, maxBet);
10
+    War(int minBet, int maxBet, int ante) {
11
+        super(minBet, maxBet, ante);
12 12
     }
13 13
 
14
-    public void Deal() {
15
-
16
-    }
17 14
 
18 15
     /**
19 16
      * Specific to war methods
20 17
      */
21 18
     public void playCard(){
22
-
19
+        //take a card from the hand
20
+        //add it to the tablecard face up
23 21
     }
24 22
 
25 23
     public void warMethod(){
26
-
24
+        //take three cards from your hand face down
25
+        //play one card face up
27 26
     }
28 27
 
29
-    public void determineWinner(){
28
+    public void determineWinner(Card player1card, Card player2card){
30 29
 
31 30
     }
32 31
 
@@ -34,15 +33,20 @@ public class War extends CardGame implements Gamble, Game {
34 33
      * Below 3 Implemented from Gamble
35 34
      */
36 35
     public void Bet(int betAmount) {
37
-
36
+        //add money to the pot
38 37
     }
39 38
 
40 39
     public int Payout(int payoutAmount) {
40
+
41 41
         return 0;
42 42
     }
43 43
 
44
-    public void Ante(int anteAmount) {
45
-
44
+    public void payAnte() {
45
+        for(int i = 0; i < super.getPlayers().size(); i ++)
46
+        {
47
+            CardPlayer player = super.getPlayers().get(i);
48
+            player.getPlayer().changeBalance(-super.getAnte());
49
+        }
46 50
     }
47 51
 
48 52
     /**
@@ -54,10 +58,37 @@ public class War extends CardGame implements Gamble, Game {
54 58
     }
55 59
 
56 60
     public void StartGame() {
57
-
61
+        Deck deck = new Deck();
62
+        payAnte();
63
+        Deal();
58 64
     }
59 65
 
60 66
     public void StartRound() {
67
+        //player plays a card faceup
68
+        //remove cards from player hand
69
+        //pc plays a card faceup
70
+        //remove cards from npc hand
71
+        //determinewinner
72
+        //add all table cards to winners discard facedown
73
+
74
+        //when player is out of cards
75
+        //shuffle players discard
76
+        //insert discard into hand facedown
77
+    }
61 78
 
79
+    public void Deal() {
80
+        //while there are cards in the deck
81
+        while(super.getDeck().size() != 0){
82
+            //for each player playing the game
83
+            for(int i = 0; i < super.getPlayers().size(); i ++)
84
+            {
85
+                //grab the card from the top (last added) to the deck
86
+                Card card = super.getDeck().get(super.getDeck().size() - 1);
87
+                //get the player whos hand we are adding the card to
88
+                CardPlayer player = super.getPlayers().get(i);
89
+                //add the card to their hand
90
+                player.getHand().add(card);
91
+            }
92
+        }
62 93
     }
63 94
 }

+ 20
- 0
src/test/java/io/zipcoder/casino/CardTest.java Voir le fichier

@@ -0,0 +1,20 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class CardTest {
6
+
7
+    @Test
8
+    public void createCard(){
9
+        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
10
+        System.out.println(card.getName());
11
+    }
12
+
13
+    @Test
14
+    public void createCard2(){
15
+        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
16
+        Card card1 = new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS);
17
+        System.out.println(card.getName());
18
+        System.out.println(card1.getName());
19
+    }
20
+}

+ 31
- 0
src/test/java/io/zipcoder/casino/DeckTest.java Voir le fichier

@@ -0,0 +1,31 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DeckTest {
7
+
8
+    @Test
9
+    public void testDeck(){
10
+        //GIVEN
11
+        Deck deck = new Deck();
12
+        //WHEN
13
+        for (int i = 0; i < 52; i++){
14
+            System.out.println(deck.getCard(i).getName());
15
+        }
16
+
17
+        //THEN
18
+    }
19
+
20
+    @Test
21
+    public void pullCard(){
22
+        //GIVEN
23
+        Deck deck = new Deck();
24
+        //WHEN
25
+        String expected = deck.getCard(0).getName();
26
+        //THEN
27
+        Card testCard = deck.pullCard();
28
+        String actual = testCard.getName();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+}

+ 27
- 0
src/test/java/io/zipcoder/casino/DiceTest.java Voir le fichier

@@ -0,0 +1,27 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DiceTest {
7
+
8
+    @Test
9
+    public void getValueTest()
10
+    {
11
+        Dice dice = new Dice();
12
+        dice.roll();
13
+        int actual = dice.getValue();
14
+        boolean expected = true;
15
+        boolean x;
16
+        if (actual<=6 || actual>=1)
17
+        {
18
+            x = true;
19
+        }
20
+        else
21
+            {
22
+                x =false;
23
+            }
24
+
25
+        Assert.assertEquals(expected,x);
26
+    }
27
+}