Sfoglia il codice sorgente

update craps presentation

Connor Dunnigan 6 anni fa
parent
commit
4b5307778c

+ 37
- 26
src/main/java/io/zipcoder/casino/dicegames/Craps.java Vedi File

@@ -37,7 +37,7 @@ public class Craps extends DiceGame implements Gamble {
37 37
     }
38 38
 
39 39
     public void placeBet() {
40
-        this.bet = console.getIntegerInput("Enter your bet");
40
+        this.bet = console.integerInputSameLine("Enter your bet: ");
41 41
     }
42 42
 
43 43
     public void evaluateBet(Player player, long payout) {
@@ -46,39 +46,23 @@ public class Craps extends DiceGame implements Gamble {
46 46
 
47 47
     public void play(CrapsPlayer currentPlayer) {
48 48
         placeBet();
49
+
49 50
         promptEnterKey("roll dice");
50
-        int sum = rollDie(2); // roll two dice, store sum in sum field.
51
+
52
+        int sum = rollDie(2);
53
+
51 54
         console.println("Your roll sum equals: " + sum);
55
+
52 56
         if (sum == 7 || sum == 11) {
53
-            console.println("\n*********");
54
-            console.println("YOU WIN!");
55
-            console.println("*********\n");
56
-            evaluateBet(currentPlayer.getP(), bet*2);
57
+            evalWin(currentPlayer.getP());
57 58
         } else if (sum == 2 || sum == 3 || sum == 12) {
58
-            console.println("\n*********");
59
-            console.println("YOU LOSE!");
60
-            console.println("*********\n");
61
-            evaluateBet(currentPlayer.getP(), -(bet*2));
59
+            evalLoss(currentPlayer.getP());
62 60
         } else {
63 61
             int point = sum;
64 62
             do {
65
-                console.println("\n--------------------");
66
-                console.println("Point to roll for: " + point);
67
-                console.println("--------------------");
68
-                promptEnterKey("roll again");
63
+                printRollAgain(point);
69 64
                 sum = rollDie(2);
70
-                console.println("You rolled a " + sum);
71
-                if (sum == 7) {
72
-                    console.println("\n*********");
73
-                    console.println("YOU LOSE!");
74
-                    console.println("*********\n");
75
-                    evaluateBet(currentPlayer.getP(), -bet);
76
-                } else if (sum == point) {
77
-                    console.println("\n*********");
78
-                    console.println("YOU WIN!");
79
-                    console.println("*********\n");
80
-                    evaluateBet(currentPlayer.getP(), bet);
81
-                }
65
+                evalReRoll(currentPlayer, sum , point);
82 66
             } while (sum != point && sum != 7);
83 67
         }
84 68
     }
@@ -89,6 +73,33 @@ public class Craps extends DiceGame implements Gamble {
89 73
         }
90 74
     }
91 75
 
76
+    public void printRollAgain(int point){
77
+        console.println("\n--------------------");
78
+        console.println("Point to roll for: " + point);
79
+        console.println("--------------------");
80
+        promptEnterKey("roll again");
81
+    }
82
+
83
+    public void evalReRoll(CrapsPlayer currentPlayer, int sum, int point){
84
+        console.println("You rolled a " + sum);
85
+        if (sum == 7) {
86
+            evalLoss(currentPlayer.getP());
87
+        } else if (sum == point) {
88
+            evalWin(currentPlayer.getP());
89
+        }
90
+    }
91
+
92
+    public void evalLoss(Player player){
93
+        console.println("\n*********\nYOU LOSE!\n*********\n");
94
+        evaluateBet(player, -bet);
95
+    }
96
+    public void evalWin(Player player){
97
+        console.println("\n*******************************\n" +
98
+                "WINNER WINNER CHICKEN DINNER!\n" +
99
+                "*******************************\n");
100
+        evaluateBet(player, bet);
101
+    }
102
+
92 103
     public void greetPlayer(Player playa){
93 104
         console.println("Ok " + playa.getName() + ", you're up...\n");
94 105
     }

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

@@ -100,6 +100,11 @@ public class Console {
100 100
         print(output + "\n", args);
101 101
     }
102 102
 
103
+    public static void printWcarrot(String output){
104
+        System.out.println(output);
105
+        System.out.print("> asdfasdfasdfasdf");
106
+    }
107
+
103 108
     public String getStringInput(String prompt){
104 109
         Scanner scanner = new Scanner(System.in);
105 110
         println(prompt);
@@ -111,7 +116,12 @@ public class Console {
111 116
          println(prompt);
112 117
          int userInput = scanner.nextInt();
113 118
          return userInput;
114
-
119
+     }
120
+     public Integer integerInputSameLine(String prompt){
121
+        Scanner scanner = new Scanner(System.in);
122
+        printWcarrot(prompt);
123
+        int userInput = scanner.nextInt();
124
+        return userInput;
115 125
      }
116 126
      public  Long getLongInput(String prompt) {
117 127
          Scanner scanner = new Scanner(System.in);