Aleena Rose-Mathew 6 lat temu
rodzic
commit
bc8d82d46f

+ 12
- 26
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherCards.java Wyświetl plik

@@ -12,6 +12,7 @@ public class  HigherCards extends CardGame implements Gambling{
12 12
     boolean playAgain = true;
13 13
     int bet;
14 14
     int player,croupier;
15
+    int totalChips,wageAmount;
15 16
     public void setBet(int bet) {
16 17
         this.bet = bet;
17 18
     }
@@ -24,20 +25,16 @@ public class  HigherCards extends CardGame implements Gambling{
24 25
          while (playAgain) {
25 26
              deck.shuffle();
26 27
              int wageAmount = wageMoney();
28
+             aConsole.println("You Got :");
27 29
              playerDrawingCard();
30
+             aConsole.println("House Got :");
28 31
              houseDrawingCard();
29
-             int totalChips = aPlayer.getTotalChips();
30
-             findWinner(player, croupier, wageAmount);
31
-             if (aPlayer.getTotalChips() > totalChips) {
32
-                 aConsole.println("Congrats ! You Won ");
33
-             } else {
34
-                 aConsole.println("You Lose");
35
-             }
36
-             aConsole.println("Your current available Chips");
37
-             aConsole.println(aPlayer.getTotalChips().toString());
32
+             findWinner(wageAmount,player, croupier);
33
+             aConsole.println("Your current available Chips %d",aPlayer.getTotalChips());
38 34
              repeat();
39 35
          }
40 36
      }
37
+
41 38
      public void repeat()
42 39
      {
43 40
          if((aPlayer.getTotalChips() == 0) )
@@ -55,44 +52,33 @@ public class  HigherCards extends CardGame implements Gambling{
55 52
          Card acard = deck.draw();
56 53
          Rank rank = acard.getRank();
57 54
          player = rank.getValue();
58
-         String playervalueString=rank.toString();
59
-         String playerFace=rank.getFaceValue();
60
-
61 55
          Suit suit = acard.getSuit();
62
-         String suitSymbol=suit.getsuitSymbol();
63
-         String suitString = suit.toString();
64
-
65
-         aConsole.println("You got :%s of %s",playervalueString,suitString);
66
-         printCard(suitSymbol,playerFace);
56
+         printCard(suit.getsuitSymbol(),rank.getFaceValue());
67 57
      }
68 58
      public void houseDrawingCard()
69 59
      {
70 60
          Card acard2 = deck.draw();
71 61
          Rank rank2 = acard2.getRank();
72 62
          croupier = rank2.getValue();
73
-         String playervalueString2=rank2.toString();
74
-         String playerFace2=rank2.getFaceValue();
75
-
76 63
          Suit suit2 = acard2.getSuit();
77
-         String suitString2 = suit2.toString();
78
-         String suitSymbol2=suit2.getsuitSymbol();
79
-
80
-         aConsole.println("House got :%s of %s",playervalueString2,suitString2);
81
-         printCard(suitSymbol2,playerFace2);
64
+         printCard(suit2.getsuitSymbol(),rank2.getFaceValue());
82 65
      }
83 66
 
84
-    public void findWinner(int player,int croupier,int wageAmount)
67
+    public void findWinner(int wageAmount,int player,int croupier)
85 68
     {
86 69
         if (player > croupier) {
70
+            aConsole.println("Congrats ! You Won ");
87 71
             int[] change = {aPlayer.getTally()[0] + 1, aPlayer.getTally()[1]};
88 72
             aPlayer.setTally(change);
89 73
            aPlayer.setTotalChips(aPlayer.getTotalChips()+ wageAmount);
90 74
         }
91 75
         else {
76
+            aConsole.println("You Lose");
92 77
             int[] change = {aPlayer.getTally()[0], aPlayer.getTally()[1] + 1};
93 78
             aPlayer.setTally(change);
94 79
             aPlayer.setTotalChips(aPlayer.getTotalChips()- wageAmount);
95 80
         }
81
+
96 82
         aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
97 83
     }
98 84
 

+ 7
- 3
src/test/java/io/zipcoder/casino/HigherCardsTest.java Wyświetl plik

@@ -5,21 +5,23 @@ 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.assertFalse;
8 9
 import static org.junit.Assert.assertTrue;
9 10
 
10 11
 
11 12
 public class HigherCardsTest {
12 13
     Player aplayer =new Player("Aleena",2000, 21);
14
+
13 15
     HigherCards higherCards=new HigherCards(aplayer);
14 16
 
15 17
     @Test
16 18
     public void testFindAWinner()
17 19
     {
18
-        Player aplayer =new Player("Aleena",2000, 21);
19
-        HigherCards higherCards=new HigherCards(aplayer);
20
+        //Player aplayer =new Player("Aleena",2000, 21);
21
+        //HigherCards higherCards=new HigherCards(aplayer);
20 22
 
21 23
         int expected=2500;
22
-        higherCards.findWinner(10,2,500);
24
+        higherCards.findWinner(500,10,2);
23 25
         int actual=aplayer.getTotalChips();
24 26
         Assert.assertEquals(actual,expected);
25 27
     }
@@ -32,4 +34,6 @@ public class HigherCardsTest {
32 34
         //Result
33 35
         assertTrue(higherCards.badBet());
34 36
     }
37
+
38
+
35 39
 }