Quellcode durchsuchen

Merge branch 'Working' of cdunni/ZCW-OOP-Casino into Working

nedredmond vor 6 Jahren
Ursprung
Commit
c866197e92

+ 21
- 23
src/main/java/io/zipcoder/casino/dicegames/Craps.java Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 package io.zipcoder.casino.dicegames;
2 2
 
3
-import io.zipcoder.casino.player.BlackJackPlayer;
4 3
 import io.zipcoder.casino.utilities.Console;
5 4
 import io.zipcoder.casino.utilities.interfaces.Gamble;
6 5
 import io.zipcoder.casino.player.CrapsPlayer;
@@ -18,6 +17,7 @@ public class Craps extends DiceGame implements Gamble {
18 17
     public Craps() {
19 18
         announceGameChoice();
20 19
         readyPlayers();
20
+        //promptBets();
21 21
         runGame();
22 22
     }
23 23
     //for test purposes
@@ -40,15 +40,8 @@ public class Craps extends DiceGame implements Gamble {
40 40
         }
41 41
     }
42 42
 
43
-    public void placeBet() {
44
-        this.bet = console.integerInputSameLine("Enter your bet: ");
45
-    }
46
-
47
-    @Override
48 43
     public void placeBet(Player player) {
49
-        BlackJackPlayer blackJackPlayer = (BlackJackPlayer) player;
50
-        long bet = Console.getLongInput("Please enter your bet.");
51
-        blackJackPlayer.setBet(bet);
44
+        bet = console.integerInputSameLine("Enter your bet: ");
52 45
     }
53 46
 
54 47
     public void evaluateBet(Player player, long payout) {
@@ -56,28 +49,34 @@ public class Craps extends DiceGame implements Gamble {
56 49
     }
57 50
 
58 51
     public void play(CrapsPlayer currentPlayer) {
59
-        placeBet();
60
-
61
-        promptEnterKey("roll dice");
62
-
52
+        placeBet(currentPlayer);
63 53
         int sum = rollDie(2);
64 54
 
55
+        promptEnterKey("roll dice");
65 56
         console.println("Your roll sum equals: " + sum);
66 57
 
58
+        simulateCraps(currentPlayer, sum);
59
+    }
60
+
61
+    private void simulateCraps(CrapsPlayer currentPlayer, int sum) {
67 62
         if (sum == 7 || sum == 11) {
68 63
             evalWin(currentPlayer.getP());
69 64
         } else if (sum == 2 || sum == 3 || sum == 12) {
70 65
             evalLoss(currentPlayer.getP());
71 66
         } else {
72
-            int point = sum;
73
-            do {
74
-                printRollAgain(point);
75
-                sum = rollDie(2);
76
-                evalReRoll(currentPlayer, sum , point);
77
-            } while (sum != point && sum != 7);
67
+            rollForPoint(currentPlayer, sum);
78 68
         }
79 69
     }
80 70
 
71
+    private void rollForPoint(CrapsPlayer currentPlayer, int sum) {
72
+        int point = sum;
73
+        do {
74
+            printRollAgain(point);
75
+            sum = rollDie(2);
76
+            evalReRoll(currentPlayer, sum , point);
77
+        } while (sum != point && sum != 7);
78
+    }
79
+
81 80
     public void print(){
82 81
         for(int i = 0; i < crapsPlayers.size(); i++){
83 82
             System.out.println(crapsPlayers.get(i).getP().getChipBalance());
@@ -85,9 +84,8 @@ public class Craps extends DiceGame implements Gamble {
85 84
     }
86 85
 
87 86
     public void printRollAgain(int point){
88
-        console.println("\n--------------------");
89
-        console.println("Point to roll for: " + point);
90
-        console.println("--------------------");
87
+        console.println("\n--------------------" +
88
+                "\nPoint to roll for: " + point + "\n--------------------");
91 89
         promptEnterKey("roll again");
92 90
     }
93 91
 
@@ -120,5 +118,5 @@ public class Craps extends DiceGame implements Gamble {
120 118
     }
121 119
 
122 120
     @Override
123
-    public void promptContinue(){};
121
+    public void promptContinue(){}
124 122
 }

+ 1
- 0
src/main/java/io/zipcoder/casino/player/CrapsPlayer.java Datei anzeigen

@@ -20,4 +20,5 @@ public class CrapsPlayer extends Player {
20 20
     public long getBet() {
21 21
         return bet;
22 22
     }
23
+    public void setBet(long bet) { this.bet = bet;}
23 24
 }

+ 1
- 1
src/main/java/io/zipcoder/casino/utilities/Console.java Datei anzeigen

@@ -104,7 +104,7 @@ public class Console {
104 104
 
105 105
     public static void printWcarrot(String output){
106 106
         System.out.println(output);
107
-        System.out.print(">");
107
+        System.out.print("> ");
108 108
     }
109 109
 
110 110
 

+ 1
- 0
src/main/java/io/zipcoder/casino/utilities/interfaces/Gamble.java Datei anzeigen

@@ -3,6 +3,7 @@ package io.zipcoder.casino.utilities.interfaces;
3 3
 import io.zipcoder.casino.player.Player;
4 4
 
5 5
 public interface Gamble {
6
+
6 7
     void placeBet(Player player);
7 8
 
8 9
     void evaluateBet(Player player, long payout);

+ 1
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java Datei anzeigen

@@ -17,6 +17,7 @@ public class CrapsTest {
17 17
         CrapsPlayer cplayer2 = new CrapsPlayer(new Player("Joe",100),20);
18 18
         CrapsPlayer cplayer3 = new CrapsPlayer(new Player("Will",100),12);
19 19
 
20
+        //When
20 21
         playerz.add(cplayer1);
21 22
         playerz.add(cplayer2);
22 23
         playerz.add(cplayer3);