瀏覽代碼

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

nedredmond 6 年之前
父節點
當前提交
49aab31740

+ 34
- 9
src/main/java/io/zipcoder/casino/dicegames/Craps.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package io.zipcoder.casino.dicegames;
2 2
 
3
+import io.zipcoder.casino.utilities.Console;
3 4
 import io.zipcoder.casino.utilities.Gamble;
4 5
 import io.zipcoder.casino.player.CrapsPlayer;
5 6
 import io.zipcoder.casino.player.Player;
@@ -8,13 +9,12 @@ import io.zipcoder.casino.player.Players;
8 9
 import java.util.ArrayList;
9 10
 
10 11
 public class Craps extends DiceGame implements Gamble {
11
-
12
+    Console console = new Console();
12 13
     private ArrayList<CrapsPlayer> crapsPlayers = new ArrayList<>();
13 14
     long bet;
14 15
 
15 16
     public Craps() {
16 17
         readyPlayers();
17
-        placeBet();
18 18
         run();
19 19
     }
20 20
     //for test purposes
@@ -31,35 +31,52 @@ public class Craps extends DiceGame implements Gamble {
31 31
 
32 32
     public void run(){
33 33
         for(int i = 0; i < crapsPlayers.size(); i++){
34
-            play(crapsPlayers.get(i),crapsPlayers.get(i).getBet());
34
+            greetPlayer(crapsPlayers.get(i).getP());
35
+            play(crapsPlayers.get(i));
35 36
         }
36 37
     }
37 38
 
38 39
     public void placeBet() {
39
-        bet = 5;
40
+        this.bet = console.getIntegerInput("Enter your bet");
40 41
     }
41 42
 
42 43
     public void evaluateBet(Player player, long payout) {
43 44
         player.setChipBalance(player.getChipBalance()+payout);
44 45
     }
45 46
 
46
-    public void play(CrapsPlayer currentPlayer, long bet) {
47
-
48
-        this.bet = bet;
49
-
47
+    public void play(CrapsPlayer currentPlayer) {
48
+        placeBet();
49
+        promptEnterKey("roll dice");
50 50
         int sum = rollDie(2); // roll two dice, store sum in sum field.
51
-
51
+        console.println("Your roll sum equals: " + sum);
52 52
         if (sum == 7 || sum == 11) {
53
+            console.println("\n*********");
54
+            console.println("YOU WIN!");
55
+            console.println("*********\n");
53 56
             evaluateBet(currentPlayer.getP(), bet*2);
54 57
         } else if (sum == 2 || sum == 3 || sum == 12) {
58
+            console.println("\n*********");
59
+            console.println("YOU LOSE!");
60
+            console.println("*********\n");
55 61
             evaluateBet(currentPlayer.getP(), -(bet*2));
56 62
         } else {
57 63
             int point = sum;
58 64
             do {
65
+                console.println("\n--------------------");
66
+                console.println("Point to roll for: " + point);
67
+                console.println("--------------------");
68
+                promptEnterKey("roll again");
59 69
                 sum = rollDie(2);
70
+                console.println("You rolled a " + sum);
60 71
                 if (sum == 7) {
72
+                    console.println("\n*********");
73
+                    console.println("YOU LOSE!");
74
+                    console.println("*********\n");
61 75
                     evaluateBet(currentPlayer.getP(), -bet);
62 76
                 } else if (sum == point) {
77
+                    console.println("\n*********");
78
+                    console.println("YOU WIN!");
79
+                    console.println("*********\n");
63 80
                     evaluateBet(currentPlayer.getP(), bet);
64 81
                 }
65 82
             } while (sum != point && sum != 7);
@@ -71,4 +88,12 @@ public class Craps extends DiceGame implements Gamble {
71 88
             System.out.println(crapsPlayers.get(i).getP().getChipBalance());
72 89
         }
73 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
+    }
74 99
 }

+ 1
- 1
src/main/java/io/zipcoder/casino/player/CrapsPlayer.java 查看文件

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