瀏覽代碼

corrected printer class

Jonathan Hinds 6 年之前
父節點
當前提交
4c82f9a3d6
共有 2 個文件被更改,包括 21 次插入21 次删除
  1. 17
    9
      src/main/java/io/zipcoder/casino/Printer.java
  2. 4
    12
      src/main/java/io/zipcoder/casino/War.java

+ 17
- 9
src/main/java/io/zipcoder/casino/Printer.java 查看文件

@@ -13,35 +13,35 @@ public class Printer {
13 13
         }
14 14
         games = games.trim();
15 15
 
16
-        System.out.println("Sorry, there is no game with that name, try one of: " + games);
16
+        printMessage("Sorry, there is no game with that name, try one of: " + games);
17 17
     }
18 18
 
19 19
     public static void getBet(String phrase){
20
-        System.out.println("What is the " + phrase + " at the table you're looking for?");
20
+        printMessage("What is the " + phrase + " at the table you're looking for?");
21 21
     }
22 22
 
23 23
     public static void unacceptableMaxBet(int minBet){
24
-        System.out.println("Your bet must be above " + minBet);
24
+        printMessage("Your bet must be above " + minBet);
25 25
     }
26 26
 
27 27
     public static void unacceptableMinBet(){
28
-        System.out.println("Your bet must be above $0");
28
+        printMessage("Your bet must be above $0");
29 29
     }
30 30
 
31 31
     public static void studHandsDealt(){
32
-        System.out.println("Each player Dealt 3 cards");
32
+        printMessage("Each player Dealt 3 cards");
33 33
     }
34 34
 
35 35
     public static void showCard(Player player, Card card){
36
-        System.out.println(player.getName() + " shows a " + card.getName());
36
+        printMessage(player.getName() + " shows a " + card.getName());
37 37
     }
38 38
 
39 39
     public static void pickGameMsg(){
40
-        System.out.println("Please choose a game to play!");
40
+        printMessage("Please choose a game to play!");
41 41
     }
42 42
 
43 43
     public static void closeGameMsg(){
44
-        System.out.println("Thanks for your money chump!");
44
+        printMessage("Thanks for your money chump!");
45 45
     }
46 46
 
47 47
     public static void printMessage(String string) {
@@ -49,7 +49,15 @@ public class Printer {
49 49
     }
50 50
 
51 51
     public static void pleaseEnterNum(){
52
-        System.out.println("Please enter a number");
52
+        printMessage("Please enter a number");
53
+    }
54
+    
55
+    public static void welcomeTo(String gameName){
56
+        printMessage("Welcome to " + gameName + "!");
57
+    }
58
+    
59
+    public static void wrongCommand(){
60
+        printMessage("Sorry, there is no game with that name.")
53 61
     }
54 62
 
55 63
 

+ 4
- 12
src/main/java/io/zipcoder/casino/War.java 查看文件

@@ -11,7 +11,7 @@ public class War extends CardGame implements Gamble, Game {
11 11
 
12 12
     private ArrayList<Card> tableCards = new ArrayList<Card>();
13 13
     private ArrayList<CardPlayer> warMembers = new ArrayList<CardPlayer>();
14
-    private Scanner scanner = new Scanner(System.in);
14
+    private Console console = new Console();
15 15
     private boolean war = false;
16 16
 
17 17
     War(int ante) {
@@ -142,7 +142,7 @@ public class War extends CardGame implements Gamble, Game {
142 142
     }
143 143
 
144 144
     public void startGame() {
145
-        System.out.println("Welcome to war!");
145
+        Printer.welcomeTo("War");
146 146
         super.chooseStatingPlayer();
147 147
         payAnte();
148 148
         deal();
@@ -152,9 +152,8 @@ public class War extends CardGame implements Gamble, Game {
152 152
     public void startRound() {
153 153
         while(super.getLoser() == null) {
154 154
 
155
-            String input = getCommand();
156
-
157
-            if (input.equals("play")) {
155
+            String input = console.getCMDFromUser("Type 'FLIP' to play the card at the top of your pile");
156
+            if (input.equals("flip")) {
158 157
                 //each player
159 158
                 for (CardPlayer player : super.getPlayers()) {
160 159
                     //plays a card, then
@@ -178,13 +177,6 @@ public class War extends CardGame implements Gamble, Game {
178 177
 
179 178
     }
180 179
 
181
-    public String getCommand(){
182
-        System.out.println("Type play to play the top card from your pile.");
183
-        String input = scanner.next();
184
-        input = input.toLowerCase().trim();
185
-        return input;
186
-    }
187
-
188 180
     public void deal() {
189 181
         //while there are cards in the deck
190 182
         while(super.getDeck().size() != 0){