Browse Source

refactored methods

Connor Dunnigan 6 years ago
parent
commit
35657bf58f

+ 17
- 12
src/main/java/io/zipcoder/casino/dicegames/Craps.java View File

@@ -46,27 +46,33 @@ public class Craps extends DiceGame implements Gamble {
46 46
 
47 47
     public void play(CrapsPlayer currentPlayer) {
48 48
         placeBet();
49
-
50
-        promptEnterKey("roll dice");
51
-
52 49
         int sum = rollDie(2);
53 50
 
51
+        promptEnterKey("roll dice");
54 52
         console.println("Your roll sum equals: " + sum);
55 53
 
54
+        simulateCraps(currentPlayer, sum);
55
+    }
56
+
57
+    private void simulateCraps(CrapsPlayer currentPlayer, int sum) {
56 58
         if (sum == 7 || sum == 11) {
57 59
             evalWin(currentPlayer.getP());
58 60
         } else if (sum == 2 || sum == 3 || sum == 12) {
59 61
             evalLoss(currentPlayer.getP());
60 62
         } else {
61
-            int point = sum;
62
-            do {
63
-                printRollAgain(point);
64
-                sum = rollDie(2);
65
-                evalReRoll(currentPlayer, sum , point);
66
-            } while (sum != point && sum != 7);
63
+            rollForPoint(currentPlayer, sum);
67 64
         }
68 65
     }
69 66
 
67
+    private void rollForPoint(CrapsPlayer currentPlayer, int sum) {
68
+        int point = sum;
69
+        do {
70
+            printRollAgain(point);
71
+            sum = rollDie(2);
72
+            evalReRoll(currentPlayer, sum , point);
73
+        } while (sum != point && sum != 7);
74
+    }
75
+
70 76
     public void print(){
71 77
         for(int i = 0; i < crapsPlayers.size(); i++){
72 78
             System.out.println(crapsPlayers.get(i).getP().getChipBalance());
@@ -74,9 +80,8 @@ public class Craps extends DiceGame implements Gamble {
74 80
     }
75 81
 
76 82
     public void printRollAgain(int point){
77
-        console.println("\n--------------------");
78
-        console.println("Point to roll for: " + point);
79
-        console.println("--------------------");
83
+        console.println("\n--------------------" +
84
+                "\nPoint to roll for: " + point + "--------------------");
80 85
         promptEnterKey("roll again");
81 86
     }
82 87
 

+ 1
- 1
src/main/java/io/zipcoder/casino/utilities/Console.java View File

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