Parcourir la source

Merge branch 'dev' into snarkyTable

merge
Kris Blassingame il y a 6 ans
Parent
révision
53a533f294

+ 3
- 6
src/main/java/io/zipcoder/casino/Leviathan/Casino.java Voir le fichier

@@ -8,15 +8,12 @@ public class Casino {
8 8
 
9 9
     public void setaPlayer() {
10 10
         String name = aConsole.getStringInput("What is your name?");
11
-        name = name.substring(0, 1).toUpperCase() + name.substring(1);
12
-        int age = aConsole.getIntInput("What is your age?");
13
-        int chips = 0;
14
-        if (age > 20) {
15
-            chips = aConsole.getIntInput("How many chips would you like to purchase?");
11
+        aPlayer = new Player(name.substring(0, 1).toUpperCase() + name.substring(1),0,aConsole.getIntInput("What is your age?"));
12
+        if (aPlayer.getAge() > 20) {
13
+            aPlayer.setTotalChips(aConsole.getIntInput("How many chips would you like to purchase?"));
16 14
         } else {
17 15
             aConsole.println("You are not old enough to gamble, so we won't be able to let you purchase any chips.");
18 16
         }
19
-        aPlayer = new Player(name, chips, age);
20 17
     }
21 18
 
22 19
     public void run() {

+ 0
- 2
src/main/java/io/zipcoder/casino/Leviathan/Console.java Voir le fichier

@@ -55,6 +55,4 @@ public class Console {
55 55
         }
56 56
         return correct;
57 57
     }
58
-
59
-
60 58
 }

+ 62
- 40
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherCards.java Voir le fichier

@@ -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(" ---------");

+ 75
- 26
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherDice.java Voir le fichier

@@ -8,33 +8,69 @@ import io.zipcoder.casino.Leviathan.Player;
8 8
 
9 9
 
10 10
 public class HigherDice extends DiceGame implements Gambling {
11
-    Console aConsole = new Console();
12
-    DrawSingleDie draw = new DrawSingleDie();
13
-    int bet;
14
-    Player aPlayer;
15
-    Die aDie = new Die();
16
-    boolean playAgain = true;
17
-
11
+    private Console aConsole = new Console();
12
+    private DrawSingleDie draw = new DrawSingleDie();
13
+    private int bet;
14
+    private Player aPlayer;
15
+    private Die aDie = new Die();
16
+    private boolean playAgain = true;
18 17
 
19 18
     public HigherDice(Player aPlayer) {
20 19
         this.aPlayer = aPlayer;
21 20
     }
22 21
 
22
+    public Console getaConsole() {
23
+        return aConsole;
24
+    }
25
+
26
+    public void setaConsole(Console aConsole) {
27
+        this.aConsole = aConsole;
28
+    }
29
+
30
+    public DrawSingleDie getDraw() {
31
+        return draw;
32
+    }
33
+
34
+    public void setDraw(DrawSingleDie draw) {
35
+        this.draw = draw;
36
+    }
37
+
38
+    public int getBet() {
39
+        return bet;
40
+    }
41
+
42
+    public void setBet(int bet) {
43
+        this.bet = bet;
44
+    }
45
+
46
+    public Player getaPlayer() {
47
+        return aPlayer;
48
+    }
49
+
50
+    public void setaPlayer(Player aPlayer) {
51
+        this.aPlayer = aPlayer;
52
+    }
53
+
54
+    public Die getaDie() {
55
+        return aDie;
56
+    }
57
+
58
+    public void setaDie(Die aDie) {
59
+        this.aDie = aDie;
60
+    }
61
+
62
+    public boolean isPlayAgain() {
63
+        return playAgain;
64
+    }
65
+
66
+    public void setPlayAgain(boolean playAgain) {
67
+        this.playAgain = playAgain;
68
+    }
23 69
 
24 70
     public void playGame() {
25 71
         aConsole.print("Welcome to HigherDice!\nWe will both roll a die, and the higher number wins the wager.\nThe House wins on ties\n");
26
-
27
-        while (playAgain == true) {
28
-
29
-            bet = wageMoney();
30
-            aConsole.getStringInput("Please roll your die");
31
-            aDie.rollADice();
32
-            int player = aDie.getValue();
33
-            aConsole.println("Your Roll:\n" + draw.drawSingleDie(player).toString());
34
-            aDie.rollADice();
35
-            int croupier = aDie.getValue();
36
-            aConsole.println("House Roll:\n" + draw.drawSingleDie(croupier).toString());
37
-            findWinner(player, croupier, bet);
72
+        while (playAgain) {
73
+            findWinner(wageMoney(), playerPhase(), housePhase());
38 74
             repeat();
39 75
         }
40 76
     }
@@ -48,31 +84,44 @@ public class HigherDice extends DiceGame implements Gambling {
48 84
         }
49 85
     }
50 86
 
51
-    public void findWinner(int player, int croupier, int wageAmount) {
87
+    public void findWinner(int wageAmount, int player, int croupier) {
52 88
 
53 89
         if (player > croupier) {
54 90
             aPlayer.setTotalChips(aPlayer.getTotalChips() + wageAmount);
55 91
             int[] change = {aPlayer.getTally()[0] + 1, aPlayer.getTally()[1]};
56 92
             aPlayer.setTally(change);
57 93
             aConsole.println("You win! Your current chip total is: " + aPlayer.getTotalChips());
58
-            aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
59 94
         } else {
60 95
             aPlayer.setTotalChips(aPlayer.getTotalChips() - wageAmount);
61 96
             int[] change = {aPlayer.getTally()[0], aPlayer.getTally()[1] + 1};
62 97
             aPlayer.setTally(change);
63 98
             aConsole.println("You lose! Your current chip total is: " + aPlayer.getTotalChips());
64
-            aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
65
-
66 99
         }
100
+        aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
67 101
     }
68 102
 
69 103
     public int wageMoney() {
70
-
71 104
         do {
72 105
             bet = aConsole.getIntInput("How much would you like to bet? You can only bet what you currently have.\n" +
73 106
                     "Current chips= " + aPlayer.getTotalChips() + "\n");
74
-        } while (bet > aPlayer.getTotalChips() && bet < 0);
75
-
107
+        } while (badBet());
76 108
         return bet;
77 109
     }
110
+
111
+    public boolean badBet() {
112
+        return (bet > aPlayer.getTotalChips() || bet < 0);
113
+    }
114
+
115
+    private int playerPhase() {
116
+        aConsole.getStringInput("Please roll your die");
117
+        aDie.rollADice();
118
+        aConsole.println("Your Roll:\n" + draw.drawSingleDie(aDie.getValue()).toString());
119
+        return aDie.getValue();
120
+    }
121
+
122
+    private int housePhase() {
123
+        aDie.rollADice();
124
+        aConsole.println("House Roll:\n" + draw.drawSingleDie(aDie.getValue()).toString());
125
+        return aDie.getValue();
126
+    }
78 127
 }

+ 13
- 1
src/test/java/io/zipcoder/casino/HigherCardsTest.java Voir le fichier

@@ -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
 }

+ 22
- 0
src/test/java/io/zipcoder/casino/HigherDiceTest.java Voir le fichier

@@ -43,6 +43,28 @@ public class HigherDiceTest {
43 43
 
44 44
     }
45 45
 
46
+    @Test
47
+    public void badBetTest(){
48
+        //Given
49
+        test.setBet(-10);
50
+        //When
51
+
52
+        //Result
53
+        assertTrue(test.badBet());
54
+
55
+    }
56
+
57
+    @Test
58
+    public void repeatTest(){
59
+        //Given
60
+        aPlayer.setTotalChips(0);
61
+        //When
62
+        test.repeat();
63
+        //Result
64
+        assertFalse(test.isPlayAgain());
65
+
66
+    }
67
+
46 68
     /**
47 69
      * Tears down the test fixture.
48 70
      *

+ 1
- 1
src/test/java/io/zipcoder/casino/TableTest.java Voir le fichier

@@ -11,7 +11,7 @@ import io.zipcoder.casino.Leviathan.*;
11 11
      */
12 12
     public class TableTest {
13 13
         Player aPlayer = new Player("Chad", 500, 27);
14
-        Table table = new Table(aPlayer);
14
+        Table test = new Table(aPlayer);
15 15
         /**
16 16
          * Default constructor for test class DiceTest
17 17
          */