Преглед изворни кода

altering sysout to separate console

Jennifer Chao пре 6 година
родитељ
комит
4986689929

+ 4
- 10
src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackJack.java Прегледај датотеку

@@ -13,11 +13,10 @@ import java.util.Scanner;
13 13
 
14 14
 public class BlackJack extends CardGame implements Gamble {
15 15
 
16
-    Casino_test instance = Casino_test.getInstance();
17
-    Player player = instance.getPlayer();
16
+    private BlackJackPlayer blackJackPlayer;
17
+    // Player player;
18 18
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
19 19
     private final int minBet = 50;
20
-   // private BlackJackGameplay gamePlay = new BlackJackGameplay();
21 20
     private Deck deck = new Deck();
22 21
     private boolean justDealt = false;
23 22
     private BlackJackPlayer dealer = new BlackJackPlayer(new Dealer());
@@ -26,7 +25,7 @@ public class BlackJack extends CardGame implements Gamble {
26 25
     public BlackJack() {}
27 26
 
28 27
     public BlackJack(Player player) {
29
-        BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
28
+        this.blackJackPlayer = new BlackJackPlayer(player);
30 29
         blackJackPlayers.add(dealer);
31 30
         this.blackJackPlayers.add(blackJackPlayer);
32 31
         this.thePlayer = blackJackPlayers.get(1);
@@ -39,12 +38,7 @@ public class BlackJack extends CardGame implements Gamble {
39 38
         player.addToHand(card);
40 39
         countPlayerHand(player);
41 40
 
42
-        if (player == blackJackPlayers.get(1)) {
43
-            System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nYou Hit: " + card.toString());
44
-        } else if (player == this.dealer) {
45
-            System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDealer Hit: " + card.toString());
46
-        }
47
-
41
+        Console_BlackJack.hitCard(player, card);
48 42
     }
49 43
 
50 44
     public void split(BlackJackPlayer player) {

+ 1
- 1
src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackJackGameplay.java
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 49
- 46
src/main/java/io/zipcoder/casino/CardGame/BlackJack/Console_BlackJack.java Прегледај датотеку

@@ -8,72 +8,75 @@ import java.util.ArrayList;
8 8
 
9 9
 public class Console_BlackJack {
10 10
 
11
-    private static String tie = "\n\n~~~~~~~~~~~~~~~~~~~\n\nTie, no one wins";
12
-    private static String win = "\n\n~~~~~~~~~~~~~~~~~~~\n\nYou win!";
13
-    private static String lose = "\n\n~~~~~~~~~~~~~~~~~~~\n\nYou lose!";
14
-
15
-    public static void printResult(BlackJackPlayer blackJackPlayer, BlackJackPlayer dealer, char result) {
16
-        String playerResult = "";
17
-        switch (result) {
18
-            case 'T':
19
-                playerResult = tie;
20
-                break;
21
-            case 'W':
22
-                playerResult = win;
23
-            case 'L':
24
-                playerResult = lose;
25
-        }
26
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nYour Hand Value: " + blackJackPlayer.getHandValue() + "\n\nDealer's Hand Value: " + dealer.getHandValue() + playerResult);
11
+    public static void inputError() {
12
+        System.out.println("That's not a valid option, please try again.");
13
+    }
14
+
15
+    public static void finalGoodbye() {
16
+        System.out.println("Thanks for coming to Thunder Theta, good bye!");
27 17
     }
28 18
 
19
+    public static void blackJackWelcome(Player player){
20
+        System.out.println("\nHi " + player.getName() + "! Welcome to BlackJack!\n\nThe minimum bet is $50.");
21
+    }
29 22
 
30 23
     public static String inGameMenu(BlackJack blackJack, BlackJackPlayer blackJackPlayer, BlackJackPlayer dealer) {
31 24
         String response = Console.getStringInput("\n~~~~~~~~~~~~~~~~~~~\n\nDealer's Current Hand: \n\nMYSTERY-CARD || " + formatHand(dealer.getDealerHand()) + "\n\nDealer's Hand Value: ??" +
32 25
                 "\n\n~~~~~~~~~~~~~~~~~~~\n\nYour Current Hand: \n\n" + formatHand(blackJackPlayer.getPlayerHand()) + "\n\nYour Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJackPlayer)) +
33
-                "\n\n~~~~~~~~~~~~~~~~~~~\n\nYOUR TURN" + "\n\n~~~~~~~~~~~~~~~~~~~\n\nWhat do you want to do?\n<< Hit - Stand - Double Down - Split - Quit >>").toUpperCase();
26
+                "\n\n~~~~~~~~~~~~~~~~~~~\n\nYOUR TURN" + "\n\n~~~~~~~~~~~~~~~~~~~\n\nWhat do you want to do?\n\n<< Hit - Stand - Double Down - Split - Quit >>").toUpperCase();
34 27
         return response;
35 28
     }
36 29
 
37
-    public static void handVSHand(BlackJack blackJack, BlackJackPlayer blackJackPlayer) {
30
+    public static void endGame(BlackJack blackJack, BlackJackPlayer blackJackPlayer, char result) {
38 31
         String name = blackJackPlayer.getPlayer().getName();
39
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDealer's Current Hand: \n\nMYSTERY-CARD || " + formatHand(blackJack.getDealer().getDealerHand()) + "\n\nDealer's Hand Value: ??");
40
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\n" + name + "'s Current Hand: \n\n" + formatHand(blackJackPlayer.getPlayerHand()) + "\n\n" + name + "'s Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJackPlayer)));
32
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDETERMINING WINNER...");
33
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDealer's Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJack.getDealer())));
34
+        System.out.println("\nYour Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJackPlayer)));
35
+        winOrLose(blackJackPlayer, result);
41 36
     }
42 37
 
43
-    public static void endOfGame(BlackJack blackJack, BlackJackPlayer blackJackPlayer, char result) {
44
-        String name = blackJackPlayer.getPlayer().getName();
45
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDETERMINING WINNER...");
46
-        System.out.println("\nDealer's Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJack.getDealer())));
47
-        System.out.println("\n" + name + "'s Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJackPlayer)));
48
-        switch (result) {
49
-            case '+':
50
-                System.out.println("\nYou Won: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
51
-                break;
52
-            case '-':
53
-                System.out.println("\nYou Lost: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
54
-                break;
55
-            default:
56
-                System.out.println("\nTie Game.\n\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
57
-                break;
38
+    public static void winOrLose(BlackJackPlayer blackJackPlayer, char result) {
39
+            switch (result) {
40
+                case '+':
41
+                    System.out.println("\nYou Won: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
42
+                    break;
43
+                case '-':
44
+                    System.out.println("\nYou Lost: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
45
+                    break;
46
+                default:
47
+                    System.out.println("\nTie Game.\n\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
48
+                    break;}
49
+    }
50
+
51
+    public static void hitCard(BlackJackPlayer blackJackPlayer, Card card){
52
+        if (blackJackPlayer.getPlayer().getName().equals("Dealer")) {
53
+            System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDealer Hit: " + card.toString());
54
+            System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDealer's Current Hand: \n\nMYSTERY-CARD || " + formatHand(blackJackPlayer.getDealerHand()) + "\n\nDealer's Hand Value: ??");
55
+        } else {
56
+            System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nYou Hit: " + card.toString());
57
+            // System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nYour Current Hand: \n\n" + formatHand(blackJackPlayer.getPlayerHand()) + "\n\nYour Hand Value: " + formatHandValue(blackJack.countPlayerHand(blackJackPlayer)));
58 58
         }
59 59
     }
60 60
 
61
-    public static void winMoney(BlackJack blackJack, BlackJackPlayer blackJackPlayer) {
61
+    public static void standingStill() {
62
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nStanding still!");
63
+    }
62 64
 
63
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDETERMINING WINNER...");
64
-        System.out.println("\nYou Won: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
65
+    public static void dealerTurn() {
66
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDEALER'S TURN");
65 67
     }
66 68
 
67
-    public static void loseMoney(BlackJack blackJack, BlackJackPlayer blackJackPlayer) {
68
-        handVSHand(blackJack, blackJackPlayer);
69
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDETERMINING WINNER...");
70
-        System.out.println("\nYou Lost: $" + blackJackPlayer.getBetPot() + "\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
69
+    public static void initiateGame(BlackJackPlayer blackJackPlayer) {
70
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nYOUR BET: " + blackJackPlayer.getBetPot());
71
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nGAME START - DEALING CARDS");
71 72
     }
72 73
 
73
-    public static void tieGame(BlackJack blackJack, BlackJackPlayer blackJackPlayer) {
74
-        handVSHand(blackJack, blackJackPlayer);
75
-        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nDETERMINING WINNER...");
76
-        System.out.println("\nTie Game.\n\nCurrent Wallet: $" + blackJackPlayer.getPlayer().getWallet());
74
+    public static String askPlayAgain() {
75
+        return Console.getStringInput("\n~~~~~~~~~~~~~~~~~~~\n\nWould you like to play again?\n\n<< Yes - No >>").toUpperCase();
76
+    }
77
+
78
+    public static void goodByeMessage() {
79
+        System.out.println("\n~~~~~~~~~~~~~~~~~~~\n\nThanks for playing! Now returning to the Casino Lobby.");
77 80
     }
78 81
 
79 82
     public static String formatHand(ArrayList<Card> array) {

+ 17
- 71
src/main/java/io/zipcoder/casino/Casino_test.java Прегледај датотеку

@@ -1,37 +1,29 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
-// BlackJack
4
-// Solitaire
5
-// Craps
6
-// Roulette?
7
-// Slot Machine?
8
-
9
-// Jackpot option? Low chance but player wins $1mil
10
-//
11
-
12 3
 import io.zipcoder.casino.CardGame.BlackJack.BlackJack;
13 4
 import io.zipcoder.casino.CardGame.BlackJack.BlackJackGameplay;
5
+import io.zipcoder.casino.CardGame.BlackJack.Console_BlackJack;
14 6
 import io.zipcoder.casino.DiceGame.Craps.Craps;
15
-import io.zipcoder.casino.CardGame.Solitaire.Solitaire;
16
-import io.zipcoder.casino.Interfaces.Game;
17
-
18
-import java.util.Scanner;
19 7
 
20 8
 public final class Casino_test {
21 9
 
22
-    private final static Casino_test instance = new Casino_test();
10
+//    private final static Casino_test instance = new Casino_test();
23 11
 
24 12
     private Player player;
13
+    private BlackJack blackJack;
14
+    private BlackJackGameplay gamePlay;
25 15
 
26
-    private final String casinoName = "Thunder Theta";
16
+    private String casinoName;
27 17
 
28
-    private Casino_test() {
18
+    public Casino_test(Player player) {
19
+        this.casinoName = "Thunder Theta";
20
+        this.player = player;
21
+        this.blackJack = new BlackJack(player);
22
+        this.gamePlay = new BlackJackGameplay(blackJack);
29 23
     }
30 24
 
31 25
     public void chooseGame() {
32
-        Scanner scanner = new Scanner(System.in);
33
-        System.out.println("\n\nWhat game would you like to play?\n<< BlackJack - Solitaire - Craps - Leave >>");
34
-        String userInput = scanner.nextLine();
26
+        String userInput = Console.getStringInput("\nWhat game would you like to play?\n\n<< BlackJack - Solitaire - Craps - Leave >>");
35 27
         String input = userInput.toUpperCase();
36 28
 
37 29
         boolean flag = true;
@@ -41,11 +33,9 @@ public final class Casino_test {
41 33
                 case "SOLITAIRE":
42 34
                     break;
43 35
                 case "BLACKJACK":
44
-                    BlackJack blackJack = new BlackJack(player);
45
-                    BlackJackGameplay gamePlay = new BlackJackGameplay(blackJack);
46
-                    System.out.println("\nHi " + player.getName() + "! Welcome to BlackJack!\n\nThe minimum bet is $50.\n");
47
-                    flag = false;
36
+                    Console_BlackJack.blackJackWelcome(player);
48 37
                     gamePlay.start(player);
38
+                    flag = false;
49 39
                     break;
50 40
                 case "CRAPS":
51 41
                     Craps craps = new Craps(player);
@@ -53,12 +43,12 @@ public final class Casino_test {
53 43
                     craps.gamePlay();
54 44
                     break;
55 45
                 case "LEAVE":
56
-                    System.out.println("Thanks for coming to Thunder Theta, good bye!");
46
+                    Console_BlackJack.finalGoodbye();
57 47
                     flag = false;
58 48
                     break;
59 49
                 default:
60
-                    System.out.println("I don't know what that game is. Please try again.");
61
-                    instance.chooseGame();
50
+                    Console_BlackJack.inputError();
51
+                    this.chooseGame();
62 52
                     break;
63 53
             }
64 54
         }
@@ -72,52 +62,8 @@ public final class Casino_test {
72 62
         return this.player;
73 63
     }
74 64
 
75
-    public static Casino_test getInstance() {
76
-        return instance;
77
-    }
78
-
79 65
     public String getCasinoName() {
80 66
         return this.casinoName;
81 67
     }
82
-
83
-    public static void main(String[] args) {
84
-        Scanner scanner = new Scanner(System.in);
85
-        Casino_test instance = Casino_test.getInstance();
86
-        System.out.println("Welcome to " + instance.getCasinoName() + "! What is your name?");
87
-        String playerName = scanner.nextLine();
88
-        Player player = new Player(playerName);
89
-        instance.setPlayer(player);
90
-        instance.chooseGame();
91
-    }
92
-
93
-//    private int money;
94
-//    private String casinoName;
95
-//    private Game game;
96
-//    private Player player;
97
-//    private String currentGame;
98
-//
99
-//    public void selectGame(int gameNum) {
100
-//
101
-//        switch (gameNum) {
102
-//            case 1:
103
-//                Game blackJack = new BlackJack(player);
104
-//                break;
105
-//            case 2:
106
-//                Game solitaire = new Solitaire(player);
107
-//                break;
108
-//            case 3:
109
-//                Game craps = new Craps(player);
110
-//                break;
111
-//            case 4:
112
-//                leaveCasino();
113
-//                break;
114
-//            default:
115
-//                System.out.println("Input unknown, please pick again.");
116
-//                break;
117
-//        }
118
-//    }
119
-//
120
-//    public void leaveCasino() {
121
-//    }
122
-
123 68
 }
69
+

+ 10
- 0
src/main/java/io/zipcoder/casino/Main.java Прегледај датотеку

@@ -0,0 +1,10 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Main {
4
+    public static void main(String[] args) {
5
+        String playerName = Console.getStringInput("\n\nWelcome to the Casino Lobby! What is your name?");
6
+        Player player = new Player(playerName);
7
+        Casino_test casino = new Casino_test(player);
8
+        casino.chooseGame();
9
+    }
10
+}

+ 70
- 10
src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackJackTest.java Прегледај датотеку

@@ -9,7 +9,6 @@ import org.junit.Assert;
9 9
 import org.junit.Test;
10 10
 
11 11
 import java.util.ArrayList;
12
-import java.util.Scanner;
13 12
 
14 13
 public class BlackJackTest {
15 14
 
@@ -243,11 +242,10 @@ public class BlackJackTest {
243 242
 //    public void testAskForBet(){
244 243
 //        gamePlay.askForBet(testPlayer);
245 244
 //
246
-//        int expected = 100;
245
+//        int expected = 50;
247 246
 //        int actual = testPlayer.getBetPot();
248 247
 //
249 248
 //        Assert.assertEquals(expected, actual);
250
-//
251 249
 //    }
252 250
 
253 251
     @Test
@@ -303,14 +301,76 @@ public class BlackJackTest {
303 301
     }
304 302
 
305 303
     @Test
306
-    public void testIfPlayerActive() {
307
-        testHand.add(deck.draw());
308
-        testHand.add(deck.draw());
309
-        testHand.add(deck.draw());
310
-        System.out.println(testPlayer.getPlayerHand());
304
+    public void testTwoStands_PlayerWin(){
305
+        testPlayer.setHandValue(20);
306
+        blackJack.getDealer().setHandValue(17);
307
+        testPlayer.setBetPot(50);
308
+        gamePlay.twoStands(testPlayer);
311 309
 
312
-        gamePlay.setActivePlayer(testPlayer);
313
-        gamePlay.ifPlayerActive(testPlayer);
310
+        int expected = 550;
311
+        int actual = testPlayer.getPlayer().getWallet();
314 312
 
313
+        Assert.assertEquals(expected, actual);
315 314
     }
315
+
316
+    @Test
317
+    public void testTwoStands_PlayerLoss(){
318
+        testPlayer.setHandValue(17);
319
+        blackJack.getDealer().setHandValue(20);
320
+        testPlayer.setBetPot(50);
321
+        gamePlay.twoStands(testPlayer);
322
+
323
+        int expected = 450;
324
+        int actual = testPlayer.getPlayer().getWallet();
325
+
326
+        Assert.assertEquals(expected, actual);
327
+    }
328
+
329
+    @Test
330
+    public void testDealerTurn(){
331
+        blackJack.getDealer().setHandValue(20);
332
+        gamePlay.dealerTurn();
333
+
334
+        int expected = 1;
335
+        int actual = gamePlay.getStands();
336
+
337
+        Assert.assertEquals(expected, actual);
338
+    }
339
+
340
+    @Test
341
+    public void testDealerTurn2(){
342
+        gamePlay.dealerTurn();
343
+        gamePlay.dealerTurn();
344
+
345
+        int expected = 2;
346
+        int actual = gamePlay.getStands();
347
+
348
+        Assert.assertEquals(expected, actual);
349
+    }
350
+
351
+    @Test
352
+    public void testDealerTurn_Turn(){
353
+        gamePlay.setTurnNumber(5);
354
+
355
+        gamePlay.dealerTurn();
356
+
357
+        int expected = 6;
358
+        int actual = gamePlay.getTurnNumber();
359
+
360
+        Assert.assertEquals(expected, actual);
361
+    }
362
+
363
+
364
+//    @Test
365
+//    public void testDealerTurn_Turn(){
366
+//        gamePlay.setTurnNumber(5);
367
+//
368
+//        gamePlay.dealerTurn();
369
+//
370
+//        int expected = 6;
371
+//        int actual = gamePlay.getTurnNumber();
372
+//
373
+//        Assert.assertEquals(expected, actual);
374
+//    }
375
+
316 376
 }