Jonathan Hinds преди 6 години
родител
ревизия
23ce62a887

+ 8
- 3
src/main/java/io/zipcoder/casino/War.java Целия файл

@@ -131,9 +131,6 @@ public class War extends CardGame implements Gamble, Game {
131 131
                 Printer.printMessage(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
132 132
                 winner.addDiscard(tableCards);
133 133
                 tableCards = new ArrayList<Card>();
134
-            }else if(input.equals("quit")){
135
-                Printer.printMessage("Thanks for playing chump!");
136
-                console.getScanner().close();
137 134
             } else {
138 135
                 Printer.printMessage("Sorry, I don't understand that command.");
139 136
             }
@@ -159,4 +156,12 @@ public class War extends CardGame implements Gamble, Game {
159 156
         }
160 157
         Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
161 158
     }
159
+
160
+    public void setScanner(Scanner scanner) {
161
+        this.console.setScanner(scanner);
162
+    }
163
+
164
+    public ArrayList<CardPlayer> getWarMembers() {
165
+        return warMembers;
166
+    }
162 167
 }

+ 13
- 15
src/test/java/io/zipcoder/casino/CardTest.java Целия файл

@@ -2,21 +2,19 @@ package io.zipcoder.casino;
2 2
 
3 3
 import org.junit.Test;
4 4
 
5
-import javax.smartcardio.Card;
6
-
7 5
 public class CardTest {
8 6
 
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
-//    }
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
+    }
22 20
 }

+ 0
- 1
src/test/java/io/zipcoder/casino/SlotTest.java Целия файл

@@ -63,6 +63,5 @@ public class SlotTest {
63 63
         slotmachine.slotResult();
64 64
         int payout=slotmachine.getPayoutAmt();
65 65
         Assert.assertEquals(0,payout);
66
-
67 66
     }
68 67
 }

+ 117
- 0
src/test/java/io/zipcoder/casino/WarTest.java Целия файл

@@ -3,6 +3,11 @@ package io.zipcoder.casino;
3 3
 import org.junit.Assert;
4 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 11
 public class WarTest {
7 12
 
8 13
     @Test
@@ -40,4 +45,116 @@ public class WarTest {
40 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.chooseStatingPlayer();
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.chooseStatingPlayer();
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.chooseStatingPlayer();
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.chooseStatingPlayer();
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.chooseStatingPlayer();
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
 }