Selaa lähdekoodia

Merge branch 'Working' of https://git.zipcode.rocks/nedredmond/ZCW-OOP-Casino into Working

ThuyKhong 6 vuotta sitten
vanhempi
commit
c64a1c7413

+ 37
- 26
src/main/java/io/zipcoder/casino/dicegames/Craps.java Näytä tiedosto

@@ -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
     }

+ 35
- 2
src/main/java/io/zipcoder/casino/dicegames/dice/Dice.java Näytä tiedosto

@@ -1,11 +1,36 @@
1 1
 package io.zipcoder.casino.dicegames.dice;
2 2
 
3
+    import java.util.ArrayList;
4
+    import java.util.HashMap;
5
+    import java.util.List;
3 6
     import java.util.Random;
4 7
 
5 8
     public class Dice {
6 9
         public int dieCount;
10
+        private ArrayList<Integer> lastRoll = new ArrayList<Integer>();
11
+
12
+        private HashMap<Integer, Character> diceGraphics = new HashMap<Integer, Character>() {{
13
+            put(1,'⚀');
14
+            put(2,'⚁');
15
+            put(3,'⚂');
16
+            put(4,'⚃');
17
+            put(5,'⚄');
18
+            put(6,'⚅');
19
+        }};
20
+
21
+        public char getDieGraphic(int roll) {
22
+            return diceGraphics.get(roll);
23
+        }
24
+
25
+        public String getLastRollGraphic() {
26
+            String lastRollGraphic = "";
27
+            for (Integer roll : lastRoll) {
28
+                lastRollGraphic += getDieGraphic(roll) + " ";
29
+            }
30
+            return lastRollGraphic;
31
+        }
7 32
 
8
-//        Dice(){ this.dieCount = 1; }
33
+        //        Dice(){ this.dieCount = 1; }
9 34
 
10 35
         public Dice(int dieCount) {
11 36
             this.dieCount = dieCount;
@@ -19,11 +44,19 @@ package io.zipcoder.casino.dicegames.dice;
19 44
             Random random = new Random();
20 45
 
21 46
             int rollSum = 0;
47
+            if (lastRoll.size() > 0) {
48
+                lastRoll.clear();
49
+            }
22 50
             for (int i = 0; i < dieCount; i++) {
23 51
                 int roll = random.nextInt(6)+1;
52
+                lastRoll.add(roll);
24 53
                 rollSum += roll;
25 54
             }
26 55
             return rollSum;
27 56
         }
28 57
 
29
-}
58
+        public ArrayList<Integer> getLastRoll() {
59
+            return lastRoll;
60
+        }
61
+
62
+    }

+ 12
- 1
src/main/java/io/zipcoder/casino/utilities/Console.java Näytä tiedosto

@@ -100,6 +100,12 @@ 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(">");
106
+    }
107
+
108
+
103 109
     public static String getStringInput(String prompt){
104 110
         Scanner scanner = new Scanner(System.in);
105 111
         println(prompt);
@@ -111,7 +117,12 @@ public class Console {
111 117
          println(prompt);
112 118
          int userInput = scanner.nextInt();
113 119
          return userInput;
114
-
120
+     }
121
+     public Integer integerInputSameLine(String prompt){
122
+        Scanner scanner = new Scanner(System.in);
123
+        printWcarrot(prompt);
124
+        int userInput = scanner.nextInt();
125
+        return userInput;
115 126
      }
116 127
      public static Long getLongInput(String prompt) {
117 128
          Scanner scanner = new Scanner(System.in);