Brandon Defrancis 6 lat temu
rodzic
commit
d0c7878434
43 zmienionych plików z 3241 dodań i 7 usunięć
  1. BIN
      .DS_Store
  2. 1
    1
      README.md
  3. 22
    0
      pom.xml
  4. BIN
      src/.DS_Store
  5. BIN
      src/main/.DS_Store
  6. BIN
      src/main/java/.DS_Store
  7. BIN
      src/main/java/io/.DS_Store
  8. BIN
      src/main/java/io/zipcoder/.DS_Store
  9. BIN
      src/main/java/io/zipcoder/casino/.DS_Store
  10. 115
    1
      src/main/java/io/zipcoder/casino/Casino.java
  11. 73
    0
      src/main/java/io/zipcoder/casino/Console.java
  12. 25
    0
      src/main/java/io/zipcoder/casino/GoFishPlay.java
  13. 11
    0
      src/main/java/io/zipcoder/casino/Main.java
  14. 51
    0
      src/main/java/io/zipcoder/casino/game/Player.java
  15. 48
    0
      src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Card.java
  16. 41
    0
      src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Deck.java
  17. 48
    0
      src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Rank.java
  18. 9
    0
      src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Suit.java
  19. 233
    0
      src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/BlackJack.java
  20. 61
    0
      src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/CardGame.java
  21. 6
    0
      src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/CardPlayer.java
  22. 523
    0
      src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/GoFish.java
  23. 283
    0
      src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/HiLo.java
  24. 184
    0
      src/main/java/io/zipcoder/casino/game/chancegames/Roulette.java
  25. 88
    0
      src/main/java/io/zipcoder/casino/game/chancegames/Slots.java
  26. 16
    0
      src/main/java/io/zipcoder/casino/game/chancegames/chancegameutilities/RandomNumGen.java
  27. 64
    0
      src/main/java/io/zipcoder/casino/game/chancegames/chancegameutilities/RouletteWheel.java
  28. 32
    0
      src/main/java/io/zipcoder/casino/game/dicegames/diceutilities/Dice.java
  29. 16
    0
      src/main/java/io/zipcoder/casino/game/dicegames/diceutilities/RandomDice.java
  30. 165
    0
      src/main/java/io/zipcoder/casino/game/dicegames/individualdicegames/Craps.java
  31. 10
    0
      src/main/java/io/zipcoder/casino/game/dicegames/individualdicegames/DiceGame.java
  32. 17
    0
      src/main/java/io/zipcoder/casino/game/interfaces/Gamble.java
  33. 7
    0
      src/main/java/io/zipcoder/casino/game/interfaces/Game.java
  34. 262
    0
      src/test/java/io/zipcoder/casino/BlackJackTest.java
  35. 0
    5
      src/test/java/io/zipcoder/casino/CasinoTest.java
  36. 167
    0
      src/test/java/io/zipcoder/casino/CrapsTest.java
  37. 22
    0
      src/test/java/io/zipcoder/casino/DiceTest.java
  38. 53
    0
      src/test/java/io/zipcoder/casino/PlayerTest.java
  39. 28
    0
      src/test/java/io/zipcoder/casino/RandomNumGenTest.java
  40. 179
    0
      src/test/java/io/zipcoder/casino/RouletteTest.java
  41. 36
    0
      src/test/java/io/zipcoder/casino/RouletteWheelTest.java
  42. 91
    0
      src/test/java/io/zipcoder/casino/SlotsTest.java
  43. 254
    0
      src/test/java/io/zipcoder/casino/game/cardgames/individualcardgames/GoFishTest.java

BIN
.DS_Store Wyświetl plik


+ 1
- 1
README.md Wyświetl plik

@@ -24,4 +24,4 @@
24 24
 * `BlackJack` and `GoFish` are both Card Games and should therefore inherit from a common `CardGame`.
25 25
 * Any common logic or fields between the games should live CardGame class, **not** BlackJack **nor** GoFish.
26 26
 * You must have a completed and approved UML diagram before you proceed to do any development
27
-* All public methods should be tested.
27
+* All public methods should be tested

+ 22
- 0
pom.xml Wyświetl plik

@@ -7,12 +7,34 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>casino</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>
13 25
             <groupId>junit</groupId>
14 26
             <artifactId>junit</artifactId>
15 27
             <version>4.12</version>
28
+        </dependency>
29
+        <dependency>
30
+            <groupId>com.github.stefanbirkner</groupId>
31
+            <artifactId>system-rules</artifactId>
32
+            <version>1.18.0</version>
33
+        </dependency>
34
+        <dependency>
35
+            <groupId>junit</groupId>
36
+            <artifactId>junit</artifactId>
37
+            <version>RELEASE</version>
16 38
             <scope>test</scope>
17 39
         </dependency>
18 40
     </dependencies>

BIN
src/.DS_Store Wyświetl plik


BIN
src/main/.DS_Store Wyświetl plik


BIN
src/main/java/.DS_Store Wyświetl plik


BIN
src/main/java/io/.DS_Store Wyświetl plik


BIN
src/main/java/io/zipcoder/.DS_Store Wyświetl plik


BIN
src/main/java/io/zipcoder/casino/.DS_Store Wyświetl plik


+ 115
- 1
src/main/java/io/zipcoder/casino/Casino.java Wyświetl plik

@@ -1,5 +1,119 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import io.zipcoder.casino.game.Player;
4
+import io.zipcoder.casino.game.cardgames.individualcardgames.BlackJack;
5
+import io.zipcoder.casino.game.cardgames.individualcardgames.GoFish;
6
+import io.zipcoder.casino.game.cardgames.individualcardgames.HiLo;
7
+import io.zipcoder.casino.game.chancegames.Roulette;
8
+import io.zipcoder.casino.game.chancegames.Slots;
9
+import io.zipcoder.casino.game.dicegames.individualdicegames.Craps;
10
+import io.zipcoder.casino.game.interfaces.Game;
3 11
 
4 12
 public class Casino {
5
-}
13
+    Player player;
14
+    Game game;
15
+    int choice;
16
+    boolean playFlag;
17
+
18
+    public Casino() {
19
+        player = new Player();
20
+    }
21
+
22
+    public void startCasino() {
23
+
24
+        printWelcome();
25
+        askForName();
26
+        askForBank();
27
+        chooseGame();
28
+    }
29
+
30
+
31
+    public void printWelcome(){
32
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
33
+        Console.print("  /$$$$$$   /$$$$$$   /$$$$$$  /$$$$$$ /$$   /$$  /$$$$$$ \n" +
34
+                " /$$__  $$ /$$__  $$ /$$__  $$|_  $$_/| $$$ | $$ /$$__  $$\n" +
35
+                "| $$  \\__/| $$  \\ $$| $$  \\__/  | $$  | $$$$| $$| $$  \\ $$\n" +
36
+                "| $$      | $$$$$$$$|  $$$$$$   | $$  | $$ $$ $$| $$  | $$\n" +
37
+                "| $$      | $$__  $$ \\____  $$  | $$  | $$  $$$$| $$  | $$\n" +
38
+                "| $$    $$| $$  | $$ /$$  \\ $$  | $$  | $$\\  $$$| $$  | $$\n" +
39
+                "|  $$$$$$/| $$  | $$|  $$$$$$/ /$$$$$$| $$ \\  $$|  $$$$$$/\n" +
40
+                " \\______/ |__/  |__/ \\______/ |______/|__/  \\__/ \\______/");
41
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
42
+        Console.print("Welcome to the Casino");
43
+    }
44
+
45
+    public void askForName() {
46
+        player.setName(Console.printAndTakeString("Enter your name:"));
47
+    }
48
+
49
+    public void printMenu() {
50
+        Console.print("Choose a game! Enter the option number (ex. 1 for Blackjack)"
51
+                + "\nPlayer Bank: "
52
+                + player.getBank()
53
+                + "\n1: Blackjack\n2: Hi Lo\n3: Roulette"
54
+                + "\n4: Craps\n5: Slots\n6: Go Fish\n7: Quit Casino");
55
+    }
56
+
57
+    public void askForBank() {
58
+
59
+        int userBank = Console.printAndTakeInt("Enter the amount you want to start playing with (bank) :");
60
+        if (!player.checkInitialBank(userBank)) {
61
+            Console.print("Didn't quite catch that, here's 10k Zimbabwean dollars to play.");
62
+            player.setBank(10000);
63
+        } else {
64
+            player.setBank(userBank);
65
+        }
66
+    }
67
+
68
+
69
+    private void chooseGame() {
70
+        boolean playGame = true;
71
+        while (playGame) {
72
+            printMenu();
73
+            choice = Console.getIntegerInput();
74
+            switch (choice) {
75
+                case 1:
76
+                    game = new BlackJack(player);
77
+                    game.play();
78
+                    break;
79
+
80
+                case 2:
81
+                    game = new HiLo(player);
82
+                    game.play();
83
+                    break;
84
+
85
+                case 3:
86
+                    game = new Roulette(player);
87
+                    game.play();
88
+                    break;
89
+
90
+                case 4:
91
+                    game = new Craps(player);
92
+                    game.play();
93
+                    break;
94
+
95
+                case 5:
96
+                    game = new Slots(player);
97
+                    game.play();
98
+                    break;
99
+
100
+                case 6:
101
+                    game = new GoFish(player);
102
+                    game.play();
103
+                    break;
104
+
105
+                case 7:
106
+                    System.exit(1);
107
+
108
+                default:
109
+                    Console.print("Incorrect choice. Choose the listed options");
110
+                    continue;
111
+            }
112
+
113
+            Console.print("\n\n\n\n\n♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣\n"
114
+                    + "Welcome back to the Casino Menu!");
115
+            }
116
+        }
117
+    }
118
+
119
+

+ 73
- 0
src/main/java/io/zipcoder/casino/Console.java Wyświetl plik

@@ -0,0 +1,73 @@
1
+package io.zipcoder.casino;
2
+
3
+import sun.awt.image.IntegerInterleavedRaster;
4
+
5
+import java.io.IOException;
6
+import java.util.Scanner;
7
+
8
+public class Console {
9
+
10
+    private static Scanner input = new Scanner(System.in);
11
+
12
+    public static void print(String string){
13
+        System.out.println(string);
14
+    }
15
+
16
+    public static void printInSameLine(String string){
17
+        System.out.print(string);
18
+    }
19
+
20
+    public static String printAndTakeString(String s) {
21
+        System.out.println(s);
22
+        return input.next();
23
+    }
24
+
25
+    public static int printAndTakeInt(String s) {
26
+        System.out.println(s);
27
+        return input.nextInt();
28
+    }
29
+
30
+    public static String getStringInput(){
31
+        return input.next();
32
+    }
33
+
34
+    public static Integer getIntegerInput(){
35
+        return input.nextInt();
36
+    }
37
+
38
+    public static void print(int slot1, int slot2, int slot3)  {
39
+        System.out.printf("| %d | %d | %d |\n", slot1, slot2, slot3);
40
+    }
41
+
42
+    public static void pause(int t) {
43
+
44
+            try {
45
+                Thread.sleep(t); // In your case it would be: Thread.sleep(100);
46
+            } catch (Exception e) {
47
+                e.printStackTrace();
48
+            }
49
+
50
+    }
51
+
52
+    public static void pause(int t, String s){
53
+
54
+            try {
55
+                Console.printInSameLine(s);
56
+                Thread.sleep(t); // In your case it would be: Thread.sleep(100);
57
+            } catch (Exception e) {
58
+                e.printStackTrace();
59
+            }
60
+
61
+    }
62
+
63
+    public static void pause(int t, String s, int loop) {
64
+        for (int i = 0; i < loop; i++) {
65
+            try {
66
+                Console.printInSameLine(s);
67
+                Thread.sleep(t); // In your case it would be: Thread.sleep(100);
68
+            } catch (Exception e) {
69
+                e.printStackTrace();
70
+            }
71
+        }
72
+    }
73
+}

+ 25
- 0
src/main/java/io/zipcoder/casino/GoFishPlay.java Wyświetl plik

@@ -0,0 +1,25 @@
1
+//package io.zipcoder.casino;
2
+//
3
+//import GoFish;
4
+//import io.zipcoder.casino.game.Player;
5
+//
6
+//public class GoFishPlay {
7
+//
8
+//
9
+//public static void main(String[]args){
10
+//    Player player1 = new Player("Jared", 100);
11
+//    GoFish goFish = new GoFish(player1);
12
+//
13
+//    goFish.play();
14
+//
15
+////    System.out.println(player.getBank());
16
+////
17
+////    player.setBank(player.getBank()+ 200);
18
+////
19
+////    System.out.println("New bank amount: " + player.getBank());
20
+//
21
+//}
22
+//
23
+//    // Fix book logic
24
+//    // test quit
25
+//}

+ 11
- 0
src/main/java/io/zipcoder/casino/Main.java Wyświetl plik

@@ -0,0 +1,11 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Main {
4
+
5
+    public static void main(String[] args) {
6
+
7
+        Casino casino = new Casino();
8
+        casino.startCasino();
9
+
10
+    }
11
+}

+ 51
- 0
src/main/java/io/zipcoder/casino/game/Player.java Wyświetl plik

@@ -0,0 +1,51 @@
1
+package io.zipcoder.casino.game;
2
+
3
+public class Player {
4
+    private String name;
5
+    private Integer bank;
6
+
7
+    public Player() {
8
+        this.name = "Default";
9
+        this.bank = 10000;
10
+    }
11
+    public Player(String name, Integer bank) {
12
+        this.name = name;
13
+        this.bank = bank;
14
+    }
15
+
16
+    public boolean checkbet(int amount) {
17
+        if ((this.getBank() - amount) < 0 || amount < 0 ) {
18
+            return false;
19
+        } else {
20
+            return true;
21
+        }
22
+    }
23
+
24
+    public boolean checkInitialBank(int amount) {
25
+        if (amount < 0) {
26
+            return false;
27
+        }
28
+
29
+        return true;
30
+    }
31
+
32
+    public String getName() {
33
+        return name;
34
+    }
35
+
36
+    public void setName(String name) {
37
+        this.name = name;
38
+    }
39
+
40
+    public Integer getBank() {
41
+        return bank;
42
+    }
43
+
44
+    public void setBank(Integer bank) {
45
+        this.bank = bank;
46
+    }
47
+    public String getState(){
48
+        return String.format("Highroller %s has $%,d", name, bank);
49
+    }
50
+}
51
+

+ 48
- 0
src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Card.java Wyświetl plik

@@ -0,0 +1,48 @@
1
+package io.zipcoder.casino.game.cardgames.cardutilities;
2
+
3
+public class Card {
4
+
5
+
6
+        public Card(Suit suit, Rank value) {
7
+            this.suit = suit;
8
+            this.value = value;
9
+        }
10
+
11
+        private Suit suit;
12
+        private Rank value;
13
+
14
+
15
+        public Suit getSuit() {
16
+            return suit;
17
+        }
18
+
19
+        public void setSuit(Suit suit) {
20
+            this.suit = suit;
21
+        }
22
+
23
+        public Rank getValue() {
24
+            return value;
25
+        }
26
+
27
+        public void setValue(Rank value) {
28
+            this.value = value;
29
+        }
30
+
31
+        @Override
32
+        public String toString (){
33
+            String s = value + " of " + suit;
34
+            return s;
35
+        }
36
+
37
+
38
+        public int getSecondaryVal(Card c) {
39
+            return c.getValue().getSecondaryvalue();
40
+        }
41
+    }
42
+
43
+
44
+
45
+
46
+
47
+
48
+

+ 41
- 0
src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Deck.java Wyświetl plik

@@ -0,0 +1,41 @@
1
+package io.zipcoder.casino.game.cardgames.cardutilities;
2
+
3
+import java.util.Collections;
4
+import java.util.Stack;
5
+
6
+public class Deck {
7
+
8
+    private Stack<Card> deck;
9
+
10
+    public Deck() {
11
+        refreshDeck();
12
+        deck = shuffleDeck();
13
+    }
14
+
15
+    public Stack<Card> getDeck() {
16
+        return deck;
17
+    }
18
+
19
+    public Stack<Card> shuffleDeck() {
20
+        Collections.shuffle(deck);
21
+        return deck;
22
+    }
23
+
24
+    public Card dealCard() {
25
+        return deck.pop();
26
+    }
27
+
28
+    public void refreshDeck() {
29
+
30
+        Stack<Card> newDeck = new Stack<>();
31
+        for (Rank r : Rank.values()) {
32
+            for (Suit s : Suit.values()) {
33
+                Card temp = new Card(s, r);
34
+                newDeck.push(temp);
35
+            }
36
+        }
37
+
38
+        this.deck = newDeck;
39
+
40
+    }
41
+}

+ 48
- 0
src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Rank.java Wyświetl plik

@@ -0,0 +1,48 @@
1
+package io.zipcoder.casino.game.cardgames.cardutilities;
2
+
3
+public enum Rank {
4
+    Ace(1, 11, "ace"),
5
+    Two(2, 2, "two"),
6
+    Three(3, 3, "three"),
7
+    Four(4, 4, "four"),
8
+    Five(5, 5, "five"),
9
+    Six(6, 6, "six"),
10
+    Seven(7, 7, "seven"),
11
+    Eight(8, 8, "eight"),
12
+    Nine(9, 9, "nine"),
13
+    Ten(10, 10, "ten"),
14
+    Jack(11, 10, "jack"),
15
+    Queen(12, 10, "queen"),
16
+    King(13, 10, "king");
17
+
18
+    Rank(int value, int secondaryvalue, String thirdvalue) {
19
+        this.value = value;
20
+        this.secondaryvalue = secondaryvalue;
21
+        this.thirdvalue = thirdvalue;
22
+    }
23
+
24
+
25
+    Rank(int value, int secondaryvalue) {
26
+        this.value = value;
27
+        this.secondaryvalue = secondaryvalue;
28
+    }
29
+
30
+    private int value;
31
+
32
+    private int secondaryvalue;
33
+
34
+    public int getSecondaryvalue() {
35
+        return secondaryvalue;
36
+    }
37
+
38
+    public String getThirdvalue() {
39
+        return thirdvalue;
40
+    }
41
+
42
+    public String thirdvalue;
43
+
44
+    public int getValue() {
45
+        return value;
46
+    }
47
+
48
+}

+ 9
- 0
src/main/java/io/zipcoder/casino/game/cardgames/cardutilities/Suit.java Wyświetl plik

@@ -0,0 +1,9 @@
1
+package io.zipcoder.casino.game.cardgames.cardutilities;
2
+
3
+public enum Suit  {
4
+
5
+    Spades, Hearts, Diamonds, Clubs
6
+
7
+}
8
+
9
+

+ 233
- 0
src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/BlackJack.java Wyświetl plik

@@ -0,0 +1,233 @@
1
+package io.zipcoder.casino.game.cardgames.individualcardgames;
2
+
3
+
4
+import io.zipcoder.casino.Console;
5
+import io.zipcoder.casino.game.Player;
6
+import io.zipcoder.casino.game.cardgames.cardutilities.Card;
7
+import io.zipcoder.casino.game.interfaces.Gamble;
8
+
9
+import java.util.*;
10
+
11
+public class BlackJack extends CardGame implements Gamble {
12
+    private Player player;
13
+    public Integer playerTotal = 0;
14
+    public Integer houseTotal = 0;
15
+    public boolean nothaRound = true;
16
+    public boolean hitCheck = true;
17
+    public BlackJack(Player player) {
18
+        this.player = player;
19
+    }
20
+
21
+    public int bet(int betVal){
22
+        return betVal;
23
+    }
24
+
25
+    @Override
26
+    public void play() {
27
+        while (nothaRound) {
28
+            Console.print(intro());
29
+            int stakes = Console.printAndTakeInt("How much money would you like to bet " + player.getName());
30
+            if(!player.checkbet(stakes)){
31
+                Console.print("You don't have enough money get outa here!!!!");
32
+                break;
33
+            }
34
+            dealHand(2);
35
+            handSum();
36
+            firstShow();
37
+            if (playerTotal == 21) {
38
+                doBlackjack(stakes);
39
+            } else {
40
+                hitOrStand(getResponse(), stakes);
41
+            }
42
+            int round = Console.printAndTakeInt("Wanna play another round? ( 1 / 0 )");
43
+            if(round == 0) {
44
+                clearHands();
45
+                nothaRound = false;
46
+            }else{
47
+                hitCheck = true;
48
+                clearHands();
49
+            }
50
+        }
51
+    }
52
+    public void clearHands(){
53
+        getPlayerHand().clear();
54
+        getHouseHand().clear();
55
+        playerTotal = 0;
56
+        houseTotal = 0;
57
+    }
58
+
59
+    public String intro(){
60
+        return "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣\n +" +
61
+                "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦ WELCOME TO BLACKJACK ♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♠♥♦♣\n" +
62
+                "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣\n";
63
+    }
64
+
65
+    public void hitOrStand(String s, int stakes){
66
+            switch (s.toLowerCase()) {
67
+                case "hit": {
68
+                    while(hitCheck) {
69
+                        dealSumFirstShow();
70
+                        if(playerTotal >= 21){
71
+                            break;
72
+                        }
73
+                        String answer = getResponse().toLowerCase();
74
+                        if(answer.equals("stand")){
75
+                            break;
76
+                        }
77
+                        hitOrStand(answer,stakes);
78
+                    }
79
+                }
80
+                case "stand": {
81
+                    if (playerTotal <= 21) {
82
+                        printState();
83
+                        if (houseTotal < 17) {
84
+                            dealHouse();
85
+                            winConditions(stakes);
86
+                            break;
87
+                        }
88
+                    }
89
+                    winConditions(stakes);
90
+                    break;
91
+                }
92
+            }
93
+    }
94
+    public boolean dealHouse(){
95
+        boolean dealtHouse = false;
96
+        int count = 0;
97
+        while (count < 4 && houseTotal < 17) {
98
+            dealSumPrint();
99
+            if (houseTotal > 21) {
100
+                break;
101
+            }
102
+            count++;
103
+        }
104
+        dealtHouse = true;
105
+        return dealtHouse;
106
+    }
107
+    public boolean dealSumPrint(){
108
+        boolean isSumDealt = false;
109
+        getHouseHand().add(deck.dealCard());
110
+        houseTotal = sum(getHouseHand());
111
+        printState();
112
+        isSumDealt = true;
113
+        return isSumDealt;
114
+    }
115
+
116
+    public boolean dealSumFirstShow(){
117
+        boolean isSumDealt = false;
118
+        getPlayerHand().add(deck.dealCard());
119
+        playerTotal = sum(getPlayerHand());
120
+        firstShow();
121
+        isSumDealt = true;
122
+        return isSumDealt;
123
+    }
124
+
125
+    public String getResponse(){
126
+        Console.print("Hit or Stand");
127
+        return Console.getStringInput();
128
+    }
129
+    public void handSum(){
130
+        playerTotal += sum(getPlayerHand());
131
+        houseTotal += sum(getHouseHand());
132
+    }
133
+    public void doBlackjack(int stakes){
134
+        Console.print("Hot Dog the PLAYER got Blackjack");
135
+        stakes = (int) (1.5 * stakes);
136
+        win(player, stakes);
137
+        Console.print(player.getState());
138
+    }
139
+    public void winConditions(int stakes){
140
+        if(playerTotal > 21){
141
+            Console.print("HOUSE WINS");
142
+            Console.print("PLAYER BUSTS");
143
+            printState();
144
+            loss(player, stakes);
145
+            Console.print(player.getState());
146
+            hitCheck = false;
147
+        }
148
+        else if(houseTotal > 21){
149
+            Console.print("PLAYER WINS");
150
+            Console.print("HOUSE BUSTS");
151
+            printState();
152
+            win(player,stakes);
153
+            Console.print(player.getState());
154
+            hitCheck = false;
155
+        }
156
+        else if(houseTotal > playerTotal){
157
+            Console.print("HOUSE WINS");
158
+            printState();
159
+            loss(player, stakes);
160
+            Console.print(player.getState());
161
+            hitCheck = false;
162
+        }
163
+        else if(houseTotal < playerTotal){
164
+            Console.print("PLAYER WINS");
165
+            printState();
166
+            win(player,stakes);
167
+            Console.print(player.getState());
168
+            hitCheck = false;
169
+        }
170
+        else if(houseTotal.equals(playerTotal)){
171
+            Console.print("PUSH");
172
+            printState();
173
+            win(player,0);
174
+            Console.print(player.getState());
175
+            hitCheck = false;
176
+        }
177
+    }
178
+
179
+    public boolean firstShow(){
180
+        boolean firstShown = true;
181
+        Console.pause(500);
182
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
183
+        Console.pause(500);
184
+        Console.print("PLAYER: " + getPlayerHand());
185
+        Console.pause(500);
186
+        Console.print("PLAYER: " + playerTotal + "\n");
187
+        Console.pause(500);
188
+        Console.print("HOUSE: [" +  getHouseHand().get(0) + ", ***** of *****]");
189
+        Console.pause(500);
190
+        Console.print("HOUSE: " +  getHouseHand().get(0).getSecondaryVal(getHouseHand().get(0)));
191
+        Console.pause(500);
192
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
193
+        Console.pause(1000);
194
+        return firstShown;
195
+    }
196
+
197
+    public void printState(){
198
+        Console.pause(500);
199
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
200
+        Console.pause(500);
201
+        Console.print("PLAYER: " + getPlayerHand());
202
+        Console.pause(500);
203
+        Console.print("PLAYER: " + playerTotal + "\n");
204
+        Console.pause(500);
205
+        Console.print("HOUSE: " + getHouseHand());
206
+        Console.pause(500);
207
+        Console.print("HOUSE: " + houseTotal);
208
+        Console.pause(500);
209
+        Console.print("♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣");
210
+        Console.pause(1000);
211
+    }
212
+    public int sum(ArrayList<Card> hand) {
213
+        Integer count = 0;
214
+        boolean aceFound = false;
215
+
216
+        for(Card crd : hand){
217
+            count += crd.getValue().getSecondaryvalue();
218
+            if(crd.getValue().getSecondaryvalue() == 11 && !aceFound){
219
+                if(count > 21){
220
+                    count -= 10;
221
+                    aceFound = true;
222
+                }
223
+            }
224
+        }
225
+        return count;
226
+    }
227
+
228
+    @Override
229
+    public boolean endGame(){
230
+        return false;
231
+    }
232
+
233
+}

+ 61
- 0
src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/CardGame.java Wyświetl plik

@@ -0,0 +1,61 @@
1
+package io.zipcoder.casino.game.cardgames.individualcardgames;
2
+import io.zipcoder.casino.game.cardgames.cardutilities.Card;
3
+import io.zipcoder.casino.game.cardgames.cardutilities.Deck;
4
+import io.zipcoder.casino.game.interfaces.Game;
5
+
6
+import java.util.ArrayList;
7
+
8
+public abstract class CardGame implements Game {
9
+
10
+
11
+    Deck deck;
12
+    private ArrayList<Card> playerHand;
13
+    private ArrayList<Card> houseHand;
14
+
15
+    public void setPlayerHand(ArrayList<Card> playerHand) {
16
+        this.playerHand = playerHand;
17
+    }
18
+
19
+    public void setHouseHand(ArrayList<Card> houseHand) {
20
+        this.houseHand = houseHand;
21
+    }
22
+
23
+    public CardGame() {
24
+        deck = new Deck();
25
+        playerHand = new ArrayList<Card>();
26
+        houseHand = new ArrayList<Card>();
27
+
28
+    }
29
+
30
+    public void dealHand(int howManyCards) {
31
+
32
+        for (int i = 0; i < howManyCards; i++) {
33
+            playerHand.add(deck.dealCard());
34
+            houseHand.add(deck.dealCard());
35
+        }
36
+
37
+    }
38
+
39
+    public Integer sumPlayer(){
40
+        Integer count = 0;
41
+        for (int i = 0; i < playerHand.size(); i ++){
42
+            count+= playerHand.get(i).getValue().getSecondaryvalue();
43
+            if(count > 21 && playerHand.contains("Ace")){
44
+                count -= 10;
45
+            }
46
+        }
47
+        return count;
48
+    }
49
+
50
+    public ArrayList<Card> getPlayerHand() {
51
+        return playerHand;
52
+    }
53
+
54
+    public ArrayList<Card> getHouseHand() {
55
+        return houseHand;
56
+    }
57
+
58
+
59
+
60
+}
61
+

+ 6
- 0
src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/CardPlayer.java Wyświetl plik

@@ -0,0 +1,6 @@
1
+package io.zipcoder.casino.game.cardgames.individualcardgames;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+
5
+public class CardPlayer extends Player {
6
+}

+ 523
- 0
src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/GoFish.java Wyświetl plik

@@ -0,0 +1,523 @@
1
+package io.zipcoder.casino.game.cardgames.individualcardgames;
2
+import io.zipcoder.casino.Console;
3
+import io.zipcoder.casino.game.Player;
4
+import io.zipcoder.casino.game.cardgames.cardutilities.Card;
5
+import io.zipcoder.casino.game.cardgames.cardutilities.Rank;
6
+
7
+import java.util.*;
8
+
9
+public class GoFish extends CardGame {
10
+
11
+    private Player player;
12
+
13
+    private ArrayList<Card> playerHand;
14
+
15
+    private ArrayList<Card> opponentHand;
16
+
17
+    private Card[] playerBookCheck;
18
+    private Card[] opponentBookCheck;
19
+
20
+    private HashMap<String, Integer> allRanks;
21
+
22
+    private boolean endGameCheck;
23
+
24
+    private int playerBook;
25
+    private int opponentBook;
26
+
27
+    private int playerTotalCards;
28
+    private int opponentTotalCards;
29
+
30
+    private int turnOrder;
31
+
32
+    public GoFish(Player player) {
33
+
34
+        this.player = player;
35
+
36
+        playerHand = getPlayerHand();
37
+        opponentHand = getHouseHand();
38
+
39
+        playerBookCheck = new Card[13];
40
+        opponentBookCheck = new Card[13];
41
+
42
+        playerBook = 0;
43
+        opponentBook = 0;
44
+        endGameCheck = false;
45
+
46
+        playerTotalCards = 0;
47
+        opponentTotalCards = 0;
48
+
49
+        turnOrder = randomTurnOrder();
50
+
51
+        allRanks = new HashMap<>();
52
+        for (Rank r: Rank.values()) {
53
+            allRanks.put(r.getThirdvalue(), r.getValue() - 1);
54
+        }
55
+    }
56
+
57
+    public void play() {
58
+
59
+        startOfGame();
60
+        firstBookCheck();
61
+
62
+
63
+        turnOrder = playerGoesFirst();
64
+
65
+        while (!endGameCheck) {
66
+            gameTurnOrder(turnOrder);
67
+        }
68
+
69
+        Console.print("Thanks for playing! \n ... Returning to main menu.");
70
+    }
71
+
72
+    public void gameTurnOrder(int turnOrder) {
73
+        if (turnOrder == 0) {
74
+            playerTurn();
75
+            opponentTurn();
76
+            bookStandings();
77
+
78
+        } else {
79
+            opponentTurn();
80
+            playerTurn();
81
+            bookStandings();
82
+        }
83
+    }
84
+
85
+    public void startOfGame() {
86
+        Console.print("Welcome to go fish, " + player.getName() + "!");
87
+        showRules();
88
+
89
+        startDealHands();
90
+    }
91
+
92
+    public void firstBookCheck() {
93
+        Console.print("Checking dealt hands for books... ");
94
+        Console.pause(250, " . ", 5);
95
+
96
+        updateBookChecker(playerHand, playerBookCheck, true);
97
+        updateBookChecker(opponentHand, opponentBookCheck, false);
98
+
99
+        bookStandings();
100
+
101
+    }
102
+
103
+    public void bookStandings() {
104
+        Console.print("\n\nCurrent book standings!"
105
+                + "\n" + player.getName() + "'s Books: " + getPlayerBook()
106
+                + "\nOpponent's Books: " + getOpponentBook() + "\n\n");
107
+    }
108
+
109
+    public void startDealHands() {
110
+        Console.print("Dealing cards...");
111
+        Console.pause(250, " . ", 5);
112
+        dealHand(7);
113
+        setPlayerTotalCards(7);
114
+        setOpponentTotalCards(7);
115
+    }
116
+
117
+    private void updateBookChecker(ArrayList<Card> hand, Card[] bookCheck, boolean isPlayersTurn) {
118
+        int cardIndex;
119
+        for(Card c: hand) {
120
+            cardIndex = c.getValue().getValue() - 1;
121
+            if (bookCheck[cardIndex] == null) {
122
+                bookCheck[cardIndex] = c;
123
+
124
+            } else {
125
+                String name = player.getName();
126
+                if (!isPlayersTurn) {
127
+                    name = "opponent";
128
+                }
129
+                addBookCountDecreaseCardTotal(isPlayersTurn);
130
+                Console.print("Removing cards " + c.toString() + " and " + bookCheck[cardIndex].toString() + " from " + name + "'s hand.");
131
+                bookCheck[cardIndex] = null;
132
+
133
+            }
134
+        }
135
+    }
136
+
137
+    private int randomTurnOrder() {
138
+        Random random = new Random();
139
+        return random.nextInt(2);
140
+    }
141
+
142
+    private int playerGoesFirst() {
143
+
144
+        Console.print("Determining who goes first...");
145
+        Console.pause(250, " . ", 5);
146
+
147
+        if (this.turnOrder == 0) {
148
+            Console.print("You go first!");
149
+            return 0;
150
+        } else {
151
+            Console.print("Your opponent goes first...");
152
+        }
153
+
154
+        return 1;
155
+    }
156
+
157
+
158
+    public void removeBook(Card[] hand, int newCardIndex) {
159
+        Console.print("Removing " + hand[newCardIndex].getValue().getValue() + "'s.");
160
+        hand[newCardIndex] = null;
161
+    }
162
+
163
+    public void increaseTotalCards(boolean isPlayersTurn) {
164
+        if (isPlayersTurn) {
165
+            incrementPlayersCards();
166
+        } else {
167
+            incrementOpponentCards();
168
+        }
169
+    }
170
+
171
+    public void addBookCountDecreaseCardTotal(boolean isPlayersTurn) {
172
+        if (isPlayersTurn) {
173
+            playerTurnTrue();
174
+        } else {
175
+            opponentTurnTrue();
176
+        }
177
+    }
178
+
179
+    private void goFish(Card[] hand, boolean isPlayersTurn) {
180
+        // put go fish here
181
+        Card newCard = deck.dealCard();
182
+        int newCardIndex = newCard.getValue().getValue() - 1;
183
+
184
+        Console.print("Adding " + newCard.toString() + " to the hand.");
185
+
186
+        if (hand[newCardIndex] != null) {
187
+            removeBook(hand, newCardIndex);
188
+            addBookCountDecreaseCardTotal(isPlayersTurn);
189
+
190
+        } else {
191
+            hand[newCardIndex] = newCard;
192
+            increaseTotalCards(isPlayersTurn);
193
+
194
+        }
195
+    }
196
+
197
+    public boolean endGame() {
198
+        return (deck.getDeck().isEmpty() || playerBook >= 13 || opponentBook >= 13);
199
+    }
200
+
201
+    private boolean checkRank(String s) {
202
+        return allRanks.get(s) != null;
203
+    }
204
+
205
+    private String startPlayerTurn() {
206
+
207
+        String userAsk = Console.printAndTakeString("What card do you want to ask for?");
208
+
209
+        if (!checkRank(userAsk)) {
210
+            userAsk = Console.printAndTakeString("Invalid entry type,"
211
+                + "try typing out the card number/face.. ie. Ace or two\n");
212
+        }
213
+
214
+        return userAsk.toLowerCase();
215
+    }
216
+
217
+    private boolean addAsktoHand(Card[] takeFromThisHand, Card[] addToThisHand , String userAsk, boolean isPlayersTurn) {
218
+
219
+        Card requestedCard = takeFromThisHand[allRanks.get(userAsk)];
220
+
221
+        if (requestedCard != null) {
222
+            Console.print("Found a card! Adding " + requestedCard.toString() + " to hand.");
223
+            takeFromThisHand[allRanks.get(userAsk)] = null;
224
+
225
+            if (addToThisHand[allRanks.get(userAsk)] != null) {
226
+
227
+                Console.print("Removing cards "
228
+                        + requestedCard.toString()
229
+                        + " and "
230
+                        + addToThisHand[allRanks.get(userAsk)].toString()
231
+                        + ".");
232
+
233
+                addToThisHand[allRanks.get(userAsk)] = null;
234
+                addBookCountDecreaseCardTotal(isPlayersTurn);
235
+
236
+            } else {
237
+
238
+                addToThisHand[allRanks.get(userAsk)] = requestedCard;
239
+                increaseTotalCards(isPlayersTurn);
240
+
241
+            }
242
+        }
243
+
244
+        return requestedCard != null;
245
+    }
246
+
247
+
248
+    private void playerTurn() {
249
+
250
+        boolean validCardAsked = false;
251
+
252
+        printSortedHand();
253
+
254
+        if (playerTotalCards == 0) {
255
+            Card newCard = deck.dealCard();
256
+            int newCardIndex = newCard.getValue().getValue() - 1;
257
+            Console.print("Adding " + newCard.toString() + " to the player's hand.");
258
+            playerBookCheck[newCardIndex] = newCard;
259
+            incrementPlayersCards();
260
+        }
261
+
262
+        while (!validCardAsked) {
263
+            String cardAskedFor = startPlayerTurn();
264
+            checkingOpponentHand();
265
+            if (checkHandForCard(playerBookCheck, cardAskedFor)) {
266
+                if (!addAsktoHand(opponentBookCheck, playerBookCheck, cardAskedFor, true)) {
267
+                    Console.print("No cards of that number found, sorry!\nGO FISH!");
268
+                    goFish(playerBookCheck, true);
269
+                }
270
+                validCardAsked = true;
271
+            } else {
272
+                Console.print("You don't have that card! Try again...");
273
+            }
274
+        }
275
+
276
+        checkPlayerBook();
277
+        endGameCheck = endGame();
278
+        endCheck(true);
279
+    }
280
+
281
+    private void checkingOpponentHand() {
282
+        Console.print("Checking opponent's hand...");
283
+        Console.pause(250, " . ", 5);
284
+    }
285
+
286
+    private boolean checkHandForCard(Card[] cards, String string) {
287
+        return cards[allRanks.get(string)] != null;
288
+    }
289
+
290
+    private void checkPlayerBook() {
291
+        Console.print("\nChecking for books... ");
292
+        Console.pause(350, " . ", 5);
293
+        Console.print("You have " + playerBook + " book(s).\n");
294
+    }
295
+
296
+    private void opponentTurn() {
297
+        printSortedHand();
298
+        opponentAsk();
299
+        endGameCheck = endGame();
300
+        endCheck(false);
301
+    }
302
+
303
+    private void opponentAsk() {
304
+
305
+        Console.print("Opponent's turn...\n");
306
+        Random random = new Random();
307
+
308
+        if (opponentTotalCards == 0) {
309
+            Card newCard = deck.dealCard();
310
+            int newCardIndex = newCard.getValue().getValue() - 1;
311
+            Console.print("Adding " + newCard.toString() + " to the owner's hand.");
312
+            opponentBookCheck[newCardIndex] = newCard;
313
+            incrementOpponentCards();
314
+        }
315
+
316
+        int result = random.nextInt(opponentTotalCards);
317
+
318
+        int counter = 0;
319
+        Card randomCard = null;
320
+
321
+        for (int i = 0; i < opponentBookCheck.length; i++) {
322
+            if (opponentBookCheck[i] != null) {
323
+                counter++;
324
+                randomCard = opponentBookCheck[i];
325
+
326
+                if (counter >= result) {
327
+                    break;
328
+                }
329
+            }
330
+        }
331
+
332
+        String opponentAsk = getRankString(opponentBookCheck[randomCard.getValue().getValue()-1]);
333
+
334
+        Console.print("Opponent is asking for " + opponentAsk + "'s. \nSearching your hand...");
335
+        Console.pause(250, " . ", 5);
336
+
337
+        if (!addAsktoHand(playerBookCheck, opponentBookCheck, opponentAsk, false)) {
338
+            goFish(opponentBookCheck, false);
339
+        }
340
+    }
341
+
342
+    public void notGameOver(Card[] bookCheck) {
343
+        Console.print("The hand is empty! Adding a card...");
344
+        Card newCard = deck.dealCard();
345
+        bookCheck[newCard.getValue().getValue() - 1] = newCard ;
346
+
347
+    }
348
+
349
+    private void endCheck(boolean isPlayersTurn) {
350
+        if (endGameCheck) {
351
+            printResult();
352
+        } else {
353
+            if (isPlayersTurn && playerTotalCards == 0) {
354
+
355
+                notGameOver(playerBookCheck);
356
+                incrementPlayersCards();
357
+
358
+            } else if (opponentTotalCards == 0) {
359
+
360
+                notGameOver(opponentBookCheck);
361
+                incrementOpponentCards();
362
+            }
363
+
364
+            Console.print("+++++ End of Turn +++++\n\n");
365
+        }
366
+
367
+        Console.pause(350, " . ", 5);
368
+    }
369
+
370
+    private String getRankString(Card c) {
371
+        return c.getValue().getThirdvalue();
372
+    }
373
+
374
+    private void showRules() {
375
+
376
+        boolean validInput = false;
377
+
378
+        Console.print("Do you want to see the rules? Y or N");
379
+
380
+        while(!validInput) {
381
+            String userRuleSelect = Console.getStringInput().toLowerCase();
382
+
383
+            switch (userRuleSelect) {
384
+                case "y" :
385
+                    rules();
386
+                    validInput = true;
387
+                    break;
388
+                case "n":
389
+                    validInput = true;
390
+                    break;
391
+                default:
392
+                    Console.print("Invalid entry, try \'Y\' or \'N\'");
393
+                    break;
394
+            }
395
+        }
396
+    }
397
+
398
+    private void rules() {
399
+
400
+        Console.print("Go Fish a game for all ages!"
401
+                + "\nEach player starts with 7 cards and the object of the game "
402
+                + "\nis to collect books, which are pairs of the same card number/rank."
403
+                + "\nFor example, a Three of hearts and a Three of diamonds makes a book!"
404
+                + "\ngame ends when the pile of cards is empty or one player has more than 13 pairs."
405
+                + "\n\nEach round, the player will ask the opponent if they have a card, but the card"
406
+                + "\nthe player asks for must be in their hand!"
407
+                + "\nIf the opponent has the card, they have to give ALL the cards that match that card "
408
+                + "\nto the player asking. If the opponent doesn't have it, the player must \"go fish\"."
409
+                + "\nGo fish means you have to get 1 card from the pile (all the leftover cards)."
410
+                + "\nThe first player to empty their hand wins!"
411
+                + "\nGood luck! :) \n\n");
412
+
413
+        pressAnyKeyToContinue();
414
+    }
415
+
416
+    private void pressAnyKeyToContinue()
417
+    {
418
+        Console.print("Press Enter key to continue...");
419
+        try {
420
+            System.in.read();
421
+        } catch(Exception e) {
422
+
423
+            e.printStackTrace();}
424
+    }
425
+
426
+    private void printResult() {
427
+        if (opponentBook > playerBook) {
428
+            Console.print("Your opponent won! :( ");
429
+        } else if (opponentBook == playerBook) {
430
+            Console.print("It was a draw :|");
431
+        } else {
432
+            Console.print("Grats, you won! :)");
433
+        }
434
+    }
435
+
436
+    public void printSortedHand() {
437
+        Console.printInSameLine("Your hand: [");
438
+
439
+        boolean firstCard = true;
440
+
441
+        for (int i = 0; i < playerBookCheck.length; i++) {
442
+
443
+            if (playerBookCheck[i] != null) {
444
+                if (!firstCard) {
445
+                    Console.printInSameLine(", ");
446
+                }
447
+                Console.printInSameLine(playerBookCheck[i].toString());
448
+                firstCard = false;
449
+            }
450
+
451
+        }
452
+        Console.printInSameLine("]\n");
453
+    }
454
+
455
+    public int getPlayerBook() {
456
+        return playerBook;
457
+    }
458
+
459
+    public void setPlayerBook(int playerBook) {
460
+        this.playerBook = playerBook;
461
+    }
462
+
463
+    public int getOpponentBook() {
464
+        return opponentBook;
465
+    }
466
+
467
+    public void setOpponentBook(int opponentBook) {
468
+        this.opponentBook = opponentBook;
469
+    }
470
+
471
+    public int getPlayerTotalCards() {
472
+        return playerTotalCards;
473
+    }
474
+
475
+    public void setPlayerTotalCards(int playerTotalCards) {
476
+        this.playerTotalCards = playerTotalCards;
477
+    }
478
+
479
+    public int getOpponentTotalCards() {
480
+        return opponentTotalCards;
481
+    }
482
+
483
+    public void setOpponentTotalCards(int opponentTotalCards) {
484
+        this.opponentTotalCards = opponentTotalCards;
485
+    }
486
+
487
+    public void incrementPlayersBook() {
488
+        setPlayerBook(getPlayerBook() + 1);
489
+    }
490
+
491
+    public void incrementOpponentBook() {
492
+        setOpponentBook(getOpponentBook() + 1);
493
+    }
494
+
495
+    public void decrementPlayersCards() {
496
+        setPlayerTotalCards(getPlayerTotalCards() - 1);
497
+    }
498
+
499
+    public void decrementOpponentCards() {
500
+        setOpponentTotalCards(getOpponentTotalCards() - 1);
501
+    }
502
+
503
+    public void incrementPlayersCards() {
504
+        setPlayerTotalCards(getPlayerTotalCards() + 1);
505
+    }
506
+
507
+    public void incrementOpponentCards() {
508
+        setOpponentTotalCards(getOpponentTotalCards() + 1);
509
+    }
510
+
511
+
512
+    public void playerTurnTrue() {
513
+        incrementPlayersBook();
514
+        decrementPlayersCards();
515
+        decrementPlayersCards();
516
+    }
517
+
518
+    public void opponentTurnTrue(){
519
+        incrementOpponentBook();
520
+        decrementOpponentCards();
521
+        decrementOpponentCards();
522
+    }
523
+}

+ 283
- 0
src/main/java/io/zipcoder/casino/game/cardgames/individualcardgames/HiLo.java Wyświetl plik

@@ -0,0 +1,283 @@
1
+
2
+        package io.zipcoder.casino.game.cardgames.individualcardgames;
3
+
4
+        import io.zipcoder.casino.game.Player;
5
+        import io.zipcoder.casino.game.cardgames.cardutilities.Card;
6
+        import io.zipcoder.casino.game.interfaces.Gamble;
7
+        import io.zipcoder.casino.Console;
8
+
9
+        import java.util.ArrayList;
10
+        import java.util.Scanner;
11
+
12
+        public class HiLo extends CardGame implements Gamble {
13
+
14
+    //Variables
15
+    Scanner in = new Scanner(System.in);
16
+
17
+    boolean gameon;
18
+
19
+    boolean cont;
20
+
21
+    boolean enoughmoney;
22
+
23
+    private Player player;
24
+
25
+    //-----------Some Verbiage--------------
26
+
27
+    String intro = "Welcome to HiLo!" + System.lineSeparator() + "Please place a bet.";
28
+
29
+    //In Next Steps Matrix
30
+
31
+    String nextsteps = "Feeling lucky today? Try your luck again then! (Yes or No)";
32
+
33
+    String outro = "Thanks for playing!";
34
+
35
+    String invalid = "That is not a valid response. Try again.";
36
+
37
+    String assout = "You're out of cash! Come back with deeper pockets!!";
38
+
39
+    //In Bet method
40
+
41
+    String notenough = "You do not have the amount specified. Would you like to place another bet or return to the main menu? (Type \"Bet\" or \"Quit\"";
42
+
43
+    String ohwell = "Better Luck Next Time!";
44
+
45
+
46
+    //Constructors
47
+    public HiLo(Player player) {
48
+        this.player = player;
49
+        gameon = true;
50
+        cont = false;
51
+    }
52
+
53
+//Main game Method
54
+
55
+    @Override
56
+    public void play() {
57
+
58
+        while (gameon) {
59
+            // place a bet
60
+            Console.print(intro);
61
+            int betbet = in.nextInt();
62
+
63
+            while (!enoughmoney) {
64
+                bet(betbet); }
65
+
66
+            //check to make sure deck has 52 cards
67
+            if (deck.getDeck().isEmpty()) {
68
+                deck.refreshDeck();
69
+            }
70
+
71
+            //deal a card to the player and house
72
+            getPlayerHand().add(deck.dealCard());
73
+            getHouseHand().add(deck.dealCard());
74
+
75
+            //prompt for high or low input
76
+            System.out.println("You have drawn a " + getPlayerHand().get(0).toString() + " would you like to bet High or Low?");
77
+            String input = in.next();
78
+
79
+            //evaluate for Win or Loss
80
+            int playerCard = (getPlayerHand().get(0).getValue().ordinal());
81
+            int dealerCard = (getHouseHand().get(0).getValue().ordinal());
82
+            winlossmatrix(input, playerCard, dealerCard, betbet);
83
+
84
+            //Next steps matrix
85
+            nextstepsmatrix();
86
+        }
87
+    }
88
+
89
+//Logic and Extra Methods
90
+
91
+
92
+    @Override
93
+    public boolean endGame() {
94
+
95
+        return true;
96
+    }
97
+
98
+
99
+    @Override
100
+    public int bet(int bet) {
101
+        int bankroll = player.getBank();
102
+        if (!player.checkbet(bet)) {
103
+            Console.print(notenough);
104
+            String response = in.next();
105
+            if (response.equalsIgnoreCase("Bet")) { play(); }
106
+            else if (response.equalsIgnoreCase("Quit")) {
107
+                Console.print(ohwell);
108
+                enoughmoney = false;
109
+                gameon = false;
110
+            }
111
+        } else {
112
+            enoughmoney = true;}
113
+        return bet;
114
+    }
115
+
116
+
117
+
118
+
119
+    public void winlossmatrix(String nput, int theplayer, int dealer, int hedge) {
120
+        int winnings = 0;
121
+
122
+        if (nput.equalsIgnoreCase("high")){
123
+            if(theplayer > dealer) {
124
+                winnings = (int) Math.floor(highLogic(hedge, dealer));
125
+                win(player, winnings);
126
+                System.out.println("You've won! The dealer's card was " + getHouseHand().get(0).toString() + " and your new bank is " + player.getBank() + "!");
127
+            } else if (theplayer == dealer ){
128
+                System.out.println("Bad luck! You and the dealer drew the same card. Dealer had a " + getHouseHand().get(0).toString());
129
+            } else {
130
+                loss(player, hedge);
131
+                System.out.println("You've lost! The dealer's card was " + getHouseHand().get(0).toString() + ". Your new bank is " + player.getBank());
132
+                in.nextLine();
133
+            }
134
+        } else if (nput.equalsIgnoreCase("low")){
135
+            if(theplayer < dealer){
136
+                winnings = (int)Math.floor(lowLogic(hedge, dealer));
137
+                win(player, winnings);
138
+                System.out.println("You've won! The dealer's card was " + getHouseHand().get(0).toString() + " and your new bank is " + player.getBank() + "!");
139
+            } else if (theplayer == dealer ){
140
+                System.out.println("Bad luck! You and the dealer drew the same card. Dealer had a " + getHouseHand().get(0).toString());
141
+            } else {
142
+                loss(player, hedge);
143
+                System.out.println("You've lost! The dealer's card was " + getHouseHand().get(0).toString() + ". Your new bank is " + player.getBank());
144
+                in.nextLine();
145
+            }
146
+        }
147
+
148
+    }
149
+
150
+
151
+
152
+    public void  nextstepsmatrix () {
153
+        while (!cont) {
154
+            if (player.getBank() > 0) {
155
+                Console.print(nextsteps);
156
+                String again = in.next();
157
+                if (again.equalsIgnoreCase("yes")) {
158
+                    enoughmoney = false;
159
+                    ArrayList<Card> newPlayerHand = new ArrayList<>();
160
+                    ArrayList<Card> newHouseHand = new ArrayList<>();
161
+                    setPlayerHand(newPlayerHand);
162
+                    setHouseHand(newHouseHand);
163
+                    play();
164
+                } else if (again.equalsIgnoreCase("no")) {
165
+                    Console.printInSameLine(outro);
166
+                    enoughmoney = false;
167
+                    gameon = false;
168
+                    cont = true;
169
+                    break;
170
+                } else {
171
+                    Console.print(invalid);
172
+                }
173
+            } else {
174
+                Console.print(assout);
175
+                enoughmoney = false;
176
+                gameon = false;
177
+                break;
178
+            }
179
+        }
180
+    }
181
+
182
+
183
+
184
+
185
+    public static double highLogic(int bet, int dealerCard){
186
+        double sum = 0;
187
+
188
+        switch (dealerCard) {
189
+            case 1:
190
+                sum = bet;
191
+                return sum;
192
+            case 2:
193
+                sum = bet * 1.1;
194
+                return sum;
195
+            case 3:
196
+                sum = bet * 1.2;
197
+                return sum;
198
+            case 4:
199
+                sum = bet * 1.4;
200
+                return sum;
201
+            case 5:
202
+                sum = bet * 1.4;
203
+                return sum;
204
+            case 6:
205
+                sum = bet * 1.5;
206
+                return sum;
207
+            case 7:
208
+                sum = bet * 1.8;
209
+                return sum;
210
+            case 8:
211
+                sum = bet * 2;
212
+                return sum;
213
+            case 9:
214
+                sum = bet * 3;
215
+                return sum;
216
+            case 10:
217
+                sum = bet * 4;
218
+                return sum;
219
+            case 11:
220
+                sum = bet * 5;
221
+                return sum;
222
+            case 12:
223
+                sum = bet * 12;
224
+                return sum;
225
+            case 13:
226
+                sum = bet;
227
+                return sum;
228
+        }
229
+
230
+        return sum;
231
+    }
232
+
233
+    public static double lowLogic(int bet, int dealerCard){
234
+        double sum = 0;
235
+
236
+        switch (dealerCard) {
237
+            case 1:
238
+                sum = bet;
239
+                return sum;
240
+            case 2:
241
+                sum = bet * 12;
242
+                return sum;
243
+            case 3:
244
+                sum = bet * 5;
245
+                return sum;
246
+            case 4:
247
+                sum = bet * 3;
248
+                return sum;
249
+            case 5:
250
+                sum = bet * 3;
251
+                return sum;
252
+            case 6:
253
+                sum = bet * 2;
254
+                return sum;
255
+            case 7:
256
+                sum = bet * 1.8;
257
+                return sum;
258
+            case 8:
259
+                sum = bet * 1.5;
260
+                return sum;
261
+            case 9:
262
+                sum = bet * 1.4;
263
+                return sum;
264
+            case 10:
265
+                sum = bet * 1.3;
266
+                return sum;
267
+            case 11:
268
+                sum = bet * 1.2;
269
+                return sum;
270
+            case 12:
271
+                sum = bet * 1.1;
272
+                return sum;
273
+            case 13:
274
+                sum = bet;
275
+                return sum;
276
+        }
277
+
278
+        return sum;
279
+    }
280
+
281
+
282
+}
283
+

+ 184
- 0
src/main/java/io/zipcoder/casino/game/chancegames/Roulette.java Wyświetl plik

@@ -0,0 +1,184 @@
1
+
2
+package io.zipcoder.casino.game.chancegames;
3
+
4
+import io.zipcoder.casino.Console;
5
+import io.zipcoder.casino.game.Player;
6
+import io.zipcoder.casino.game.chancegames.chancegameutilities.RandomNumGen;
7
+import io.zipcoder.casino.game.chancegames.chancegameutilities.RouletteWheel;
8
+import io.zipcoder.casino.game.interfaces.Gamble;
9
+import io.zipcoder.casino.game.interfaces.Game;
10
+
11
+import java.util.*;
12
+
13
+public class Roulette implements Gamble, Game {
14
+
15
+    Player player;
16
+    private int numResult;
17
+    private String clrResult;
18
+    private int numGuess;
19
+    private String clrGuess;
20
+    private int betAmount;
21
+    private RouletteWheel wheel = new RouletteWheel();
22
+    private RandomNumGen random = new RandomNumGen();
23
+    boolean runner = true;
24
+
25
+
26
+
27
+    public Roulette(Player player) {
28
+        this.player = player;
29
+
30
+    }
31
+
32
+    public void play() {
33
+
34
+        while (runner == true) {
35
+
36
+            Console.print("Welcome to Zip Roulette: please enter a wager");
37
+            Console.print("Player Bank: " + player.getBank());
38
+            betAmount = Console.getIntegerInput();
39
+            int input = Console.printAndTakeInt("Great job! Enter 1 for to bet on a number; enter 2 to bet on a color");
40
+            playEntry(input);
41
+            win(betAmount);
42
+            runner = endGame();
43
+        }
44
+    }
45
+
46
+    @Override
47
+    public boolean endGame() {
48
+
49
+        String input = Console.printAndTakeString("Do you want to end the game or play again? Yes or No?");
50
+        if (input.equalsIgnoreCase("yes")) {
51
+            return runner = true;
52
+        } else {
53
+            return runner = false;
54
+        }
55
+    }
56
+
57
+
58
+    public void getResult(RandomNumGen random) {
59
+        Object[] keys = wheel.getWheel().keySet().toArray();
60
+        Object tempKey = keys[random.randomRoulette()];
61
+        numResult = (int) tempKey;
62
+        clrResult = wheel.getWheel().get(tempKey);
63
+        Console.print("\n****** " + numResult + " " + clrResult + " ******");
64
+    }
65
+
66
+    public void playEntry(int input) {
67
+        if (input == 1) {
68
+            numberEntry();
69
+        } else if (input == 2) {
70
+            colorEntry();
71
+        } else {
72
+            Console.print("Please try again");
73
+        }
74
+    }
75
+
76
+    public void numberEntry() {
77
+        numGuess = Console.printAndTakeInt("Please enter number between 0 and 36");
78
+        Console.pause(500, ". ",4);
79
+        getResult(random);
80
+        compareNumbers(numGuess);
81
+    }
82
+
83
+    public void colorEntry() {
84
+        clrGuess = Console.printAndTakeString("Please enter black, red or green");
85
+        Console.pause(500, ". ",4);
86
+        getResult(random);
87
+        compareBlckRd(clrGuess);
88
+
89
+
90
+    }
91
+
92
+    public boolean compareNumbers(int numGuess) {
93
+
94
+        if (numGuess == numResult) {
95
+            bet(5);
96
+            return true;
97
+        } else {
98
+            loss(betAmount);
99
+            betAmount = 0;
100
+            return false;}
101
+
102
+    }
103
+
104
+    public boolean compareBlckRd(String clrGuess) {
105
+
106
+        if(clrGuess.equalsIgnoreCase(clrResult)){
107
+            bet(2);
108
+            return true;
109
+        } else {
110
+            loss(betAmount);
111
+            betAmount = 0;
112
+            return false;}
113
+
114
+    }
115
+
116
+
117
+    @Override
118
+    public int bet(int betMultiplier) {
119
+
120
+        return betAmount *= betMultiplier;
121
+
122
+    }
123
+
124
+    public void win(int betAmount) {
125
+        player.setBank(player.getBank() + betAmount);
126
+    }
127
+
128
+
129
+    public void loss(int betAmount) {
130
+        player.setBank(player.getBank() - betAmount);
131
+
132
+    }
133
+
134
+
135
+    public void checkBet() {
136
+        if (betAmount > player.getBank()) {
137
+            Console.print("Not enough funds: enter another wager");
138
+
139
+        }
140
+    }
141
+
142
+    public int getNumResult() {
143
+        return numResult;
144
+    }
145
+
146
+    public String getClrResult() {
147
+        return clrResult;
148
+    }
149
+
150
+    public void setNumResult(int numResult) {
151
+        this.numResult = numResult;
152
+    }
153
+
154
+    public void setClrResult(String clrResult) {
155
+        this.clrResult = clrResult;
156
+    }
157
+
158
+    public int getNumGuess() {
159
+        return numGuess;
160
+    }
161
+
162
+    public String getClrGuess() {
163
+        return clrGuess;
164
+    }
165
+
166
+    public int getBetAmount() {
167
+        return betAmount;
168
+    }
169
+
170
+    public void setBetAmount(int betAmount) {
171
+        this.betAmount = betAmount;
172
+    }
173
+
174
+    public void setNumGuess(int numGuess) {
175
+        this.numGuess = numGuess;
176
+    }
177
+
178
+    public void setClrGuess(String clrGuess) {
179
+        this.clrGuess = clrGuess;
180
+    }
181
+
182
+    public boolean isRunner() { return runner; }
183
+}
184
+

+ 88
- 0
src/main/java/io/zipcoder/casino/game/chancegames/Slots.java Wyświetl plik

@@ -0,0 +1,88 @@
1
+package io.zipcoder.casino.game.chancegames;
2
+
3
+import io.zipcoder.casino.Console;
4
+import io.zipcoder.casino.game.Player;
5
+import io.zipcoder.casino.game.interfaces.Gamble;
6
+import io.zipcoder.casino.game.interfaces.Game;
7
+
8
+public class Slots implements Game, Gamble {
9
+
10
+    Player player;
11
+    private int slots[];
12
+    private int amount;
13
+
14
+    public Slots(Player player){
15
+        this.player = player;
16
+        slots = new int[3];
17
+    }
18
+
19
+    public void play(){
20
+        amount = Console.printAndTakeInt("Enter the bet amount you want to bet");
21
+
22
+        if(player.checkbet(amount)){
23
+            spin();
24
+        }
25
+        else{
26
+            String choice = Console.printAndTakeString("You have insufficient balance.\nEnter \"yes\" to continue with some new amount or \"no\" to exit the game");
27
+            if(choice.equals("yes"))
28
+                play();
29
+        }
30
+
31
+    }
32
+
33
+    @Override
34
+    public boolean endGame() {
35
+        return false;
36
+    }
37
+
38
+    public void result(){
39
+        int endAmount = bet(amount);
40
+
41
+        if(endAmount > amount)
42
+            win(player, endAmount);
43
+        else
44
+            loss(player, endAmount);
45
+        Console.print("Amount in your Bank : " + player.getBank());
46
+    }
47
+
48
+
49
+    public void spin() {
50
+
51
+            for (int i = 0; i < this.slots.length; i++)
52
+                this.slots[i] = (int)(Math.random() * 7 + 1);
53
+            Console.print(slots[0],slots[1], slots[2]);
54
+
55
+        result();
56
+
57
+    }
58
+
59
+
60
+
61
+    @Override
62
+    public int bet(int initialAmount) {
63
+        int returnBet = checkMatching(initialAmount);
64
+
65
+        if(returnBet > initialAmount)
66
+            Console.print("Congrats!! You won");
67
+        else
68
+            Console.print("YOu Lost!!");
69
+        return returnBet;
70
+    }
71
+
72
+    public int checkMatching(int initialAmount){
73
+        if(slots[0] == slots[1] && slots[1] == slots[2])
74
+            return initialAmount * 3;
75
+        else if(slots[0] == slots[1] || slots[1] == slots[2] || slots[2] == slots[0])
76
+            return initialAmount * 2;
77
+        else
78
+            return initialAmount;
79
+    }
80
+
81
+    public int[] getSlots() {
82
+        return this.slots;
83
+    }
84
+
85
+    public void setSlots(int[] slots) {
86
+        this.slots = slots;
87
+    }
88
+}

+ 16
- 0
src/main/java/io/zipcoder/casino/game/chancegames/chancegameutilities/RandomNumGen.java Wyświetl plik

@@ -0,0 +1,16 @@
1
+package io.zipcoder.casino.game.chancegames.chancegameutilities;
2
+
3
+import java.util.Random;
4
+
5
+public class RandomNumGen {
6
+Random random;
7
+
8
+    public RandomNumGen() {
9
+        random = new Random();
10
+    }
11
+
12
+
13
+    public int randomRoulette() {
14
+        return random.nextInt(37);
15
+    }
16
+}

+ 64
- 0
src/main/java/io/zipcoder/casino/game/chancegames/chancegameutilities/RouletteWheel.java Wyświetl plik

@@ -0,0 +1,64 @@
1
+package io.zipcoder.casino.game.chancegames.chancegameutilities;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+public class RouletteWheel {
7
+    private final Map<Integer, String> wheel;
8
+
9
+
10
+
11
+    public RouletteWheel() {
12
+        wheel = new HashMap<>();
13
+        wheel.put(0, "Green");
14
+        wheel.put(1, "Red");
15
+        wheel.put(2, "Black");
16
+        wheel.put(3, "Red");
17
+        wheel.put(4, "Black");
18
+        wheel.put(5, "Red");
19
+        wheel.put(6, "Black");
20
+        wheel.put(7, "Red");
21
+        wheel.put(8, "Black");
22
+        wheel.put(9, "Red");
23
+        wheel.put(10, "Black");
24
+        wheel.put(11, "Red");
25
+        wheel.put(12, "Black");
26
+        wheel.put(13, "Red");
27
+        wheel.put(14, "Black");
28
+        wheel.put(15, "Red");
29
+        wheel.put(16, "Black");
30
+        wheel.put(17, "Red");
31
+        wheel.put(18, "Black");
32
+        wheel.put(19, "Red");
33
+        wheel.put(20, "Black");
34
+        wheel.put(21, "Red");
35
+        wheel.put(22, "Black");
36
+        wheel.put(23, "Red");
37
+        wheel.put(24, "Black");
38
+        wheel.put(25, "Red");
39
+        wheel.put(26, "Black");
40
+        wheel.put(27, "Red");
41
+        wheel.put(28, "Black");
42
+        wheel.put(29, "Black");
43
+        wheel.put(30, "Red");
44
+        wheel.put(31, "Black");
45
+        wheel.put(32, "Red");
46
+        wheel.put(33, "Black");
47
+        wheel.put(34, "Black");
48
+        wheel.put(35, "Black");
49
+        wheel.put(36, "Red");
50
+
51
+    }
52
+
53
+    public RouletteWheel(Map<Integer, String> wheel) {
54
+        this.wheel = wheel;
55
+    }
56
+
57
+    public Map<Integer, String> getWheel() {
58
+        return wheel;
59
+    }
60
+
61
+    public int getWheelSize() {
62
+       return wheel.size();
63
+    }
64
+}

+ 32
- 0
src/main/java/io/zipcoder/casino/game/dicegames/diceutilities/Dice.java Wyświetl plik

@@ -0,0 +1,32 @@
1
+package io.zipcoder.casino.game.dicegames.diceutilities;
2
+
3
+import java.util.Random;
4
+
5
+public class Dice {
6
+
7
+    RandomDice randomDice;
8
+    private int numOfDice;
9
+
10
+    public Dice(int numOfDice){
11
+        this.numOfDice = numOfDice;
12
+        randomDice = new RandomDice();
13
+    }
14
+
15
+    public void setRandomDice(RandomDice randomDice) {
16
+        this.randomDice = randomDice;
17
+    }
18
+
19
+    public int tossAndSum() {
20
+
21
+        int sumRoll = 0;
22
+
23
+        for (int i = 0; i < numOfDice; i++) {
24
+            sumRoll += randomDice.randDice();
25
+        }
26
+        return sumRoll;
27
+    }
28
+
29
+    public int getNumOfDice() {
30
+        return numOfDice;
31
+    }
32
+}

+ 16
- 0
src/main/java/io/zipcoder/casino/game/dicegames/diceutilities/RandomDice.java Wyświetl plik

@@ -0,0 +1,16 @@
1
+package io.zipcoder.casino.game.dicegames.diceutilities;
2
+
3
+import java.util.Random;
4
+
5
+public class RandomDice {
6
+
7
+    public int randDice()
8
+
9
+    {
10
+        int sum = 0;
11
+        Random rand = new Random();
12
+        sum = rand.nextInt(6) + 1;
13
+
14
+        return sum;
15
+    }
16
+}

+ 165
- 0
src/main/java/io/zipcoder/casino/game/dicegames/individualdicegames/Craps.java Wyświetl plik

@@ -0,0 +1,165 @@
1
+package io.zipcoder.casino.game.dicegames.individualdicegames;
2
+
3
+import io.zipcoder.casino.Console;
4
+import io.zipcoder.casino.game.dicegames.diceutilities.Dice;
5
+import io.zipcoder.casino.game.interfaces.Gamble;
6
+import io.zipcoder.casino.game.Player;
7
+
8
+public class Craps extends DiceGame implements Gamble {
9
+
10
+    private Player player;
11
+    private Dice pairOfDice;
12
+    private int numOfRolls;
13
+    public boolean win;
14
+    public boolean continueGame;
15
+    private int amount;
16
+    public int rollOne;
17
+    public int rollTwo;
18
+
19
+
20
+    public Craps(Player player){
21
+        this.player = player;
22
+        numOfRolls = 0;
23
+        pairOfDice = createDice(2);
24
+        rollOne = 0;
25
+        rollTwo = 0;
26
+    }
27
+
28
+    public int getNumOfRolls(){
29
+        return numOfRolls;
30
+    }
31
+
32
+    public Dice getPairOfDice() {
33
+        return pairOfDice;
34
+    }
35
+
36
+    public int roll(){
37
+        int sum = pairOfDice.tossAndSum();
38
+        return sum;
39
+    }
40
+
41
+    @Override
42
+    public Dice createDice(int numberOfDice) {
43
+        Dice crapsDice = new Dice(numberOfDice);
44
+        return crapsDice;
45
+    }
46
+
47
+    @Override
48
+    public int bet(int initialAmount) {
49
+        int returnBet = initialAmount;
50
+
51
+        if (win){
52
+            returnBet *= 2;
53
+            win(player, returnBet);
54
+        } else if (!win) {
55
+            loss(player, returnBet);
56
+        }
57
+        return -1;
58
+    }
59
+
60
+    @Override
61
+    public void play() {
62
+
63
+        continueGame = true;
64
+
65
+        Console.print("  _______________________________________________________________ ___________________    _____ __________  _________\n" +
66
+                " /   _____/\\__    ___/\\______   \\_   _____/\\_   _____/\\__    ___/ \\_   ___ \\______   \\  /  _  \\\\______   \\/   _____/\n" +
67
+                " \\_____  \\   |    |    |       _/|    __)_  |    __)_   |    |    /    \\  \\/|       _/ /  /_\\  \\|     ___/\\_____  \\ \n" +
68
+                " /        \\  |    |    |    |   \\|        \\ |        \\  |    |    \\     \\___|    |   \\/    |    \\    |    /        \\\n" +
69
+                "/_______  /  |____|    |____|_  /_______  //_______  /  |____|     \\______  /____|_  /\\____|__  /____|   /_______  /\n" +
70
+                "        \\/                    \\/        \\/         \\/                     \\/       \\/         \\/                 \\/");
71
+
72
+        Console.print("               (( _______\n" +
73
+                "     _______     /\\O    O\\\n" +
74
+                "    /O     /\\   /  \\      \\\n" +
75
+                "   /   O  /O \\ / O  \\O____O\\ ))\n" +
76
+                "((/_____O/    \\\\    /O     /\n" +
77
+                "  \\O    O\\    / \\  /   O  /\n" +
78
+                "   \\O    O\\ O/   \\/_____O/\n" +
79
+                "    \\O____O\\/ ))          ))\n" +
80
+                "  ((");
81
+
82
+        while(continueGame) {
83
+            Console.print("Player Bank: " + "$" + player.getBank());
84
+            Console.print("Enter the amount you want to bet");
85
+            amount = Console.getIntegerInput();
86
+            Console.print("\n");
87
+
88
+            if (player.checkbet(amount)) {
89
+                runGame();
90
+            } else {
91
+                Console.print("You have insufficient funds.\nEnter \"yes\" to continue with a new bet or \"no\" to exit the game");
92
+                String choice = Console.getStringInput();
93
+                if (choice.equals("yes")) {
94
+                    continue;
95
+                } else if (choice.equals("no")) {
96
+                    continueGame = false;
97
+                    break;
98
+                }
99
+            }
100
+            continueGame = endGame();
101
+        }
102
+    }
103
+
104
+    public void runGame() {
105
+        firstRoll();
106
+        bet(amount);
107
+    }
108
+
109
+    public boolean isWin() {
110
+        return win;
111
+    }
112
+
113
+    public void firstRoll() {
114
+
115
+        rollOne = roll();
116
+        if (rollOne == 7 || rollOne == 11) {
117
+            Console.print("Your first roll is: " + rollOne);
118
+            Console.print("You Win!! (⌐■_■)");
119
+            win = true;
120
+
121
+        } else if (rollOne == 2 || rollOne == 3 || rollOne == 12) {
122
+            Console.print("Your first roll is: " + rollOne);
123
+            Console.print("You Lose ಠ_ಠ");
124
+            win = false;
125
+        } else{
126
+            Console.print("Your first roll is: " + rollOne + ", Rolling again.");
127
+            Console.pause(500/2, " ⚀ ");
128
+            Console.pause(500/2, " ⚁ ");
129
+            Console.pause(500/2, " ⚂ ");
130
+            Console.pause(500/2, " ⚃ ");
131
+            Console.pause(500/2, " ⚄ ");
132
+            Console.pause(500/2, " ⚅ ");
133
+            secondRoll();}
134
+    }
135
+
136
+        public void secondRoll() {
137
+            rollTwo = roll();
138
+
139
+            if (rollTwo == rollOne) {
140
+                Console.print("Your second roll is your point number");
141
+                Console.print("You Win!! (⌐■_■)");
142
+                win = true;
143
+            } else  {
144
+                Console.print("\nYour second roll is: " + rollTwo);
145
+                Console.print("You Lose ಠ_ಠ");
146
+                win = false;
147
+            }
148
+        }
149
+
150
+    @Override
151
+    public boolean endGame() {
152
+        Console.print("Do you want to continue Street Craps, Yes or No?");
153
+        String input = Console.getStringInput();
154
+
155
+        if (input.equalsIgnoreCase("yes")) {
156
+            return true;
157
+        } else {
158
+            return false;
159
+        }
160
+    }
161
+
162
+}
163
+
164
+
165
+

+ 10
- 0
src/main/java/io/zipcoder/casino/game/dicegames/individualdicegames/DiceGame.java Wyświetl plik

@@ -0,0 +1,10 @@
1
+package io.zipcoder.casino.game.dicegames.individualdicegames;
2
+
3
+import io.zipcoder.casino.game.dicegames.diceutilities.Dice;
4
+import io.zipcoder.casino.game.interfaces.Gamble;
5
+import io.zipcoder.casino.game.interfaces.Game;
6
+
7
+public abstract class DiceGame implements Game, Gamble {
8
+
9
+    public abstract Dice createDice(int numberOfDice);
10
+}

+ 17
- 0
src/main/java/io/zipcoder/casino/game/interfaces/Gamble.java Wyświetl plik

@@ -0,0 +1,17 @@
1
+package io.zipcoder.casino.game.interfaces;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+
5
+public interface Gamble {
6
+
7
+    int bet(int initialAmount);
8
+
9
+    default void win(Player player, int winnings) {
10
+        player.setBank(player.getBank() + winnings);
11
+    }
12
+
13
+    default void loss(Player player, int losses) {
14
+        player.setBank(player.getBank() - losses);
15
+    }
16
+
17
+}

+ 7
- 0
src/main/java/io/zipcoder/casino/game/interfaces/Game.java Wyświetl plik

@@ -0,0 +1,7 @@
1
+package io.zipcoder.casino.game.interfaces;
2
+
3
+public interface Game {
4
+
5
+    void play();
6
+    boolean endGame();
7
+}

+ 262
- 0
src/test/java/io/zipcoder/casino/BlackJackTest.java Wyświetl plik

@@ -0,0 +1,262 @@
1
+package io.zipcoder.casino;
2
+
3
+
4
+
5
+import io.zipcoder.casino.game.Player;
6
+import io.zipcoder.casino.game.cardgames.cardutilities.Card;
7
+import io.zipcoder.casino.game.cardgames.cardutilities.Deck;
8
+import io.zipcoder.casino.game.cardgames.cardutilities.Rank;
9
+import io.zipcoder.casino.game.cardgames.cardutilities.Suit;
10
+import io.zipcoder.casino.game.cardgames.individualcardgames.BlackJack;
11
+import org.junit.*;
12
+public class BlackJackTest {
13
+    private DeckMock deck;
14
+    @Before
15
+    public void initialize(){
16
+        deck = new DeckMock();
17
+    }
18
+
19
+
20
+@Test
21
+public void clearHandsTest(){
22
+    //Given
23
+    PlayerMock playerMock = new PlayerMock();
24
+    BlackJack blackJack = new BlackJack(playerMock);
25
+    blackJack.playerTotal = 21;
26
+    Integer actual = 0;
27
+    //When
28
+    blackJack.clearHands();
29
+    //Then
30
+    Assert.assertEquals(blackJack.playerTotal, actual);
31
+}
32
+    @Test
33
+    public void endGameTest(){
34
+        //Given
35
+        PlayerMock playerMock = new PlayerMock();
36
+        BlackJack blackJack = new BlackJack(playerMock);
37
+        blackJack.playerTotal = 21;
38
+        //When
39
+        boolean actual = blackJack.endGame();
40
+        //Then
41
+        Assert.assertFalse(actual);
42
+    }
43
+
44
+
45
+@Test
46
+public void introTest(){
47
+    //Given
48
+    PlayerMock playerMock = new PlayerMock();
49
+    BlackJack blackJack = new BlackJack(playerMock);
50
+    String expected = "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣\n +" +
51
+            "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦ WELCOME TO BLACKJACK ♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♠♥♦♣\n" +
52
+            "♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣♠♥♦♣\n";
53
+    //When
54
+    String actual = blackJack.intro();
55
+    //Then
56
+    Assert.assertEquals(expected, actual);
57
+
58
+}
59
+
60
+@Test
61
+public void dealHouseTest(){
62
+    //Given
63
+    PlayerMock playerMock = new PlayerMock();
64
+    BlackJack blackJack = new BlackJack(playerMock);
65
+    boolean expected = true;
66
+    //When
67
+    boolean actual = blackJack.dealHouse();
68
+    //Then
69
+    Assert.assertTrue(actual);
70
+
71
+}
72
+
73
+@Test
74
+public void handSumTest(){
75
+    //Given
76
+    PlayerMock playerMock = new PlayerMock();
77
+    BlackJack blackJack = new BlackJack(playerMock);
78
+    blackJack.getPlayerHand().add(new CardMock());
79
+    blackJack.getHouseHand().add(new CardMock());
80
+    int expected = 11;
81
+    //When
82
+    blackJack.handSum();
83
+    int actual = blackJack.playerTotal;
84
+    //Then
85
+    Assert.assertEquals(expected,actual);
86
+
87
+
88
+}
89
+@Test
90
+public void doBlackjackTest(){
91
+        //Given
92
+        PlayerMock playerMock = new PlayerMock();
93
+        BlackJack blackJack = new BlackJack(playerMock);
94
+        int stakes = 1000;
95
+        int expected = 12500;
96
+        //When
97
+        blackJack.doBlackjack(stakes);
98
+        int actual = playerMock.getBank() + stakes;
99
+        //Then
100
+        Assert.assertEquals(expected,actual);
101
+
102
+    }
103
+    @Test
104
+    public void winConditionsPlayerBustTest(){
105
+        //Given
106
+        PlayerMock playerMock = new PlayerMock();
107
+        BlackJack blackJack = new BlackJack(playerMock);
108
+        blackJack.playerTotal = 22;
109
+        int stakes = 1000;
110
+        int expected = 9000;
111
+        //When
112
+        blackJack.winConditions(stakes);
113
+        int actual = playerMock.getBank();
114
+        //Then
115
+        Assert.assertEquals(expected,actual);
116
+
117
+    }
118
+    @Test
119
+    public void winConditionsHouseBustTest(){
120
+        //Given
121
+        PlayerMock playerMock = new PlayerMock();
122
+        BlackJack blackJack = new BlackJack(playerMock);
123
+        blackJack.playerTotal = 10;
124
+        blackJack.houseTotal = 22;
125
+        int stakes = 1000;
126
+        int expected = 11000;
127
+        //When
128
+        blackJack.winConditions(stakes);
129
+        int actual = playerMock.getBank();
130
+        //Then
131
+        Assert.assertEquals(expected,actual);
132
+
133
+    }
134
+    @Test
135
+    public void winConditionsPlayerWinsTest(){
136
+        //Given
137
+        PlayerMock playerMock = new PlayerMock();
138
+        BlackJack blackJack = new BlackJack(playerMock);
139
+        blackJack.playerTotal = 20;
140
+        blackJack.houseTotal = 10;
141
+        int stakes = 1000;
142
+        int expected = 11000;
143
+        //When
144
+        blackJack.winConditions(stakes);
145
+        int actual = playerMock.getBank();
146
+        //Then
147
+        Assert.assertEquals(expected,actual);
148
+
149
+    }
150
+    @Test
151
+    public void winConditionsHouseWinsTest(){
152
+        //Given
153
+        PlayerMock playerMock = new PlayerMock();
154
+        BlackJack blackJack = new BlackJack(playerMock);
155
+        blackJack.playerTotal = 10;
156
+        blackJack.houseTotal = 20;
157
+        int stakes = 1000;
158
+        int expected = 9000;
159
+        //When
160
+        blackJack.winConditions(stakes);
161
+        int actual = playerMock.getBank();
162
+        //Then
163
+        Assert.assertEquals(expected,actual);
164
+
165
+    }
166
+    @Test
167
+    public void winConditionsPushTest(){
168
+        //Given
169
+        PlayerMock playerMock = new PlayerMock();
170
+        BlackJack blackJack = new BlackJack(playerMock);
171
+        blackJack.playerTotal = 10;
172
+        blackJack.houseTotal = 10;
173
+        int stakes = 1000;
174
+        int expected = 10000;
175
+        //When
176
+        blackJack.winConditions(stakes);
177
+        int actual = playerMock.getBank();
178
+        //Then
179
+        Assert.assertEquals(expected,actual);
180
+
181
+    }
182
+    @Test
183
+    public void dealHouseWith21Test(){
184
+        //Given
185
+        PlayerMock playerMock = new PlayerMock();
186
+        BlackJack blackJack = new BlackJack(playerMock);
187
+        blackJack.houseTotal = 22;
188
+        boolean expected = true;
189
+        //When
190
+        boolean actual = blackJack.dealHouse();
191
+        //Then
192
+        Assert.assertTrue(actual);
193
+
194
+    }
195
+    @Test
196
+    public void dealSumPrintTest(){
197
+        //Given
198
+        PlayerMock playerMock = new PlayerMock();
199
+        BlackJack blackJack = new BlackJack(playerMock);
200
+        blackJack.houseTotal = 22;
201
+        boolean expected = true;
202
+        //When
203
+        boolean actual = blackJack.dealSumPrint();
204
+        //Then
205
+        Assert.assertTrue(actual);
206
+
207
+    }
208
+    @Test
209
+    public void dealSumFirstShowTest(){
210
+        //Given
211
+        PlayerMock playerMock = new PlayerMock();
212
+        BlackJack blackJack = new BlackJack(playerMock);
213
+        blackJack.getHouseHand().add(new CardMock());
214
+        blackJack.houseTotal = 22;
215
+        boolean expected = true;
216
+        //When
217
+        boolean actual = blackJack.dealSumFirstShow();
218
+        //Then
219
+        Assert.assertTrue(actual);
220
+
221
+    }
222
+    @Test
223
+    public void firstShownTest(){
224
+        //Given
225
+        PlayerMock playerMock = new PlayerMock();
226
+        BlackJack blackJack = new BlackJack(playerMock);
227
+        blackJack.houseTotal = 22;
228
+        blackJack.getHouseHand().add(new CardMock());
229
+        boolean expected = true;
230
+        //When
231
+        boolean actual = blackJack.firstShow();
232
+        //Then
233
+        Assert.assertTrue(actual);
234
+    }
235
+
236
+private class CardMock extends Card{
237
+    private CardMock() {
238
+        super(Suit.Spades, Rank.Ace);
239
+    }
240
+
241
+
242
+}
243
+    public class DeckMock extends Deck{
244
+        CardMock cardMock = new CardMock();
245
+        public DeckMock() {
246
+        }
247
+        @Override
248
+        public Card dealCard(){
249
+            return cardMock;
250
+
251
+        }
252
+
253
+    }
254
+
255
+    private class PlayerMock extends Player{
256
+
257
+        public PlayerMock() {
258
+            super("John", 10000);
259
+        }
260
+    }
261
+}
262
+

+ 0
- 5
src/test/java/io/zipcoder/casino/CasinoTest.java Wyświetl plik

@@ -1,5 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-
4
-public class CasinoTest {
5
-}

+ 167
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java Wyświetl plik

@@ -0,0 +1,167 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+import io.zipcoder.casino.game.dicegames.diceutilities.RandomDice;
5
+import io.zipcoder.casino.game.dicegames.individualdicegames.Craps;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+public class CrapsTest {
10
+
11
+    Craps craps;
12
+    Player player;
13
+    mockRandom rand = new mockRandom();
14
+
15
+    public CrapsTest(){
16
+        player = new Player();
17
+        craps = new Craps(player);
18
+    }
19
+
20
+    private class mockRandom extends RandomDice {
21
+        public Integer rollNumber;
22
+
23
+        @Override
24
+        public int randDice(){
25
+            return rollNumber;
26
+        }
27
+    }
28
+
29
+    @Test
30
+    public void createDiceTest() {
31
+        craps.createDice(2);
32
+
33
+        int expected = 2;
34
+
35
+        int actual = craps.getPairOfDice().getNumOfDice();
36
+
37
+        Assert.assertEquals(expected, actual);
38
+
39
+    }
40
+
41
+    @Test
42
+    public void rollTest() {
43
+        craps.createDice(2);
44
+
45
+        boolean actualRoll = false;
46
+
47
+        int diceRoll = craps.roll();
48
+        if (diceRoll <= 12 && diceRoll >= 2){
49
+            actualRoll = true;
50
+        }
51
+        //then
52
+        System.out.println(diceRoll);
53
+        Assert.assertTrue(actualRoll);
54
+
55
+    }
56
+
57
+    @Test
58
+    public void getNumOfRollsTest() {
59
+        int expected = 0;
60
+
61
+        int actual = craps.getNumOfRolls();
62
+
63
+        Assert.assertEquals(expected, actual);
64
+    }
65
+
66
+    @Test
67
+    public void playTest() {
68
+    }
69
+
70
+    @Test
71
+    public void betTest() {
72
+        craps.win = true;
73
+        craps.bet(10);
74
+
75
+        int expected = player.getBank();
76
+        int actual = 10020;
77
+
78
+        Assert.assertEquals(expected, actual);
79
+    }
80
+
81
+    @Test
82
+    public void betTest1() {
83
+        craps.win = false;
84
+        craps.bet(10);
85
+
86
+        int expected = player.getBank();
87
+        int actual = 9990;
88
+
89
+        Assert.assertEquals(expected, actual);
90
+    }
91
+
92
+
93
+    @Test
94
+    public void firstRoll() {
95
+        craps.firstRoll();
96
+
97
+        Assert.assertTrue(craps.rollOne >= 2 && craps.rollOne <= 12);
98
+    }
99
+
100
+    @Test
101
+    public void firstRoll2(){
102
+        Craps craps = new Craps(player);
103
+
104
+        rand.rollNumber = 6;
105
+
106
+        craps.getPairOfDice().setRandomDice(rand);
107
+
108
+        craps.firstRoll();
109
+
110
+        Assert.assertFalse(craps.isWin());
111
+}
112
+
113
+    @Test
114
+    public void firstRoll3(){
115
+        Craps craps = new Craps(player);
116
+
117
+        rand.rollNumber = 1;
118
+
119
+        craps.getPairOfDice().setRandomDice(rand);
120
+
121
+        craps.firstRoll();
122
+
123
+        Assert.assertFalse(craps.isWin());
124
+    }
125
+
126
+    @Test
127
+    public void secondRoll() {
128
+        Craps craps = new Craps(player);
129
+
130
+        rand.rollNumber = 3;
131
+
132
+        craps.getPairOfDice().setRandomDice(rand);
133
+
134
+        craps.firstRoll();
135
+
136
+        Assert.assertTrue(craps.isWin());
137
+    }
138
+
139
+    @Test
140
+    public void secondRoll2() {
141
+        Craps craps = new Craps(player);
142
+
143
+        rand.rollNumber = 4;
144
+
145
+        craps.getPairOfDice().setRandomDice(rand);
146
+
147
+        craps.firstRoll();
148
+
149
+        Assert.assertTrue(craps.isWin());
150
+    }
151
+
152
+
153
+
154
+    @Test
155
+    public void endGameTest() {
156
+        craps.continueGame = true;
157
+        Assert.assertTrue("yes", true);
158
+    }
159
+
160
+    @Test
161
+    public void endGameTest2() {
162
+        craps.continueGame = false;
163
+        Assert.assertTrue("no", true);
164
+    }
165
+
166
+}
167
+

+ 22
- 0
src/test/java/io/zipcoder/casino/DiceTest.java Wyświetl plik

@@ -0,0 +1,22 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.dicegames.diceutilities.Dice;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class DiceTest {
8
+
9
+    @Test
10
+    public void DiceTest1(){
11
+
12
+        Dice dice = new Dice(2);
13
+
14
+        boolean actual = false;
15
+        int roll = dice.tossAndSum();
16
+        if (roll <= 12 && roll >= 1){
17
+            actual = true;
18
+        }
19
+        System.out.println(roll);
20
+        Assert.assertTrue(actual);
21
+    }
22
+}

+ 53
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java Wyświetl plik

@@ -0,0 +1,53 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+import org.junit.*;
5
+
6
+public class PlayerTest {
7
+
8
+    @Test
9
+    public  void playerNameTest(){
10
+        //Given
11
+        Player player = new Player("Bob", 5000);
12
+        String expected = "John";
13
+        //When
14
+        player.setName("John");
15
+        String actual = player.getName();
16
+        //Then
17
+        Assert.assertEquals(expected,actual);
18
+
19
+    }
20
+    @Test
21
+    public  void playerBankTest(){
22
+        //Given
23
+        Player player = new Player("Bob", 5000);
24
+        Integer expected = 10000;
25
+        //When
26
+        player.setBank(10000);
27
+        Integer actual = player.getBank();
28
+        //Then
29
+        Assert.assertEquals(expected,actual);
30
+
31
+    }
32
+    @Test
33
+    public  void playerStateTest(){
34
+        //Given
35
+        Player player = new Player("Bob", 5000);
36
+        String expected = "Highroller Bob has $5,000";
37
+        //When
38
+        String actual = player.getState();
39
+        //Then
40
+        Assert.assertEquals(expected,actual);
41
+    }
42
+
43
+    @Test
44
+    public void playerDefaultTest(){
45
+        //Given
46
+        Player player = new Player();
47
+        String expected = "Highroller Default has $10,000";
48
+        //When
49
+        String actual = player.getState();
50
+        //Then
51
+        Assert.assertEquals(expected,actual);
52
+    }
53
+}

+ 28
- 0
src/test/java/io/zipcoder/casino/RandomNumGenTest.java Wyświetl plik

@@ -0,0 +1,28 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.chancegames.chancegameutilities.RandomNumGen;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class RandomNumGenTest {
8
+
9
+    @Test
10
+    public void randomRouletteTest() {
11
+        RandomNumGen gen = new RandomNumGen();
12
+
13
+        int actual = gen.randomRoulette();
14
+
15
+        Assert.assertTrue(actual >= 0 && actual<= 37);
16
+    }
17
+
18
+    @Test
19
+    public void randomRouletteChangeTest() {
20
+        RandomNumGen gen = new RandomNumGen();
21
+
22
+        int first = gen.randomRoulette();
23
+        int second = gen.randomRoulette();
24
+
25
+        Assert.assertFalse(first == second);
26
+
27
+    }
28
+}

+ 179
- 0
src/test/java/io/zipcoder/casino/RouletteTest.java Wyświetl plik

@@ -0,0 +1,179 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+import io.zipcoder.casino.game.chancegames.chancegameutilities.RandomNumGen;
5
+import org.junit.Assert;
6
+import io.zipcoder.casino.game.Player;
7
+import io.zipcoder.casino.game.chancegames.Roulette;
8
+import org.junit.Before;
9
+import org.junit.Test;
10
+
11
+
12
+public class RouletteTest {
13
+    Player player;
14
+    MockRandom random;
15
+    Roulette test;
16
+
17
+    private class MockRandom extends RandomNumGen {
18
+        @Override
19
+        public int randomRoulette() {
20
+            return 1;
21
+        }
22
+    }
23
+
24
+    @Before
25
+    public void initialize() {
26
+        random = new MockRandom();
27
+        player = new Player();
28
+        test = new Roulette(player);
29
+        player.setBank(1000);
30
+    }
31
+
32
+    @Test
33
+    public void setGetNumResultTest() {
34
+
35
+        Roulette test = new Roulette(player);
36
+        test.setNumResult(1);
37
+
38
+        int expected = 1;
39
+        int actual = test.getNumResult();
40
+
41
+        Assert.assertEquals(expected, actual);
42
+
43
+
44
+    }
45
+
46
+    @Test
47
+    public void setGetColorResultTest() {
48
+        String expected = "Red";
49
+        test.setClrResult("Red");
50
+        String actual = test.getClrResult();
51
+
52
+        Assert.assertEquals(expected, actual);
53
+
54
+    }
55
+
56
+    @Test
57
+    public void setGetNumGuessTest() {
58
+        int expected = 10;
59
+        test.setNumGuess(10);
60
+
61
+        int actual = test.getNumGuess();
62
+
63
+
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void setGetClrGuessTest() {
69
+        String expected = "Black";
70
+        test.setClrGuess("Black");
71
+
72
+        String actual = test.getClrGuess();
73
+
74
+        Assert.assertEquals(expected, actual);
75
+
76
+    }
77
+
78
+    @Test
79
+    public void setGetBetAmountTest() {
80
+        int expected = 100;
81
+        test.setBetAmount(100);
82
+
83
+        int actual = test.getBetAmount();
84
+
85
+        Assert.assertEquals(expected, actual);
86
+    }
87
+
88
+    @Test
89
+    public void compareNumbersTest01() {
90
+        test.setNumResult(10);
91
+
92
+        boolean actual = test.compareNumbers(10);
93
+
94
+        Assert.assertTrue(actual);
95
+
96
+    }
97
+
98
+    @Test
99
+    public void compareNumbersTest02() {
100
+        test.setNumResult(100);
101
+
102
+        boolean actual = test.compareNumbers(10);
103
+
104
+        Assert.assertFalse(actual);
105
+
106
+    }
107
+
108
+    @Test
109
+    public void compareBlckRd01() {
110
+        test.setClrResult("Black");
111
+
112
+        boolean actual = test.compareBlckRd("Black");
113
+
114
+        Assert.assertTrue(actual);
115
+    }
116
+
117
+    @Test
118
+    public void compareBlckRd02() {
119
+        test.setClrResult("Red");
120
+
121
+        boolean actual = test.compareBlckRd("Black");
122
+
123
+        Assert.assertFalse(actual);
124
+    }
125
+
126
+    @Test
127
+    public void betMultiplierTest() {
128
+        test.setBetAmount(5);
129
+        int expected = 500;
130
+        int actual = test.bet(100);
131
+
132
+        Assert.assertEquals(expected, actual);
133
+
134
+    }
135
+
136
+    @Test
137
+    public void lossTest() {
138
+       int expected = 900;
139
+       test.loss(100);
140
+
141
+       int actual = player.getBank();
142
+
143
+       Assert.assertEquals(expected, actual);
144
+
145
+    }
146
+
147
+    @Test
148
+    public void winTest() {
149
+        int expected = 1100;
150
+
151
+        test.win(100);
152
+        int actual = player.getBank();
153
+
154
+        Assert.assertEquals(expected, actual);
155
+    }
156
+
157
+    @Test
158
+    public void getResultNumTest() {
159
+        test.getResult(random);
160
+        int expected = 1;
161
+
162
+        int actual = test.getNumResult();
163
+
164
+        Assert.assertEquals(expected, actual);
165
+
166
+    }
167
+
168
+    @Test
169
+    public void getResultClrTest02() {
170
+        test.getResult(random);
171
+        String expected = "Red";
172
+
173
+        String actual = test.getClrResult();
174
+
175
+        Assert.assertEquals(expected, actual);
176
+
177
+    }
178
+    
179
+}

+ 36
- 0
src/test/java/io/zipcoder/casino/RouletteWheelTest.java Wyświetl plik

@@ -0,0 +1,36 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.chancegames.chancegameutilities.RouletteWheel;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+import java.util.HashMap;
8
+import java.util.Map;
9
+
10
+public class RouletteWheelTest {
11
+
12
+    @Test
13
+    public void getWheelSizeTest() {
14
+
15
+    RouletteWheel wheelTest = new RouletteWheel();
16
+
17
+    int expected = 37;
18
+    int actual = wheelTest.getWheelSize();
19
+
20
+    Assert.assertEquals(expected, actual);
21
+}
22
+
23
+    @Test
24
+    public void getWheelTest() {
25
+        Map<Integer, String> test = new HashMap<>();
26
+        test.put(1, "black");
27
+        test.put(2, "red");
28
+        RouletteWheel wheelTest = new RouletteWheel(test);
29
+
30
+        int expected = test.size();
31
+        int actual = wheelTest.getWheelSize();
32
+
33
+        Assert.assertEquals(expected, actual);
34
+
35
+    }
36
+}

+ 91
- 0
src/test/java/io/zipcoder/casino/SlotsTest.java Wyświetl plik

@@ -0,0 +1,91 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+import io.zipcoder.casino.game.chancegames.Slots;
5
+import org.junit.Assert;
6
+import org.junit.Before;
7
+import org.junit.Test;
8
+
9
+public class SlotsTest {
10
+    Slots slots;
11
+    Player player;
12
+    int slotsArr[];
13
+    @Before
14
+    public void setup(){
15
+        player = new Player();
16
+        slots = new Slots(player);
17
+    }
18
+
19
+    @Test
20
+    public void testPlay(){
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testSpin(){
26
+
27
+        slots.spin();
28
+
29
+       //System.out.println(slots.getSlots()[0]);
30
+
31
+        Assert.assertTrue(slots.getSlots()[0] > 0 && slots.getSlots()[0] < 8);
32
+    }
33
+
34
+    @Test
35
+    public void testCheckWin(){
36
+        slotsArr = new int[3];
37
+        //when all the three slots have same value
38
+        slotsArr[0] = 2;
39
+        slotsArr[1] = 2;
40
+        slotsArr[2] = 2;
41
+
42
+        slots.setSlots(slotsArr);
43
+        slots.bet(3);
44
+        int actual = slots.checkMatching(3);
45
+        int expectedAmount = 9;
46
+        Assert.assertEquals(expectedAmount, actual);
47
+    }
48
+
49
+    @Test
50
+    public void testCheckTwoMatching(){
51
+        slotsArr = new int[3];
52
+        //when all the three slots have same value
53
+        slotsArr[0] = 1;
54
+        slotsArr[1] = 1;
55
+        slotsArr[2] = 9;
56
+        slots.setSlots(slotsArr);
57
+        int actual = slots.checkMatching(2);
58
+        int expectedAmount = 4;
59
+        Assert.assertEquals(expectedAmount, actual);
60
+    }
61
+
62
+    @Test
63
+    public void testCheckNoMatching(){
64
+        slotsArr = new int[3];
65
+        //when all the three slots have same value
66
+        slotsArr[0] = 4;
67
+        slotsArr[1] = 6;
68
+        slotsArr[2] = 9;
69
+        slots.setSlots(slotsArr);
70
+        int actual = slots.checkMatching(2);
71
+        int expectedAmount = 2;
72
+        Assert.assertEquals(expectedAmount, actual);
73
+    }
74
+
75
+    @Test
76
+    public void testResult(){
77
+
78
+    }
79
+
80
+    @Test
81
+    public void testGetSlots(){
82
+        int slotsArr[] = slots.getSlots();
83
+        Assert.assertTrue(slotsArr.length == 3);
84
+    }
85
+
86
+    @Test
87
+    public void testEndGame(){
88
+
89
+    }
90
+
91
+}

+ 254
- 0
src/test/java/io/zipcoder/casino/game/cardgames/individualcardgames/GoFishTest.java Wyświetl plik

@@ -0,0 +1,254 @@
1
+package io.zipcoder.casino.game.cardgames.individualcardgames;
2
+
3
+import io.zipcoder.casino.game.Player;
4
+import org.junit.Assert;
5
+import org.junit.Rule;
6
+import org.junit.Test;
7
+
8
+import org.junit.contrib.java.lang.system.SystemOutRule;
9
+
10
+public class GoFishTest {
11
+    Player player;
12
+    GoFish goFishTest;
13
+    public GoFishTest() {
14
+        player = new Player();
15
+        goFishTest = new GoFish(player);
16
+    }
17
+
18
+    /* Test Section : Setters and Getters */
19
+    @Test
20
+    public void testSetPlayerBookTrue() {
21
+
22
+        int expectedBookCount = 1;
23
+
24
+        goFishTest.setPlayerBook(1);
25
+
26
+        int actualBookCount = goFishTest.getPlayerBook();
27
+
28
+        Assert.assertEquals(expectedBookCount, actualBookCount);
29
+    }
30
+
31
+    @Test
32
+    public void testSetPlayerBookFalse() {
33
+        int expectedBookCount = 1;
34
+
35
+        goFishTest.setPlayerBook(18);
36
+
37
+        int actualBookCount = goFishTest.getPlayerBook();
38
+
39
+        Assert.assertNotEquals(expectedBookCount, actualBookCount);
40
+
41
+    }
42
+
43
+    @Test
44
+    public void testSetOpponentBookTrue() {
45
+
46
+        int expectedBookCount = 1;
47
+
48
+        goFishTest.setOpponentBook(1);
49
+
50
+        int actualBookCount = goFishTest.getOpponentBook();
51
+
52
+        Assert.assertEquals(expectedBookCount, actualBookCount);
53
+
54
+    }
55
+
56
+    @Test
57
+    public void testSetOpponentBookFalse() {
58
+
59
+        int expectedBookCount = 1;
60
+
61
+        goFishTest.setPlayerBook(18);
62
+
63
+        int actualBookCount = goFishTest.getPlayerBook();
64
+
65
+        Assert.assertNotEquals(expectedBookCount, actualBookCount);
66
+
67
+    }
68
+
69
+    @Test
70
+    public void testSetPlayerTotalCards() {
71
+        int expectedTotalCards = 7;
72
+
73
+        goFishTest.setPlayerTotalCards(7);
74
+
75
+        int actualCardCount = goFishTest.getPlayerTotalCards();
76
+
77
+        Assert.assertEquals(expectedTotalCards, actualCardCount);
78
+
79
+    }
80
+
81
+    @Test
82
+    public void testSetOpponentTotalCards() {
83
+        int expectedTotalCards = 7;
84
+
85
+        goFishTest.setOpponentTotalCards(7);
86
+
87
+        int actualCardCount = goFishTest.getOpponentTotalCards();
88
+
89
+        Assert.assertEquals(expectedTotalCards, actualCardCount);
90
+
91
+    }
92
+
93
+    @Test
94
+    public void testIncrementPlayersBookOnce() {
95
+
96
+        int expectedTotalBooks = 2;
97
+
98
+        goFishTest.setPlayerBook(1);
99
+        goFishTest.incrementPlayersBook();
100
+
101
+        int actualCardCount = goFishTest.getPlayerBook();
102
+
103
+        Assert.assertEquals(expectedTotalBooks, actualCardCount);
104
+
105
+    }
106
+
107
+    @Test
108
+    public void testIncrementPlayersBook10Times() {
109
+
110
+        int expectedTotalBooks = 10;
111
+
112
+        for (int i = 0; i < 10; i++) {
113
+            goFishTest.incrementPlayersBook();
114
+        }
115
+
116
+        int actualCardCount = goFishTest.getPlayerBook();
117
+
118
+        Assert.assertEquals(expectedTotalBooks, actualCardCount);
119
+
120
+    }
121
+
122
+    @Test
123
+    public void testIncrementOpponentBookOnce() {
124
+        int expectedTotalBooks = 2;
125
+
126
+        goFishTest.setOpponentBook(1);
127
+        goFishTest.incrementOpponentBook();
128
+
129
+        int actualCardCount = goFishTest.getOpponentBook();
130
+
131
+        Assert.assertEquals(expectedTotalBooks, actualCardCount);
132
+
133
+    }
134
+
135
+    @Test
136
+    public void testIncrementOpponentBook7Times() {
137
+
138
+        int expectedTotalBooks = 7;
139
+
140
+        for (int i = 0; i < 7; i++) {
141
+            goFishTest.incrementOpponentBook();
142
+        }
143
+
144
+        int actualCardCount = goFishTest.getOpponentBook();
145
+
146
+        Assert.assertEquals(expectedTotalBooks, actualCardCount);
147
+
148
+    }
149
+
150
+    @Test
151
+    public void testDecrementPlayerCards() {
152
+        int expectedTotalCards = 6;
153
+
154
+        goFishTest.setPlayerTotalCards(7);
155
+        goFishTest.decrementPlayersCards();
156
+
157
+        int actualCards = goFishTest.getPlayerTotalCards();
158
+
159
+        Assert.assertEquals(expectedTotalCards, actualCards);
160
+
161
+    }
162
+
163
+    @Test
164
+    public void testDecrementOpponentCards() {
165
+        int expectedTotalCards = 3;
166
+
167
+        goFishTest.setOpponentTotalCards(4);
168
+        goFishTest.decrementOpponentCards();
169
+
170
+        int actualCards = goFishTest.getOpponentTotalCards();
171
+
172
+        Assert.assertEquals(expectedTotalCards, actualCards);
173
+
174
+    }
175
+
176
+    @Test
177
+    public void testIncrementPlayersCards() {
178
+        int expectedTotalCards = 8;
179
+
180
+        goFishTest.setPlayerTotalCards(7);
181
+        goFishTest.incrementPlayersCards();
182
+
183
+        int actualCards = goFishTest.getPlayerTotalCards();
184
+
185
+        Assert.assertEquals(expectedTotalCards, actualCards);
186
+
187
+    }
188
+
189
+    @Test
190
+    public void testIncrementOpponentsCards() {
191
+        int expectedTotalCards = 5;
192
+
193
+        goFishTest.setOpponentTotalCards(4);
194
+        goFishTest.incrementOpponentCards();
195
+
196
+        int actualCards = goFishTest.getOpponentTotalCards();
197
+
198
+        Assert.assertEquals(expectedTotalCards, actualCards);
199
+
200
+    }
201
+
202
+    /* Combination Setters */
203
+
204
+    @Test
205
+    public void testPlayerTurnTrue() {
206
+        // Expect to increment players book by 1
207
+        // expect to decrement players cards by 2
208
+
209
+        int expectedCards = 3;
210
+        int expectedBooks = 1;
211
+
212
+        goFishTest.setPlayerTotalCards(5);
213
+
214
+        goFishTest.playerTurnTrue();
215
+
216
+        Assert.assertEquals(expectedCards, goFishTest.getPlayerTotalCards());
217
+        Assert.assertEquals(expectedBooks, goFishTest.getPlayerBook());
218
+
219
+    }
220
+
221
+    @Test
222
+    public void testOpponentTurnTrue() {
223
+
224
+        int expectedCards = 1;
225
+        int expectedBooks = 3;
226
+
227
+        goFishTest.setOpponentTotalCards(7);
228
+
229
+        for (int i = 0; i < 3; i++) {
230
+            goFishTest.opponentTurnTrue();
231
+        }
232
+
233
+        Assert.assertEquals(expectedCards, goFishTest.getOpponentTotalCards());
234
+        Assert.assertEquals(expectedBooks, goFishTest.getOpponentBook());
235
+
236
+    }
237
+
238
+    @Rule
239
+    public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
240
+
241
+    @Test
242
+    public void overrideProperty() {
243
+        System.out.print("hello world");
244
+        Assert.assertEquals("hello world", systemOutRule.getLog());
245
+    }
246
+
247
+    @Test
248
+    public void testPrintSortedHand() {
249
+
250
+        goFishTest.printSortedHand();
251
+
252
+
253
+    }
254
+}