Bladeren bron

Merge conflict resolution

Lauren Green 6 jaren geleden
bovenliggende
commit
a538db9398

+ 14
- 2
src/main/java/io/zipcoder/casino/Casino.java Bestand weergeven

@@ -42,7 +42,7 @@ public class Casino {
42 42
     {
43 43
         while(running) {
44 44
 
45
-            Printer.pickGameMsg();
45
+            Printer.printMessage("Please choose a game to play!");
46 46
             Printer.printMessage(getGameListing());
47 47
 
48 48
             int command = console.getIntFromUser("Please choose a game to play by entering the number next to the game.");
@@ -53,6 +53,7 @@ public class Casino {
53 53
                     Game war = new War(10);
54 54
                     ((War) war).addPlayers(player);
55 55
                     ((War) war).addNpc();
56
+                    game = war;
56 57
                     war.startGame();
57 58
                     break;
58 59
 
@@ -60,6 +61,7 @@ public class Casino {
60 61
                     Game stud = new Stud(10);
61 62
                     ((Stud) stud).addPlayers(player);
62 63
                     ((Stud) stud).addNpc();
64
+                    game = stud;
63 65
                     stud.startGame();
64 66
                     break;
65 67
 
@@ -67,6 +69,7 @@ public class Casino {
67 69
                     int slotBet1= console.getIntFromUser("Enter the amount you want to bet on Slot");
68 70
                     Game slot= new SlotMachine(slotBet1);
69 71
                     slot.startGame();
72
+                    game = slot;
70 73
                     ((SlotMachine) slot).payout();
71 74
                     break;
72 75
 
@@ -76,6 +79,7 @@ public class Casino {
76 79
                     int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
77 80
                     ((Yahtzee) yahtzee).setBid(betAmount);
78 81
                     ((Yahtzee) yahtzee).bet(betAmount);
82
+                    game = yahtzee;
79 83
                     yahtzee.startRound();
80 84
                     Printer.printMessage("You scored " + ((Yahtzee) yahtzee).getDicePlayer().getScoreSheet().getTotalScore() + " points.");
81 85
                     ((Yahtzee) yahtzee).payout();
@@ -84,7 +88,7 @@ public class Casino {
84 88
 
85 89
                 case 5:
86 90
                     running = false;
87
-                    Printer.closeGameMsg();
91
+                    Printer.printMessage("Thanks for the money chump!");
88 92
                     break;
89 93
 
90 94
                 default:
@@ -120,4 +124,12 @@ public class Casino {
120 124
     public void setPlayer(Player player) {
121 125
         this.player = player;
122 126
     }
127
+
128
+    public ArrayList<String> getGameLib() {
129
+        return gameLib;
130
+    }
131
+
132
+    public Game getGame() {
133
+        return game;
134
+    }
123 135
 }

+ 10
- 1
src/main/java/io/zipcoder/casino/Console.java Bestand weergeven

@@ -4,6 +4,7 @@ import java.util.InputMismatchException;
4 4
 import java.util.Scanner;
5 5
 
6 6
 public class Console {
7
+
7 8
     private Scanner scanner = new Scanner(System.in);
8 9
 
9 10
     Console(){
@@ -23,7 +24,7 @@ public class Console {
23 24
             int num = scanner.nextInt();
24 25
             return num;
25 26
         }catch(InputMismatchException err){
26
-            Printer.pleaseEnterNum();
27
+            Printer.printMessage("Please enter a number.");
27 28
             scanner.next();
28 29
         }
29 30
         return -1;
@@ -42,4 +43,12 @@ public class Console {
42 43
         input.toLowerCase().trim();
43 44
         return input;
44 45
     }
46
+
47
+    public void setScanner(Scanner scanner) {
48
+        this.scanner = scanner;
49
+    }
50
+
51
+    public Scanner getScanner() {
52
+        return scanner;
53
+    }
45 54
 }

+ 0
- 28
src/main/java/io/zipcoder/casino/Printer.java Bestand weergeven

@@ -19,32 +19,4 @@ public class Printer {
19 19
 
20 20
         printMessage("Sorry, there is no game with that name, try one of: " + games);
21 21
     }
22
-
23
-    public static void showCard(Player player, Card card){
24
-        printMessage(player.getName() + " shows a " + card.getName());
25
-    }
26
-
27
-    public static void pickGameMsg(){
28
-        printMessage("Please choose a game to play!");
29
-    }
30
-
31
-    public static void closeGameMsg(){
32
-        printMessage("Thanks for your money chump!");
33
-    }
34
-
35
-    public static void pleaseEnterNum(){
36
-        printMessage("Please enter a number");
37
-    }
38
-    
39
-    public static void welcomeTo(String gameName){
40
-        printMessage("Welcome to " + gameName + "!");
41
-    }
42
-
43
-    public static void printWarTurnResult(String name, String cardName, int handSize){
44
-        printMessage(name + " has played " + cardName + " and has " + handSize + " cards left.");
45
-    }
46
-
47
-    public static void playedFaceDown(String name){
48
-        printMessage(name + " has played a card face down.");
49
-    }
50 22
 }

+ 1
- 1
src/main/java/io/zipcoder/casino/Stud.java Bestand weergeven

@@ -13,7 +13,7 @@ public class Stud extends CardGame implements Gamble, Game {
13 13
     
14 14
     public void playCard(Player player, Card card) {
15 15
         card.setVisibility(true);               //CARD isVISIBLE
16
-        Printer.showCard(player, card);         //PRINT card name to CONSOLE
16
+        Printer.printMessage(player.getName() + " shows a " + card.getName());         //PRINT card name to CONSOLE
17 17
     }
18 18
 
19 19
 

+ 5
- 5
src/main/java/io/zipcoder/casino/War.java Bestand weergeven

@@ -29,9 +29,9 @@ public class War extends CardGame implements Gamble, Game {
29 29
     public void playCardInHand(boolean cardFace){
30 30
         Card card = getCardFromHand(cardFace);
31 31
         if(cardFace) {
32
-            Printer.printWarTurnResult(super.getPlayersTurn().getPlayer().getName(), card.getName(), super.getPlayersTurn().getHand().size());
32
+            Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " has played a " + card.getName() + " and has " + super.getPlayersTurn().getHand().size() + " cards left.");
33 33
         } else {
34
-            Printer.playedFaceDown(super.getPlayersTurn().getPlayer().getName());
34
+            Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " has played a card face down.");
35 35
         }
36 36
     }
37 37
 
@@ -114,9 +114,9 @@ public class War extends CardGame implements Gamble, Game {
114 114
         }
115 115
     }
116 116
 
117
-    @Override
118
-    public void startGame() {
119
-        Printer.welcomeTo("War");
117
+
118
+    public void startGame(){
119
+        Printer.printMessage("Welcome to War!");
120 120
         super.chooseStatingPlayer();
121 121
         payAnte();
122 122
         deal();

+ 37
- 0
src/test/java/io/zipcoder/casino/ConsoleTest.java Bestand weergeven

@@ -0,0 +1,37 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+import java.io.ByteArrayInputStream;
6
+import java.io.InputStream;
7
+import java.nio.ByteBuffer;
8
+import java.util.*;
9
+
10
+public class ConsoleTest {
11
+
12
+    @Test
13
+    public void testCreateAccont()
14
+    {
15
+        Console console = new Console();
16
+        String name = "Jon \n";
17
+        Integer balance = 100;
18
+        ByteBuffer b = ByteBuffer.allocate(balance);
19
+        byte[] result = b.array();
20
+
21
+
22
+        byte[] one = result;
23
+        byte[] two = name.getBytes();
24
+        byte[] combined = new byte[one.length + two.length];
25
+
26
+        System.arraycopy(one,0,combined,0,one.length);
27
+        System.arraycopy(two,0,combined,one.length,two.length);
28
+
29
+
30
+        String data = "Jon" + "\nA second line of user input.";
31
+        System.setIn(new ByteArrayInputStream(combined));
32
+
33
+        console.setScanner(new Scanner(new ByteArrayInputStream(combined)));
34
+
35
+    }
36
+
37
+}

+ 27
- 0
src/test/java/io/zipcoder/casino/PrinterTest.java Bestand weergeven

@@ -0,0 +1,27 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.io.BufferedInputStream;
7
+import java.io.ByteArrayInputStream;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
11
+public class PrinterTest {
12
+
13
+    @Test
14
+    public void testWrongGameEntered(){
15
+        Casino casino = new Casino();
16
+        Console console = new Console();
17
+
18
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream("6".getBytes())));
19
+        try {
20
+            casino.chooseGame();
21
+        }catch(NoSuchElementException e){
22
+
23
+        }
24
+
25
+        Assert.assertEquals(null, casino.getGame());
26
+    }
27
+}

+ 31
- 0
src/test/java/io/zipcoder/casino/WarTest.java Bestand weergeven

@@ -1,12 +1,43 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import org.junit.Assert;
3 4
 import org.junit.Test;
4 5
 
5 6
 public class WarTest {
6 7
 
7 8
     @Test
8 9
     public void warTest01(){
10
+        War war = new War(10);
11
+        war.addNpc();
12
+        war.addNpc();
9 13
 
14
+        Assert.assertEquals(2, war.getPlayers().size());
15
+    }
16
+
17
+    @Test
18
+    public void playCardPileTest(){
19
+        Deck deck = new Deck();
20
+        War war = new War(10);
21
+        Player player = new Player("Jon", 100);
22
+        war.addPlayers(player);
23
+        war.chooseStatingPlayer();
24
+        war.deal();
25
+        war.getPlayers().get(0).setDiscard(deck);
26
+
27
+        war.playCardFromPile(false);
28
+
29
+        Assert.assertEquals(103, war.getPlayers().get(0).getHand().size());
30
+    }
31
+
32
+    @Test
33
+    public void playCardTest() {
34
+        War war = new War(10);
35
+        Player player = new Player("Jon", 100);
36
+        war.addPlayers(player);
37
+        war.chooseStatingPlayer();
38
+        war.playCard(false);
39
+
40
+        Assert.assertEquals(war.getLoser(), player);
10 41
     }
11 42
 
12 43
 }