Browse Source

Merge branch 'master' of katelynne/Casino into master

JenniferChao4 6 years ago
parent
commit
3ad2e3c2cd

+ 75
- 31
src/main/java/io/zipcoder/casino/DiceGame/Craps/Craps.java View File

9
 import java.lang.reflect.Array;
9
 import java.lang.reflect.Array;
10
 import java.util.ArrayList;
10
 import java.util.ArrayList;
11
 import java.util.Map;
11
 import java.util.Map;
12
+import java.util.Scanner;
12
 
13
 
13
 public class Craps extends DiceGame implements Gamble {
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
     int rollNumber = 0;
18
     int rollNumber = 0;
18
-    private ArrayList<CrapsPlayers> crapsPlayers;
19
+    private CrapsPlayers crapsPlayer;
19
     private int minBet;
20
     private int minBet;
20
     private Player player;
21
     private Player player;
21
-    private Map<Integer, Integer> betPots;
22
     private Dice dice;
22
     private Dice dice;
23
     private int pointer;
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
     public Craps(Player player) {
26
     public Craps(Player player) {
35
         CrapsPlayers crappyPlayer = new CrapsPlayers(player);
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
         this.minBet = 10;
29
         this.minBet = 10;
39
         this.dice = new Dice();
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
     public int rollDice() {
48
     public int rollDice() {
49
     public void firstRoll() {
55
     public void firstRoll() {
50
         rollDice();
56
         rollDice();
51
         if (rollDice() == 7 || rollDice() == 11) {
57
         if (rollDice() == 7 || rollDice() == 11) {
52
-            //player wins!!
58
+            win(crapsPlayer);
53
         } else if (rollDice() == 2 || rollDice() == 3 || rollDice() == 12) {
59
         } else if (rollDice() == 2 || rollDice() == 3 || rollDice() == 12) {
54
-            //player loses :(
60
+            lose(crapsPlayer);
55
         } else {
61
         } else {
56
             pointer = rollDice();
62
             pointer = rollDice();
57
         }
63
         }
60
     public void remainingRolls() {
66
     public void remainingRolls() {
61
         rollDice();
67
         rollDice();
62
         if (rollDice() == pointer) {
68
         if (rollDice() == pointer) {
63
-            //player wins pot
69
+            win(crapsPlayer);
64
         } else if (rollDice() == 7) {
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
         return amount;
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
     public void distributePot(int amount, Player player) {
111
     public void distributePot(int amount, Player player) {
83
     }
113
     }
84
 
114
 
85
     public void start() {
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
     public void end() {
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
     public void takeATurn() {
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
     public void addPlayer(Player player) {
146
     public void addPlayer(Player player) {
100
         CrapsPlayers crappyPlayer = new CrapsPlayers(player);
147
         CrapsPlayers crappyPlayer = new CrapsPlayers(player);
101
-        this.crapsPlayers.add(crappyPlayer);
148
+        this.crapsPlayer = crappyPlayer;
102
     }
149
     }
103
 
150
 
104
     public void removePlayer(Player player) {
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 View File

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

+ 5
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java View File

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 import io.zipcoder.casino.DiceGame.Craps.Craps;
3
 import io.zipcoder.casino.DiceGame.Craps.Craps;
4
+import io.zipcoder.casino.DiceGame.Craps.CrapsPlayers;
4
 import io.zipcoder.casino.DiceGame.DiceGame;
5
 import io.zipcoder.casino.DiceGame.DiceGame;
5
 import org.junit.Assert;
6
 import org.junit.Assert;
6
 import org.junit.Test;
7
 import org.junit.Test;
10
     Player Crappy = new Player("Crappy");
11
     Player Crappy = new Player("Crappy");
11
     Craps game1 = new Craps(Crappy);
12
     Craps game1 = new Craps(Crappy);
12
 
13
 
14
+
13
     @Test
15
     @Test
14
     public void rollDiceTest(){
16
     public void rollDiceTest(){
15
         int actual = game1.rollDice();
17
         int actual = game1.rollDice();
16
         Assert.assertTrue((2 < actual) && (actual < 12));
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 View File

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