Quellcode durchsuchen

fixed game annoucnement for Craps and Blackjack

NedRedmond vor 6 Jahren
Ursprung
Commit
481643a384

+ 16
- 44
src/main/java/io/zipcoder/casino/Casino.java Datei anzeigen

@@ -49,57 +49,29 @@ public class Casino {
49 49
     }
50 50
 
51 51
     public void chooseTable() {
52
+        Game game = null;
53
+
54
+        Integer gameChoice = console.getGameChoice();
55
+
56
+        switch(gameChoice){
57
+            case 1:
58
+                game = new Craps();
59
+                break;
60
+            case 2:
61
+                game = new BlackJack();
62
+                break;
63
+            case 3:
64
+                game = new GoFish();
65
+                break;
66
+        }
52 67
 
53
-      console.println("GAME LIST\n");
54
-      console.println("1. CRAPS\n");
55
-      console.println("2. BLACK JACK\n");
56
-      console.println("3. GO FISH\n");
57
-      console.println("CHOOSE TABLE\n");
58
-      Integer number=console.getIntegerInput("") ;
59
-       switch(number){
60
-         case 1:
61
-             runGame(new Craps());
62
-             break;
63
-        case 2:
64
-             runGame(new BlackJack());
65
-             break;
66
-        case 3:
67
-             runGame(new GoFish());
68
-             break;
69
-       }        
68
+        runGame(game);
70 69
      }
71 70
 
72 71
     private void runGame(Game game) {
73
-        console.println("WELCOME TO %s", game.getClassName());
74 72
         this.game = game;
75 73
     }
76 74
 
77
-    public void confirmPlayers() {
78
-      boolean isConfirmed = false;
79
-      while(!isConfirmed){
80
-        console.println("Current Players: ");
81
-        for(Player player : players.getPlayers()){
82
-          console.println(player.getName());
83
-        }
84
-        Integer choice = console.getIntegerInput("Choose option:\n (1)Confirm Players\n (2)Add Player\n (3)Remove Player\n");
85
-        String name;
86
-        switch(choice){
87
-          case 1: isConfirmed = true;
88
-            break;
89
-          case 2: name = console.getStringInput("Enter name of player to add: ");
90
-                    players.addPlayer(new Player(name));
91
-            break;
92
-          case 3: name = console.getStringInput("Enter name of player to remove: ");
93
-                  for(Player player : players.getPlayers()){
94
-                    if(player.getName() == name)
95
-                      players.removePlayer(player);
96
-                  }
97
-            break;
98
-          default: break;
99
-        }
100
-      }
101
-    }
102
-
103 75
     public void bootPlayer() {
104 76
         // If player balance is 0, player game over
105 77
         for (int i = 0; i < players.getPlayers().size(); i++) {

+ 4
- 3
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java Datei anzeigen

@@ -32,6 +32,7 @@ public class BlackJack extends CardGame implements Gamble {
32 32
 
33 33
     @Override
34 34
     public void runGame(){
35
+        announceGameChoice();
35 36
         for(int i = 0; i < blackJackPlayers.size(); i++){
36 37
             play(blackJackPlayers.get(i),blackJackPlayers.get(i).getBet());
37 38
         }
@@ -181,8 +182,8 @@ public class BlackJack extends CardGame implements Gamble {
181 182
         for (int i = 0; i < blackJackPlayers.size(); i++) {
182 183
             p = blackJackPlayers.get(i);
183 184
             if (getSum(p.getHand()) == 21) {
184
-                Console.println(p.getName() + ", you have " + p.getHand().display());
185
-                Console.println(p.getName() + ", you have blackjack. You win!");
185
+                Console.println(p.getP().getName() + ", you have " + p.getHand().display());
186
+                Console.println(p.getP().getName() + ", you have blackjack. You win!");
186 187
                 evaluateBet(p, p.getBet());
187 188
                 blackJackPlayers.remove(i);
188 189
             }
@@ -212,7 +213,7 @@ public class BlackJack extends CardGame implements Gamble {
212 213
     @Override
213 214
     public void placeBet(Player player) {
214 215
         BlackJackPlayer blackJackPlayer = (BlackJackPlayer) player;
215
-        long bet = Console.getLongInput("Please enter your bet.");
216
+        long bet = Console.getLongInput(String.format("%s, please enter your bet.", ((BlackJackPlayer) player).getP().getName()));
216 217
         blackJackPlayer.setBet(bet);
217 218
     }
218 219
 

+ 1
- 0
src/main/java/io/zipcoder/casino/dicegames/Craps.java Datei anzeigen

@@ -33,6 +33,7 @@ public class Craps extends DiceGame implements Gamble {
33 33
 
34 34
     @Override
35 35
     public void runGame(){
36
+        announceGameChoice();
36 37
         for(int i = 0; i < crapsPlayers.size(); i++){
37 38
             greetPlayer(crapsPlayers.get(i).getP());
38 39
             play(crapsPlayers.get(i));

+ 11
- 0
src/main/java/io/zipcoder/casino/utilities/Console.java Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder.casino.utilities;
2 2
 
3
+import io.zipcoder.casino.Casino;
4
+
3 5
 import java.awt.peer.SystemTrayPeer;
4 6
 import java.util.Scanner;
5 7
 
@@ -137,6 +139,15 @@ public class Console {
137 139
         return userInput;
138 140
     }
139 141
 
142
+    public Integer getGameChoice() {
143
+        println("GAME LIST\n");
144
+        println("1. CRAPS\n");
145
+        println("2. BLACK JACK\n");
146
+        println("3. GO FISH\n");
147
+        println("CHOOSE TABLE\n");
148
+        return getIntegerInput("");
149
+    }
150
+
140 151
 
141 152
 //
142 153
 //    public Integer getPlayersInput(String prompt){

+ 11
- 2
src/main/java/io/zipcoder/casino/utilities/abstracts/Game.java Datei anzeigen

@@ -1,13 +1,22 @@
1 1
 package io.zipcoder.casino.utilities.abstracts;
2 2
 
3
+import io.zipcoder.casino.utilities.Console;
4
+
5
+import java.sql.DriverManager;
6
+
3 7
 public abstract class Game {
4
-    String className = this.getClass().getName();
8
+    String className = this.getClass().getSimpleName();
5 9
 
6 10
     public abstract void promptContinue();
7 11
 
8 12
     public abstract void runGame();
9 13
 
10
-    public String getClassName() {
14
+    private String getClassName() {
11 15
         return className;
12 16
     }
17
+
18
+    protected void announceGameChoice() {
19
+        Console console = new Console();
20
+        console.println("Welcome to %s\n", this.getClassName());
21
+    }
13 22
 }