Ver código fonte

Merge branch 'master' of katelynne/Casino into master

JenniferChao4 6 anos atrás
pai
commit
3ad2e3c2cd

+ 75
- 31
src/main/java/io/zipcoder/casino/DiceGame/Craps/Craps.java Ver arquivo

@@ -9,34 +9,40 @@ import io.zipcoder.casino.Player;
9 9
 import java.lang.reflect.Array;
10 10
 import java.util.ArrayList;
11 11
 import java.util.Map;
12
+import java.util.Scanner;
12 13
 
13 14
 public class Craps extends DiceGame implements Gamble {
15
+    Scanner scanner;
14 16
 
15 17
 
16
-    public int[] betOptions = {2, 3, 4, 5, 6, 8, 9, 10, 11, 12};
17 18
     int rollNumber = 0;
18
-    private ArrayList<CrapsPlayers> crapsPlayers;
19
+    private CrapsPlayers crapsPlayer;
19 20
     private int minBet;
20 21
     private Player player;
21
-    private Map<Integer, Integer> betPots;
22 22
     private Dice dice;
23 23
     private int pointer;
24 24
 
25
-    public int getPointer() {
26
-        return pointer;
27
-    }
28
-
29
-    public void setPointer(int pointer) {
30
-        this.pointer = pointer;
31
-    }
32
-
33 25
 
34 26
     public Craps(Player player) {
35 27
         CrapsPlayers crappyPlayer = new CrapsPlayers(player);
36
-        ArrayList<Integer> betOptions = new ArrayList<>(10);
37
-        this.crapsPlayers = new ArrayList<>();
28
+        this.crapsPlayer = new CrapsPlayers(player);
38 29
         this.minBet = 10;
39 30
         this.dice = new Dice();
31
+        scanner = new Scanner(System.in);
32
+    }
33
+
34
+    public void gamePlay(){
35
+        System.out.println("What would you like to bet? Min bet is: " + minBet);
36
+        int amount = scanner.nextInt();
37
+        System.out.println("Are you ready to roll?");
38
+        String response = scanner.next();
39
+        if(response.equalsIgnoreCase("yes")) {
40
+            rollDice();
41
+        } else {
42
+            System.out.println("ready yet?");
43
+        }
44
+        firstRoll();
45
+        remainingRolls();
40 46
     }
41 47
 
42 48
     public int rollDice() {
@@ -49,9 +55,9 @@ public class Craps extends DiceGame implements Gamble {
49 55
     public void firstRoll() {
50 56
         rollDice();
51 57
         if (rollDice() == 7 || rollDice() == 11) {
52
-            //player wins!!
58
+            win(crapsPlayer);
53 59
         } else if (rollDice() == 2 || rollDice() == 3 || rollDice() == 12) {
54
-            //player loses :(
60
+            lose(crapsPlayer);
55 61
         } else {
56 62
             pointer = rollDice();
57 63
         }
@@ -60,12 +66,9 @@ public class Craps extends DiceGame implements Gamble {
60 66
     public void remainingRolls() {
61 67
         rollDice();
62 68
         if (rollDice() == pointer) {
63
-            //player wins pot
69
+            win(crapsPlayer);
64 70
         } else if (rollDice() == 7) {
65
-            //player loses all money in pot
66
-        } else {
67
-            //if betOptions == rollDice()
68
-            //casino adds money to the pot - matching whatever bet the player made
71
+            lose(crapsPlayer);
69 72
         }
70 73
     }
71 74
 
@@ -73,9 +76,36 @@ public class Craps extends DiceGame implements Gamble {
73 76
         return amount;
74 77
     }
75 78
 
76
-    public void bet() {
79
+    public int betAmount(int amount, CrapsPlayers crapsPlayers) {
80
+        crapsPlayers.addToBetPot(amount);
81
+        return betAmount(amount, crapsPlayers.getPlayer());
82
+    }
77 83
 
84
+    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
+        }
96
+    }
78 97
 
98
+    public void lose(CrapsPlayers crapsPlayers) {
99
+        System.out.println("I'm so sorry, you lose!");
100
+        System.out.println("Would you like to play again?");
101
+        String response = scanner.next();
102
+        if(response.equalsIgnoreCase("yes")) {
103
+            start();
104
+        } else if(response.equalsIgnoreCase("no")) {
105
+            end();
106
+        } else {
107
+            System.out.println("Sorry I didn't quite get that, try again!");
108
+        }
79 109
     }
80 110
 
81 111
     public void distributePot(int amount, Player player) {
@@ -83,32 +113,46 @@ public class Craps extends DiceGame implements Gamble {
83 113
     }
84 114
 
85 115
     public void start() {
86
-        //when starting a game passLine bet or dontPassLine bet is made
87
-
88
-
116
+        gamePlay();
89 117
     }
90 118
 
91 119
     public void end() {
120
+        System.out.println("Would you like to leave the table?");
121
+        String response = scanner.next();
122
+        if(response.equalsIgnoreCase("yes")) {
123
+            exitTable(crapsPlayer);
124
+        } else if(response.equalsIgnoreCase("no")) {
125
+            start();
126
+        }
127
+
128
+    }
92 129
 
130
+    public void exitTable(CrapsPlayers crapsPlayer){
131
+        removePlayer(player);
93 132
     }
94 133
 
95 134
     public void takeATurn() {
96 135
 
97 136
     }
98 137
 
138
+    public int getPointer() {
139
+        return pointer;
140
+    }
141
+
142
+    public void setPointer(int pointer) {
143
+        this.pointer = pointer;
144
+    }
145
+
99 146
     public void addPlayer(Player player) {
100 147
         CrapsPlayers crappyPlayer = new CrapsPlayers(player);
101
-        this.crapsPlayers.add(crappyPlayer);
148
+        this.crapsPlayer = crappyPlayer;
102 149
     }
103 150
 
104 151
     public void removePlayer(Player player) {
105
-        for (CrapsPlayers crappyPlayer : crapsPlayers) {
106
-            if (crappyPlayer.getPlayer() == player) {
107
-                this.crapsPlayers.remove(crappyPlayer);
108
-                break;
152
+            if (crapsPlayer.getPlayer() == player) {
153
+                this.crapsPlayer = null;
109 154
             }
110 155
 
111 156
         }
112 157
 
113
-    }
114
-}
158
+    }

+ 1
- 0
src/main/java/io/zipcoder/casino/DiceGame/Craps/CrapsPlayers.java Ver arquivo

@@ -27,6 +27,7 @@ public class CrapsPlayers {
27 27
 
28 28
         public void addToBetPot(int amount) {
29 29
             betPot += amount;
30
+            this.player.setWallet(player.getWallet()- amount);
30 31
         }
31 32
 
32 33
         public int getBetPot() {

+ 5
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java Ver arquivo

@@ -1,6 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 import io.zipcoder.casino.DiceGame.Craps.Craps;
4
+import io.zipcoder.casino.DiceGame.Craps.CrapsPlayers;
4 5
 import io.zipcoder.casino.DiceGame.DiceGame;
5 6
 import org.junit.Assert;
6 7
 import org.junit.Test;
@@ -10,10 +11,14 @@ public class CrapsTest {
10 11
     Player Crappy = new Player("Crappy");
11 12
     Craps game1 = new Craps(Crappy);
12 13
 
14
+
13 15
     @Test
14 16
     public void rollDiceTest(){
15 17
         int actual = game1.rollDice();
16 18
         Assert.assertTrue((2 < actual) && (actual < 12));
17 19
     }
18 20
 
21
+
22
+
23
+
19 24
 }

+ 7
- 0
src/test/java/io/zipcoder/casino/DiceGame/Craps/CrapsTest.java Ver arquivo

@@ -0,0 +1,7 @@
1
+package io.zipcoder.casino.DiceGame.Craps;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class CrapsTest {
6
+
7
+}