瀏覽代碼

gssadasdaerge branch 'master' of https://git.zipcode.rocks/JenniferChao4/Casino

Jennifer Chao 6 年之前
父節點
當前提交
7af62dbdf2

+ 27
- 24
src/main/java/io/zipcoder/casino/DiceGame/Craps/Craps.java 查看文件

@@ -32,14 +32,20 @@ public class Craps extends DiceGame implements Gamble {
32 32
     }
33 33
 
34 34
     public void gamePlay(){
35
-        System.out.println("What would you like to bet? Min bet is: " + minBet);
35
+        System.out.println("What would you like to bet? Min bet is: $" + minBet);
36 36
         int amount = scanner.nextInt();
37
-        System.out.println("Are you ready to roll?");
37
+        if (amount<minBet){
38
+            System.out.println("Sorry but the minimum bet is $"+minBet);
39
+            gamePlay();
40
+        }
41
+        crapsPlayer.setInitialBet(amount);
42
+        System.out.println("Are you ready to roll?  yes or no");
38 43
         String response = scanner.next();
39 44
         if(response.equalsIgnoreCase("yes")) {
40
-            rollDice();
41
-        } else {
42
-            System.out.println("ready yet?");
45
+        } else if(response.equalsIgnoreCase("no")) {
46
+            gamePlay();
47
+        } else{
48
+            System.out.println("no valid");
43 49
         }
44 50
         firstRoll();
45 51
         remainingRolls();
@@ -53,23 +59,23 @@ public class Craps extends DiceGame implements Gamble {
53 59
     }
54 60
 
55 61
     public void firstRoll() {
56
-        rollDice();
57
-        if (rollDice() == 7 || rollDice() == 11) {
62
+        int result = rollDice();
63
+        if (result == 7 || result == 11) {
58 64
             win(crapsPlayer);
59
-        } else if (rollDice() == 2 || rollDice() == 3 || rollDice() == 12) {
65
+        } else if (result == 2 || result == 3 || result == 12) {
60 66
             lose(crapsPlayer);
61 67
         } else {
62
-            pointer = rollDice();
68
+            pointer = result;
63 69
         }
64 70
     }
65 71
 
66 72
     public void remainingRolls() {
67
-        rollDice();
68
-        if (rollDice() == pointer) {
73
+        int result = rollDice();
74
+        if (result == pointer) {
69 75
             win(crapsPlayer);
70
-        } else if (rollDice() == 7) {
76
+        } else if (result == 7) {
71 77
             lose(crapsPlayer);
72
-        }
78
+        } else remainingRolls();
73 79
     }
74 80
 
75 81
     public int betAmount(int amount, Player player) {
@@ -82,21 +88,17 @@ public class Craps extends DiceGame implements Gamble {
82 88
     }
83 89
 
84 90
     public void win(CrapsPlayers crapsPlayers){
85
-        player.setWallet(player.getWallet() + crapsPlayers.getBetPot() * 2);
86
-        System.out.println("Congrats! You won: $" + crapsPlayers.getBetPot());
87
-        System.out.println("Would you like to play again?");
88
-        String response = scanner.next();
89
-        if(response.equalsIgnoreCase("yes")) {
90
-            start();
91
-        } else if(response.equalsIgnoreCase("no")) {
92
-            end();
93
-        } else {
94
-            System.out.println("Sorry I didn't quite get that, try again!");
95
-        }
91
+       crapsPlayers.setWallet(crapsPlayers.getWallet() + crapsPlayers.getInitialBet() * 2);
92
+        System.out.println("Congrats! You won: $" + crapsPlayers.getInitialBet());
93
+        playAgain();
96 94
     }
97 95
 
98 96
     public void lose(CrapsPlayers crapsPlayers) {
99 97
         System.out.println("I'm so sorry, you lose!");
98
+      playAgain();
99
+    }
100
+
101
+    public void playAgain(){
100 102
         System.out.println("Would you like to play again?");
101 103
         String response = scanner.next();
102 104
         if(response.equalsIgnoreCase("yes")) {
@@ -106,6 +108,7 @@ public class Craps extends DiceGame implements Gamble {
106 108
         } else {
107 109
             System.out.println("Sorry I didn't quite get that, try again!");
108 110
         }
111
+        end();
109 112
     }
110 113
 
111 114
     public void distributePot(int amount, Player player) {

+ 10
- 7
src/main/java/io/zipcoder/casino/DiceGame/Craps/CrapsPlayers.java 查看文件

@@ -5,7 +5,7 @@ import io.zipcoder.casino.Player;
5 5
 public class CrapsPlayers {
6 6
 
7 7
         private Player player;
8
-
8
+        private int wallet;
9 9
         private int initialBet;
10 10
         private int rollValue;
11 11
         private int betPot;
@@ -21,21 +21,24 @@ public class CrapsPlayers {
21 21
             return player;
22 22
         }
23 23
 
24
-        public int getInitialBet() {
25
-            return initialBet;
26
-        }
27
-
28 24
         public void addToBetPot(int amount) {
29 25
             betPot += amount;
30 26
             this.player.setWallet(player.getWallet()- amount);
31 27
         }
32 28
 
33
-        public int getBetPot() {
34
-            return betPot;
29
+        public int getInitialBet() {
30
+            return initialBet;
35 31
         }
36 32
 
37 33
         public void setInitialBet(int amount){
38 34
             this.initialBet = amount;
39 35
         }
40 36
 
37
+    public void setWallet(int wallet) {
38
+            this.wallet = wallet;
39
+    }
40
+
41
+    public int getWallet() {
42
+            return wallet;
41 43
     }
44
+}

+ 14
- 0
src/main/java/io/zipcoder/casino/Test.java 查看文件

@@ -0,0 +1,14 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.DiceGame.Craps.Craps;
4
+
5
+public class Test {
6
+
7
+    public static void main(String[] args) {
8
+
9
+        Player Crappy = new Player("Crappy");
10
+        Craps game1 = new Craps(Crappy);
11
+
12
+        game1.gamePlay();
13
+    }
14
+}

+ 55
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java 查看文件

@@ -18,6 +18,61 @@ public class CrapsTest {
18 18
         Assert.assertTrue((2 < actual) && (actual < 12));
19 19
     }
20 20
 
21
+    @Test
22
+    public void testGamePlay(){
23
+        game1.gamePlay();
24
+    }
25
+
26
+    @Test
27
+    public void testFirstRoll(){
28
+
29
+    }
30
+
31
+    @Test
32
+    public void testRemainingRolls(){
33
+
34
+    }
35
+
36
+    @Test
37
+    public void testWin(){
38
+
39
+    }
40
+
41
+    @Test
42
+    public void testLose(){
43
+
44
+    }
45
+
46
+    @Test
47
+    public void testEnd(){
48
+
49
+    }
50
+
51
+    @Test
52
+    public void testGetPointer(){
53
+
54
+    }
55
+
56
+    @Test
57
+    public void testSetPointer(){
58
+
59
+    }
60
+
61
+    @Test
62
+    public void testAddPlayer(){
63
+
64
+    }
65
+
66
+    @Test
67
+    public void testRemovePlayer(){
68
+
69
+    }
70
+
71
+    @Test
72
+    public void testExitTable(){
73
+
74
+    }
75
+
21 76
 
22 77
 
23 78