Simran Bhutani vor 6 Jahren
Ursprung
Commit
bb0be794ba

+ 2
- 25
src/main/java/io/zipcoder/casino/Card.java Datei anzeigen

14
         this.name = cardValue + " of " + suit;
14
         this.name = cardValue + " of " + suit;
15
     }
15
     }
16
 
16
 
17
+
17
     public String getName() {
18
     public String getName() {
18
         return name;
19
         return name;
19
     }
20
     }
20
 
21
 
21
-    public void setName(String name) {
22
-        this.name = name;
23
-    }
24
-
25
     public boolean isVisible() {
22
     public boolean isVisible() {
26
         return isVisible;
23
         return isVisible;
27
     }
24
     }
28
 
25
 
29
-    public void setVisible(boolean visible) {
30
-        isVisible = visible;
31
-    }
32
-
33
     public void setVisibility(boolean visibility){
26
     public void setVisibility(boolean visibility){
34
         isVisible = visibility;
27
         isVisible = visibility;
35
     }
28
     }
39
         return suit;
32
         return suit;
40
     }
33
     }
41
 
34
 
42
-    public void setSuit(Suit suit)
43
-    {
44
-        this.suit = suit;
45
-    }
46
-
47
     public int getCardValue()
35
     public int getCardValue()
48
     {
36
     {
49
         return cardValue.getCardValue();
37
         return cardValue.getCardValue();
50
     }
38
     }
51
 
39
 
52
-    public void setCardValue(CardValue cardValue)
53
-    {
54
-        this.cardValue = cardValue;
55
-    }
56
-
57
     public enum CardValue
40
     public enum CardValue
58
     {
41
     {
59
         TWO(2),
42
         TWO(2),
94
         Suit (String suitValue)
77
         Suit (String suitValue)
95
         {
78
         {
96
             this.suitValue = suitValue;
79
             this.suitValue = suitValue;
97
-        }
98
-
99
-        public String getSuitValue(){
100
-            return suitValue;
101
-        }
102
-
103
-    }
80
+        }}
104
 }
81
 }

+ 1
- 14
src/main/java/io/zipcoder/casino/CardGame.java Datei anzeigen

8
 public abstract class CardGame {
8
 public abstract class CardGame {
9
 
9
 
10
     private int tablePot;
10
     private int tablePot;
11
-    private int minBet;
12
-    private int maxBet;
13
     private int handSize;
11
     private int handSize;
14
     private int ante;
12
     private int ante;
15
     private CardPlayer playersTurn;
13
     private CardPlayer playersTurn;
23
         this.ante = ante;
21
         this.ante = ante;
24
     }
22
     }
25
 
23
 
26
-    //use hand size to determine dealing
27
-    // public abstract void deal();
28
-    // public abstract void deal(ArrayList<CardPlayer> players); // NEEDED FOR STUD
29
-
30
-    public void shuffle(){
31
-
32
-        //shuffle the card stack
33
-
34
-    }
35
-
36
     public Deck getDeck() {
24
     public Deck getDeck() {
37
         return deck;
25
         return deck;
38
     }
26
     }
48
         }
36
         }
49
     }
37
     }
50
 
38
 
51
-
52
     public int getAnte(){
39
     public int getAnte(){
53
         return ante;
40
         return ante;
54
     }
41
     }
85
         addPlayers(new NPC("Opponant", getAnte()));
72
         addPlayers(new NPC("Opponant", getAnte()));
86
     }
73
     }
87
 
74
 
88
-    public void chooseStatingPlayer(){
75
+    public void chooseStartingPlayer(){
89
         //loop through the players
76
         //loop through the players
90
         for(int i = 0; i < getPlayers().size(); i ++){
77
         for(int i = 0; i < getPlayers().size(); i ++){
91
             //if one is not an NPC
78
             //if one is not an NPC

+ 1
- 1
src/main/java/io/zipcoder/casino/Casino.java Datei anzeigen

71
                         Printer.printMessage("Invalid bet amount entered, min bet for slot is $1 and max $100 ");
71
                         Printer.printMessage("Invalid bet amount entered, min bet for slot is $1 and max $100 ");
72
                         break;
72
                         break;
73
                     }
73
                     }
74
-                    Game slot= new SlotMachine(slotBet1);
74
+                    Game slot= new SlotMachine(slotBet1, player);
75
                     game = slot;
75
                     game = slot;
76
                     slot.startGame();
76
                     slot.startGame();
77
                     ((SlotMachine) slot).slotResult();
77
                     ((SlotMachine) slot).slotResult();

+ 39
- 15
src/main/java/io/zipcoder/casino/SlotMachine.java Datei anzeigen

12
     String word2="";
12
     String word2="";
13
     String word3="";
13
     String word3="";
14
     double totalBet=0;
14
     double totalBet=0;
15
+    Player player;
16
+
17
+    public SlotMachine(int betAmount, Player player) {
15
 
18
 
16
-    public SlotMachine(int betAmount) {
17
         this.betAmount = betAmount;
19
         this.betAmount = betAmount;
20
+        this.player = player;
18
     }
21
     }
19
 
22
 
20
     @Override
23
     @Override
21
     public void bet(int betAmount) {
24
     public void bet(int betAmount) {
22
 
25
 
23
         this.betAmount= betAmount;
26
         this.betAmount= betAmount;
27
+        player.changeBalance(-betAmount);
28
+
24
     }
29
     }
25
 
30
 
26
     public void payout(){
31
     public void payout(){
32
+        getPlayer().changeBalance(payoutAmt);
27
         Printer.printMessage("Your payout amount for slot machine is: $" + payoutAmt + "\n");
33
         Printer.printMessage("Your payout amount for slot machine is: $" + payoutAmt + "\n");
34
+
28
     }
35
     }
29
 
36
 
30
     @Override
37
     @Override
37
         }
44
         }
38
         Printer.printMessage("Your slot is in progress" + "\n");
45
         Printer.printMessage("Your slot is in progress" + "\n");
39
 
46
 
40
-        try {
41
-            Thread.sleep(3000);
42
-        } catch (InterruptedException e) {
43
-            e.printStackTrace();
44
-        }
45
-
46
-
47
-        outputword = "";
47
+        startRound();
48
+    }
48
 
49
 
50
+    public void generateWords() {
49
         Random rand = new Random();
51
         Random rand = new Random();
50
 
52
 
51
         generateWords(rand);
53
         generateWords(rand);
85
                 word3 = word;
87
                 word3 = word;
86
             }
88
             }
87
         }
89
         }
90
+
91
+        outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
92
+
88
     }
93
     }
89
 
94
 
90
     public void slotResult()
95
     public void slotResult()
91
     {
96
     {
92
-            outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
93
-
94
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
97
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
95
 
98
 
96
                 outputword= outputword + "\n"+" You have won $0";
99
                 outputword= outputword + "\n"+" You have won $0";
97
-                payoutAmt=0;
100
+                setPayoutAmt(0);
98
             }
101
             }
99
             else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
102
             else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
100
 
103
 
101
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
104
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
102
-                payoutAmt=betAmount*2;
105
+                setPayoutAmt(betAmount*2);
103
             }
106
             }
104
 
107
 
105
 
108
 
106
-            else if(word1.equals(word2) && word1.equals(word3)  /*&& ((word2.equals(word1)) && (word2.equals(word3))) && ( (word3.equals(word1)) && (word3.equals(word2)))*/){
109
+            else if(word1.equals(word2) && word1.equals(word3)) {
107
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
110
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
108
-                payoutAmt=betAmount*3;
111
+                setPayoutAmt(betAmount*3);
109
             }
112
             }
110
 
113
 
111
             Printer.printMessage(( outputword + "\n" ));
114
             Printer.printMessage(( outputword + "\n" ));
119
 
122
 
120
     @Override
123
     @Override
121
     public void startRound() {
124
     public void startRound() {
125
+        try {
126
+            Thread.sleep(3000);
127
+        } catch (InterruptedException e) {
128
+            e.printStackTrace();
129
+        }
122
 
130
 
131
+        generateWords();
123
     }
132
     }
133
+
124
     public int getPayoutAmt() {
134
     public int getPayoutAmt() {
125
 
135
 
126
         return payoutAmt;
136
         return payoutAmt;
127
     }
137
     }
138
+
139
+    public void setPayoutAmt(int payoutAmt) {
140
+        this.payoutAmt = payoutAmt;
141
+    }
142
+
128
     public void setWord1(String word1) {
143
     public void setWord1(String word1) {
129
 
144
 
130
         this.word1 = word1;
145
         this.word1 = word1;
137
     public void setWord3(String word3) {
152
     public void setWord3(String word3) {
138
         this.word3 = word3;
153
         this.word3 = word3;
139
     }
154
     }
155
+
156
+    public String getOutputword() {
157
+        return outputword;
158
+    }
159
+
160
+    public Player getPlayer() {
161
+        return player;
162
+    }
163
+
140
 }
164
 }
141
 
165
 

+ 14
- 12
src/main/java/io/zipcoder/casino/Stud.java Datei anzeigen

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
+import java.util.Scanner;
4
 
5
 
5
 public class Stud extends CardGame implements Game {
6
 public class Stud extends CardGame implements Game {
6
     Console console = new Console();
7
     Console console = new Console();
17
         Printer.printMessage(player.getName() + " shows a " + card.getName());         //PRINT card name to CONSOLE
18
         Printer.printMessage(player.getName() + " shows a " + card.getName());         //PRINT card name to CONSOLE
18
     }
19
     }
19
 
20
 
20
-
21
     public boolean getIsDealt(){
21
     public boolean getIsDealt(){
22
         return isDealt;
22
         return isDealt;
23
     }
23
     }
24
 
24
 
25
-
26
     /**
25
     /**
27
      * Determine what player wins by looping through player array and then
26
      * Determine what player wins by looping through player array and then
28
      * passing each hand to the 'handValue' method
27
      * passing each hand to the 'handValue' method
138
     public void payAnte(ArrayList<CardPlayer> players) {
137
     public void payAnte(ArrayList<CardPlayer> players) {
139
         for(int i = 0; i < super.getPlayers().size(); i ++)
138
         for(int i = 0; i < super.getPlayers().size(); i ++)
140
         {
139
         {
141
-            players.get(i).getPlayer().changeBalance(-super.getAnte());
140
+            //players.get(i).getPlayer().changeBalance(-super.getAnte());
141
+            CardPlayer player = super.getPlayers().get(i);
142
+            player.getPlayer().changeBalance(-super.getAnte());
142
         }
143
         }
143
     }
144
     }
144
 
145
 
145
     public void startGame() {
146
     public void startGame() {
146
-        setHandSize(3);             //SET Hand Size for game(3)
147
-        payAnte(this.getPlayers());                  //PAY ante (all players)
148
-        deal(this.getPlayers());                     //DEALS cards/ hands to each player
149
-        startRound();               //METHOD called
147
+        setHandSize(3);                 //SET Hand Size for game(3)
148
+        payAnte(this.getPlayers());     //PAY ante (all players)
149
+        deal(this.getPlayers());        //DEALS cards/ hands to each player
150
+        startRound();                   //METHOD called
150
 
151
 
151
     }
152
     }
152
 
153
 
179
      * Deal each player(and dealer) 3 face down cards in turn
180
      * Deal each player(and dealer) 3 face down cards in turn
180
      */
181
      */
181
     public void deal(ArrayList<CardPlayer> players) {
182
     public void deal(ArrayList<CardPlayer> players) {
182
-        for(int i = 0; i < getHandSize(); i ++){                        //OUTER loop - run 3 times as there are 3 cards per hand
183
-            for (int j = 0; j < players.size(); j++) {             //INNER loop through each player
184
-                players.get(j).getHand().add(getDeck().pullCard());                                 //ADD card to player hand
183
+        for(int i = 0; i < getHandSize(); i ++){
184
+            for (int j = 0; j < players.size(); j++) {
185
+                players.get(j).getHand().add(getDeck().pullCard());
185
             }
186
             }
186
         }
187
         }
187
         isDealt = true;
188
         isDealt = true;
202
         return isCardFlipped;
203
         return isCardFlipped;
203
     }
204
     }
204
 
205
 
205
-    public void quit() {}
206
-    // public void payout(){ }
206
+    public void setScanner(Scanner scanner){
207
+        this.console.setScanner(scanner);
208
+    }
207
 }
209
 }
208
 
210
 

+ 12
- 9
src/main/java/io/zipcoder/casino/War.java Datei anzeigen

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 import java.util.*;
3
 import java.util.*;
4
-import java.util.concurrent.Executors;
5
-import java.util.concurrent.ScheduledExecutorService;
6
-import java.util.concurrent.TimeUnit;
7
-import java.util.regex.Pattern;
8
-import java.util.concurrent.TimeUnit;
9
 
4
 
10
 public class War extends CardGame implements Gamble, Game {
5
 public class War extends CardGame implements Gamble, Game {
11
 
6
 
114
         }
109
         }
115
     }
110
     }
116
 
111
 
112
+
117
     public void startGame(){
113
     public void startGame(){
118
         Printer.printMessage("Welcome to War!");
114
         Printer.printMessage("Welcome to War!");
119
-        super.chooseStatingPlayer();
115
+        super.chooseStartingPlayer();
120
         payAnte();
116
         payAnte();
121
         deal();
117
         deal();
122
         startRound();
118
         startRound();
123
     }
119
     }
124
 
120
 
121
+
122
+
125
     public void startRound() {
123
     public void startRound() {
126
         while(super.getLoser() == null) {
124
         while(super.getLoser() == null) {
127
             String input = console.getCMDFromUser("Type 'FLIP' to play the card at the top of your pile");
125
             String input = console.getCMDFromUser("Type 'FLIP' to play the card at the top of your pile");
131
                 Printer.printMessage(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
129
                 Printer.printMessage(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
132
                 winner.addDiscard(tableCards);
130
                 winner.addDiscard(tableCards);
133
                 tableCards = new ArrayList<Card>();
131
                 tableCards = new ArrayList<Card>();
134
-            }else if(input.equals("quit")){
135
-                Printer.printMessage("Thanks for playing chump!");
136
-                console.getScanner().close();
137
             } else {
132
             } else {
138
                 Printer.printMessage("Sorry, I don't understand that command.");
133
                 Printer.printMessage("Sorry, I don't understand that command.");
139
             }
134
             }
159
         }
154
         }
160
         Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
155
         Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
161
     }
156
     }
157
+
158
+    public void setScanner(Scanner scanner) {
159
+        this.console.setScanner(scanner);
160
+    }
161
+
162
+    public ArrayList<CardPlayer> getWarMembers() {
163
+        return warMembers;
164
+    }
162
 }
165
 }

+ 2
- 2
src/main/java/io/zipcoder/casino/Yahtzee.java Datei anzeigen

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
-import java.util.Scanner;
5
 
4
 
6
 public class Yahtzee extends DiceGame implements Game, Gamble {
5
 public class Yahtzee extends DiceGame implements Game, Gamble {
7
 
6
 
46
                 int rollChoice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
45
                 int rollChoice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
47
                 String diceToRoll = "";
46
                 String diceToRoll = "";
48
                 if(rollChoice == 2) {
47
                 if(rollChoice == 2) {
49
-                    diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
48
+                    Console console2 = new Console();
49
+                    diceToRoll = console2.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
50
                 }
50
                 }
51
                 rollOptions(rollChoice, diceToRoll); }
51
                 rollOptions(rollChoice, diceToRoll); }
52
 
52
 

+ 34
- 15
src/test/java/io/zipcoder/casino/CardTest.java Datei anzeigen

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
+import org.junit.Assert;
3
 import org.junit.Test;
4
 import org.junit.Test;
4
 
5
 
5
-import javax.smartcardio.Card;
6
-
7
 public class CardTest {
6
 public class CardTest {
8
 
7
 
9
-//    @Test
10
-//    public void createCard(){
11
-//        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
12
-//        System.out.println(card.getName());
13
-//    }
14
-//
15
-//    @Test
16
-//    public void createCard2(){
17
-//        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
18
-//        Card card1 = new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS);
19
-//        System.out.println(card.getName());
20
-//        System.out.println(card1.getName());
21
-//    }
8
+    @Test
9
+    public void testCreateCard(){
10
+        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
11
+        String expected = "TWO of CLUBS";
12
+        String actual = card.getName();
13
+        Assert.assertEquals(expected, actual);
14
+    }
15
+
16
+    @Test
17
+    public void testGetSuit(){
18
+        Card card = new Card(Card.CardValue.THREE, Card.Suit.DIAMONDS);
19
+        Card.Suit expected = Card.Suit.DIAMONDS;
20
+        Card.Suit actual = card.getSuit();
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testGetCardValue(){
26
+        Card card = new Card(Card.CardValue.ACE, Card.Suit.HEARTS);
27
+        int expected = 14;
28
+        int actual = card.getCardValue();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testVisibility(){
34
+        Card card = new Card(Card.CardValue.KING, Card.Suit.SPADES);
35
+        boolean before = card.isVisible();
36
+        card.setVisibility(true);
37
+        boolean after = card.isVisible();
38
+        Assert.assertNotEquals(before, after);
39
+    }
40
+
22
 }
41
 }

+ 56
- 3
src/test/java/io/zipcoder/casino/SlotTest.java Datei anzeigen

4
 import org.junit.Before;
4
 import org.junit.Before;
5
 import org.junit.Test;
5
 import org.junit.Test;
6
 import org.junit.Assert;
6
 import org.junit.Assert;
7
-
8
 import java.util.Random;
7
 import java.util.Random;
9
 
8
 
10
 
9
 
10
+
11
 public class SlotTest {
11
 public class SlotTest {
12
     private int betAmount = 10;
12
     private int betAmount = 10;
13
     private SlotMachine slotmachine = new SlotMachine(betAmount);
13
     private SlotMachine slotmachine = new SlotMachine(betAmount);
14
 
14
 
15
+    Player player = new Player("Bob", 400);
16
+
15
     @Test
17
     @Test
16
     public void testSlotResult1(){
18
     public void testSlotResult1(){
17
         String word1="MOUSE";
19
         String word1="MOUSE";
18
         String word2="MOUSE";
20
         String word2="MOUSE";
19
         String word3="MOUSE";
21
         String word3="MOUSE";
20
         //given
22
         //given
23
+        SlotMachine slotmachine = new SlotMachine(betAmount, player);
21
         slotmachine.setWord1(word1);
24
         slotmachine.setWord1(word1);
22
         slotmachine.setWord2(word2);
25
         slotmachine.setWord2(word2);
23
         slotmachine.setWord3(word3);
26
         slotmachine.setWord3(word3);
36
 
39
 
37
 
40
 
38
         //given
41
         //given
42
+        SlotMachine slotmachine = new SlotMachine(betAmount, player);
39
         slotmachine.setWord1(word1);
43
         slotmachine.setWord1(word1);
40
         slotmachine.setWord2(word2);
44
         slotmachine.setWord2(word2);
41
         slotmachine.setWord3(word3);
45
         slotmachine.setWord3(word3);
54
         String word3="CAT";
58
         String word3="CAT";
55
 
59
 
56
         //given
60
         //given
57
-        SlotMachine slotmachine = new SlotMachine(betAmount);
61
+        SlotMachine slotmachine = new SlotMachine(betAmount, player);
58
 
62
 
59
         slotmachine.setWord1(word1);
63
         slotmachine.setWord1(word1);
60
         slotmachine.setWord2(word2);
64
         slotmachine.setWord2(word2);
63
         slotmachine.slotResult();
67
         slotmachine.slotResult();
64
         int payout=slotmachine.getPayoutAmt();
68
         int payout=slotmachine.getPayoutAmt();
65
         Assert.assertEquals(0,payout);
69
         Assert.assertEquals(0,payout);
70
+    }
71
+
72
+    @Test
73
+    public void testGenerateWords() {
74
+        //Given
75
+        SlotMachine game = new SlotMachine(100, player);
76
+        String before = game.getOutputword();
77
+
78
+        //When
79
+        game.generateWords();
80
+        String after = game.getOutputword();
81
+
82
+        //Then
83
+        Assert.assertNotEquals(before, after);
84
+
85
+
86
+    }
87
+
88
+    @Test
89
+    public void testBet() {
90
+        //Given
91
+        SlotMachine game = new SlotMachine(100, player);
92
+        int expected = 300;
93
+
94
+        //When
95
+        game.bet(100);
96
+        int actual = game.getPlayer().getCurrentBalance();
97
+
98
+        //Then
99
+        Assert.assertEquals(expected, actual);
100
+
101
+
102
+    }
103
+
104
+    @Test
105
+    public void testPayout() {
106
+        //Given
107
+        SlotMachine game = new SlotMachine(100, player);
108
+        int expected = 500;
109
+
110
+        //When
111
+        game.bet(100);
112
+        game.setPayoutAmt(200);
113
+        game.payout();
114
+        int actual = game.getPlayer().getCurrentBalance();
115
+
116
+        //Then
117
+        Assert.assertEquals(expected, actual);
118
+
66
 
119
 
67
     }
120
     }
68
 
121
 
82
     }
135
     }
83
 
136
 
84
     @Test
137
     @Test
85
-    public void testGenerateWords(){
138
+    public void testGenerateWords2(){
86
         Random random = new Random(1);
139
         Random random = new Random(1);
87
 
140
 
88
 
141
 

+ 29
- 8
src/test/java/io/zipcoder/casino/StudTest.java Datei anzeigen

28
         cardsTest1.add(cardSix); cardsTest1.add(cardFive); cardsTest1.add(cardFour);
28
         cardsTest1.add(cardSix); cardsTest1.add(cardFive); cardsTest1.add(cardFour);
29
         this.cardPlayer1.setHand(cardsTest1);
29
         this.cardPlayer1.setHand(cardsTest1);
30
 
30
 
31
+
31
         ArrayList<Card> cardsTest2 = new ArrayList<>();
32
         ArrayList<Card> cardsTest2 = new ArrayList<>();
32
         Player player2 = new Player("Player2", 10);
33
         Player player2 = new Player("Player2", 10);
33
         this.cardPlayer2 = new CardPlayer(player2);
34
         this.cardPlayer2 = new CardPlayer(player2);
40
         players.add(this.cardPlayer1);
41
         players.add(this.cardPlayer1);
41
         players.add(this.cardPlayer2);
42
         players.add(this.cardPlayer2);
42
 
43
 
44
+        stud.addPlayers(player1, player2);
45
+
43
     }
46
     }
44
 
47
 
45
     @Test
48
     @Test
237
         boolean expected = true;
240
         boolean expected = true;
238
         //THEN
241
         //THEN
239
         boolean actual = stud.getIsDealt();
242
         boolean actual = stud.getIsDealt();
240
-
241
         Assert.assertEquals(expected, actual);
243
         Assert.assertEquals(expected, actual);
242
     }
244
     }
243
 
245
 
244
     @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
246
     @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
245
     public void payAnteTest(){
247
     public void payAnteTest(){
246
-        stud.payAnte(players);
247
-        //WHEN @Before
248
-        int expected = 10;
249
-        //THEN
250
-        int actual = players.get(0).getPlayer().getCurrentBalance();
251
-
252
-        Assert.assertEquals(expected, actual);
248
+       stud.payAnte(stud.getPlayers());
249
+       int expect = 0;
250
+       int actual = stud.getPlayers().get(0).getPlayer().getCurrentBalance();
251
+       Assert.assertEquals(expect, actual);
253
     }
252
     }
254
 
253
 
255
     @Test
254
     @Test
273
 
272
 
274
         Assert.assertEquals(expected, actual);
273
         Assert.assertEquals(expected, actual);
275
     }
274
     }
275
+
276
+//    @Test
277
+//    public void testStartRound(){
278
+//
279
+//        String input = "flip \n";
280
+//        stud.deal(players);
281
+//        System.out.println(players.get(0).getHand().size());
282
+//
283
+//        //System.out.println(cardPlayer1.getHand().size());
284
+//
285
+//        stud.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
286
+//        try {
287
+//            stud.startRound();
288
+//        } catch (NoSuchElementException e) {
289
+//
290
+//        }
291
+//
292
+//
293
+//
294
+//
295
+//        //Assert.assertTrue(war.getPlayersTurn() instanceof CardPlayer);
296
+//    }
276
 }
297
 }
277
 /*
298
 /*
278
     CODE FOR TRASH PANDAS
299
     CODE FOR TRASH PANDAS

+ 119
- 2
src/test/java/io/zipcoder/casino/WarTest.java Datei anzeigen

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
 
5
 
6
+import java.io.ByteArrayInputStream;
7
+import java.util.ArrayList;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
6
 public class WarTest {
11
 public class WarTest {
7
 
12
 
8
     @Test
13
     @Test
20
         War war = new War(10);
25
         War war = new War(10);
21
         Player player = new Player("Jon", 100);
26
         Player player = new Player("Jon", 100);
22
         war.addPlayers(player);
27
         war.addPlayers(player);
23
-        war.chooseStatingPlayer();
28
+        war.chooseStartingPlayer();
24
         war.deal();
29
         war.deal();
25
         war.getPlayers().get(0).setDiscard(deck);
30
         war.getPlayers().get(0).setDiscard(deck);
26
 
31
 
34
         War war = new War(10);
39
         War war = new War(10);
35
         Player player = new Player("Jon", 100);
40
         Player player = new Player("Jon", 100);
36
         war.addPlayers(player);
41
         war.addPlayers(player);
37
-        war.chooseStatingPlayer();
42
+        war.chooseStartingPlayer();
38
         war.playCard(false);
43
         war.playCard(false);
39
 
44
 
40
         Assert.assertEquals(war.getLoser(), player);
45
         Assert.assertEquals(war.getLoser(), player);
41
     }
46
     }
42
 
47
 
48
+    @Test
49
+    public void warDealTest(){
50
+        War war = new War(10);
51
+        war.addPlayers(new Player("Jon", 100));
52
+        war.chooseStartingPlayer();
53
+        war.deal();
54
+
55
+        Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 52);
56
+    }
57
+
58
+    @Test
59
+    public void warEachPlayerPlayCardTest(){
60
+        War war = new War(10);
61
+        war.addPlayers(new Player("Jon", 100), new Player("Jose", 200));
62
+
63
+        war.chooseStartingPlayer();
64
+        war.deal();
65
+        war.eachPlayerPlayCard();
66
+
67
+        int toalHand = 0;
68
+
69
+        for(CardPlayer player : war.getPlayers()){
70
+            toalHand += player.getHand().size();
71
+        }
72
+        Assert.assertTrue(toalHand == 50);
73
+    }
74
+
75
+    @Test
76
+    public void testWarStartGame(){
77
+        War war = new War(10);
78
+        Player player1 = new Player("Jose", 100);
79
+        Player player2 = new Player("Lauren", 200);
80
+        war.addPlayers(player1, player2);
81
+        war.chooseStartingPlayer();
82
+        war.deal();
83
+
84
+        String input = "flip \n";
85
+
86
+
87
+            war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
88
+            try {
89
+                war.startGame();
90
+            } catch (NoSuchElementException e) {
91
+
92
+            }
93
+
94
+
95
+        Assert.assertTrue(war.getPlayersTurn() instanceof CardPlayer);
96
+    }
97
+
98
+    @Test
99
+    public void testWarQuit(){
100
+        War war = new War(10);
101
+        Player player1 = new Player("Jose", 100);
102
+        Player player2 = new Player("Lauren", 200);
103
+        war.addPlayers(player1, player2);
104
+        war.chooseStartingPlayer();
105
+        CardPlayer startPlayer = war.getPlayersTurn();
106
+        war.deal();
107
+
108
+        String input = "quit \n";
109
+
110
+
111
+        war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
112
+        try {
113
+            war.startGame();
114
+        } catch (NoSuchElementException e) {
115
+
116
+        }
117
+
118
+
119
+       Assert.assertTrue(war.getPlayersTurn() == startPlayer);
120
+    }
121
+
122
+    @Test
123
+    public void testWarMethod(){
124
+        War war = new War(10);
125
+        Player player1 = new Player("Jose", 100);
126
+        Player player2 = new Player("Lauren", 200);
127
+        war.addPlayers(player1, player2);
128
+        war.chooseStartingPlayer();
129
+        CardPlayer startPlayer = war.getPlayersTurn();
130
+
131
+        ArrayList<Card> hand1 = new ArrayList<>();
132
+        hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
133
+        hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
134
+        hand1.add(new Card(Card.CardValue.THREE, Card.Suit.HEARTS));
135
+        hand1.add(new Card(Card.CardValue.TWO, Card.Suit.HEARTS));
136
+        hand1.add(new Card(Card.CardValue.ACE, Card.Suit.HEARTS));
137
+
138
+        ArrayList<Card> hand2 = new ArrayList<>();
139
+        hand2.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
140
+        hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
141
+        hand2.add(new Card(Card.CardValue.JACK, Card.Suit.HEARTS));
142
+        hand2.add(new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS));
143
+        hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
144
+
145
+        String input = "flip \n";
146
+
147
+        war.getPlayers().get(0).setHand(hand1);
148
+        war.getPlayers().get(1).setHand(hand2);
149
+
150
+        war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
151
+        try {
152
+            war.startRound();
153
+        } catch (NoSuchElementException e) {
154
+
155
+        }
156
+
157
+        Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 1);
158
+    }
159
+
43
 }
160
 }