Browse Source

Merge branch 'dev' into Table

merge
Chad 6 years ago
parent
commit
ac02f17493

+ 62
- 40
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherCards.java View File

@@ -1,52 +1,32 @@
1 1
 package io.zipcoder.casino.Leviathan.Games;
2
-import io.zipcoder.casino.Leviathan.Games.GameUtilities.Deck;
3
-import io.zipcoder.casino.Leviathan.Games.GameUtilities.Rank;
2
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.*;
4 3
 
5
-import io.zipcoder.casino.Leviathan.Games.GameUtilities.Card;
6
-import io.zipcoder.casino.Leviathan.Games.GameUtilities.Suit;
7 4
 import io.zipcoder.casino.Leviathan.Interfaces.*;
8 5
 import io.zipcoder.casino.Leviathan.*;
9 6
 
10 7
 public class  HigherCards extends CardGame implements Gambling{
8
+
11 9
     Console aConsole=new Console();
10
+    Deck deck = new Deck();
12 11
     Player aPlayer;
13 12
     boolean playAgain = true;
13
+    int wageAmount;
14
+    int bet;
15
+    int player,croupier;
16
+    public void setBet(int bet) {
17
+        this.bet = bet;
18
+    }
14 19
 
15 20
     public HigherCards(Player aPlayer){
16 21
         this.aPlayer = aPlayer;
17 22
     }
18
-
19
-     public void playGame() {
23
+    public void playGame() {
20 24
          aConsole.print("Welcome to HigherCards!\nWe both will draw a card, and the higher card wins the wager.\nThe House wins on ties\n");
21 25
          while (playAgain) {
26
+             deck.shuffle();
22 27
              int wageAmount = wageMoney();
23
-             Deck deck = new Deck();
24
-
25
-             Card acard = deck.draw();
26
-             Rank rank = acard.getRank();
27
-             int player = rank.getValue();
28
-             String playervalueString=rank.toString();
29
-             String playerFace=rank.getFaceValue();
30
-
31
-             Suit suit = acard.getSuit();
32
-             String suitSymbol=suit.getsuitSymbol();
33
-             String suitString = suit.toString();
34
-
35
-             aConsole.println("You got :%s of %s",playervalueString,suitString);
36
-             printCard(suitSymbol,playerFace);
37
-
38
-             Card acard2 = deck.draw();
39
-             Rank rank2 = acard2.getRank();
40
-             int croupier = rank2.getValue();
41
-             String playervalueString2=rank2.toString();
42
-             String playerFace2=rank2.getFaceValue();
43
-
44
-             Suit suit2 = acard2.getSuit();
45
-             String suitString2 = suit2.toString();
46
-             String suitSymbol2=suit2.getsuitSymbol();
47
-             aConsole.println("House got :%s of %s",playervalueString2,suitString2);
48
-             printCard(suitSymbol2,playerFace2);
49
-
28
+             playerDrawingCard();
29
+             houseDrawingCard();
50 30
              int totalChips = aPlayer.getTotalChips();
51 31
              findWinner(player, croupier, wageAmount);
52 32
              if (aPlayer.getTotalChips() > totalChips) {
@@ -60,11 +40,52 @@ public class  HigherCards extends CardGame implements Gambling{
60 40
                  String availableChips = aPlayer.getTotalChips().toString();
61 41
                  aConsole.println(availableChips);
62 42
              }
63
-             if((aPlayer.getTotalChips() == 0) || aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")){
64
-                 playAgain= false;
65
-             }
43
+             repeat();
66 44
          }
67 45
      }
46
+     public void repeat()
47
+     {
48
+         if((aPlayer.getTotalChips() == 0) )
49
+         {
50
+             aConsole.println("You are out of chips. You may no longer play\n");
51
+             playAgain= false;
52
+         }
53
+         else if(aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no"))
54
+         {
55
+             playAgain = false;
56
+         }
57
+     }
58
+     public void playerDrawingCard()
59
+     {
60
+         Card acard = deck.draw();
61
+         Rank rank = acard.getRank();
62
+         player = rank.getValue();
63
+         String playervalueString=rank.toString();
64
+         String playerFace=rank.getFaceValue();
65
+
66
+         Suit suit = acard.getSuit();
67
+         String suitSymbol=suit.getsuitSymbol();
68
+         String suitString = suit.toString();
69
+
70
+         aConsole.println("You got :%s of %s",playervalueString,suitString);
71
+         printCard(suitSymbol,playerFace);
72
+     }
73
+     public void houseDrawingCard()
74
+     {
75
+         Card acard2 = deck.draw();
76
+         Rank rank2 = acard2.getRank();
77
+         croupier = rank2.getValue();
78
+         String playervalueString2=rank2.toString();
79
+         String playerFace2=rank2.getFaceValue();
80
+
81
+         Suit suit2 = acard2.getSuit();
82
+         String suitString2 = suit2.toString();
83
+         String suitSymbol2=suit2.getsuitSymbol();
84
+
85
+         aConsole.println("House got :%s of %s",playervalueString2,suitString2);
86
+         printCard(suitSymbol2,playerFace2);
87
+     }
88
+
68 89
     public void findWinner(int player,int croupier,int wageAmount)
69 90
     {
70 91
         if (player > croupier) {
@@ -82,17 +103,18 @@ public class  HigherCards extends CardGame implements Gambling{
82 103
     }
83 104
 
84 105
     public int wageMoney() {
85
-        int bet;
86
-
87 106
         do {
88 107
             bet = aConsole.getIntInput("How much would you like to bet? You can only bet what you currently have.\n" +
89 108
                     "Current chips= " + aPlayer.getTotalChips());
90 109
 
91
-        }while(bet > aPlayer.getTotalChips());
92
-
110
+        }while (badBet() == true);
93 111
         return bet;
94 112
     }
95 113
 
114
+    public boolean badBet(){
115
+        return (bet > aPlayer.getTotalChips() || bet < 0);
116
+    }
117
+
96 118
     public void printCard(String suitSymbol,String playerFace)
97 119
     {
98 120
         aConsole.println(" ---------");

+ 13
- 1
src/test/java/io/zipcoder/casino/HigherCardsTest.java View File

@@ -5,8 +5,13 @@ import io.zipcoder.casino.Leviathan.Player;
5 5
 import org.junit.Assert;
6 6
 import org.junit.Test;
7 7
 
8
+import static org.junit.Assert.assertTrue;
9
+
8 10
 
9 11
 public class HigherCardsTest {
12
+    Player aplayer =new Player("Aleena",2000, 21);
13
+    HigherCards higherCards=new HigherCards(aplayer);
14
+
10 15
     @Test
11 16
     public void testFindAWinner()
12 17
     {
@@ -17,7 +22,14 @@ public class HigherCardsTest {
17 22
         higherCards.findWinner(10,2,500);
18 23
         int actual=aplayer.getTotalChips();
19 24
         Assert.assertEquals(actual,expected);
25
+    }
26
+    @Test
27
+    public void badBetTest() {
28
+        //Given
29
+        higherCards.setBet(-10);
30
+        //When
20 31
 
21
-
32
+        //Result
33
+        assertTrue(higherCards.badBet());
22 34
     }
23 35
 }