Kaynağa Gözat

updated craps

Connor Dunnigan 6 yıl önce
ebeveyn
işleme
9da0d33d5d

+ 32
- 8
src/main/java/io/zipcoder/casino/dicegames/Craps.java Dosyayı Görüntüle

@@ -15,7 +15,6 @@ public class Craps extends DiceGame implements Gamble {
15 15
 
16 16
     public Craps() {
17 17
         readyPlayers();
18
-        placeBet();
19 18
         run();
20 19
     }
21 20
     //for test purposes
@@ -32,35 +31,52 @@ public class Craps extends DiceGame implements Gamble {
32 31
 
33 32
     public void run(){
34 33
         for(int i = 0; i < crapsPlayers.size(); i++){
35
-            play(crapsPlayers.get(i),crapsPlayers.get(i).getBet());
34
+            greetPlayer(crapsPlayers.get(i).getP());
35
+            play(crapsPlayers.get(i));
36 36
         }
37 37
     }
38 38
 
39 39
     public void placeBet() {
40
-        bet = console.getIntegerInput("Enter your bet");
40
+        this.bet = console.getIntegerInput("Enter your bet");
41 41
     }
42 42
 
43 43
     public void evaluateBet(Player player, long payout) {
44 44
         player.setChipBalance(player.getChipBalance()+payout);
45 45
     }
46 46
 
47
-    public void play(CrapsPlayer currentPlayer, long bet) {
48
-
49
-        this.bet = bet;
50
-
47
+    public void play(CrapsPlayer currentPlayer) {
48
+        placeBet();
49
+        promptEnterKey("roll dice");
51 50
         int sum = rollDie(2); // roll two dice, store sum in sum field.
52
-
51
+        console.println("Your roll sum equals: " + sum);
53 52
         if (sum == 7 || sum == 11) {
53
+            console.println("\n*********");
54
+            console.println("YOU WIN!");
55
+            console.println("*********\n");
54 56
             evaluateBet(currentPlayer.getP(), bet*2);
55 57
         } else if (sum == 2 || sum == 3 || sum == 12) {
58
+            console.println("\n*********");
59
+            console.println("YOU LOSE!");
60
+            console.println("*********\n");
56 61
             evaluateBet(currentPlayer.getP(), -(bet*2));
57 62
         } else {
58 63
             int point = sum;
59 64
             do {
65
+                console.println("\n--------------------");
66
+                console.println("Point to roll for: " + point);
67
+                console.println("--------------------");
68
+                promptEnterKey("roll again");
60 69
                 sum = rollDie(2);
70
+                console.println("You rolled a " + sum);
61 71
                 if (sum == 7) {
72
+                    console.println("\n*********");
73
+                    console.println("YOU LOSE!");
74
+                    console.println("*********\n");
62 75
                     evaluateBet(currentPlayer.getP(), -bet);
63 76
                 } else if (sum == point) {
77
+                    console.println("\n*********");
78
+                    console.println("YOU WIN!");
79
+                    console.println("*********\n");
64 80
                     evaluateBet(currentPlayer.getP(), bet);
65 81
                 }
66 82
             } while (sum != point && sum != 7);
@@ -72,4 +88,12 @@ public class Craps extends DiceGame implements Gamble {
72 88
             System.out.println(crapsPlayers.get(i).getP().getChipBalance());
73 89
         }
74 90
     }
91
+
92
+    public void greetPlayer(Player playa){
93
+        console.println("Ok " + playa.getName() + ", you're up...\n");
94
+    }
95
+
96
+    public void promptEnterKey(String str){
97
+        String input = console.getStringInput("\nPress \"ENTER\" to " + str);
98
+    }
75 99
 }

+ 1
- 1
src/main/java/io/zipcoder/casino/player/CrapsPlayer.java Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder.casino.player;
2 2
 
3
-public class CrapsPlayer {
3
+public class CrapsPlayer  {
4 4
     Player crapsPlayer;
5 5
     long bet;
6 6