Vincent Sima před 6 roky
rodič
revize
025b9ff59c

binární
.DS_Store Zobrazit soubor


binární
src/.DS_Store Zobrazit soubor


binární
src/main/.DS_Store Zobrazit soubor


binární
src/main/java/.DS_Store Zobrazit soubor


binární
src/main/java/io/.DS_Store Zobrazit soubor


binární
src/main/java/io/zipcoder/.DS_Store Zobrazit soubor


+ 30
- 36
src/main/java/io/zipcoder/casino/CardGame.java Zobrazit soubor

@@ -2,44 +2,38 @@ package io.zipcoder.casino;
2 2
 
3 3
 public abstract class CardGame implements Game, Gamble {
4 4
 
5
-//    int playerHand;
6
-//    int dealerHand;
7
-//    int currentBet;
8
-//    Player player;
9
-//    CardDeck deck;
10
-//
11
-//    public CardGame(Player player) {
12
-//
13
-//        this.player = player;
14
-//        this.deck = new deck();
15
-//
16
-//    }
17
-//
18
-//
19
-//    public int drawCard() {
20
-//
21
-//
22
-//    }
23
-//
24
-//    public void stand() {
25
-//
26
-//    }
27
-//
28
-//    void startGame();
29
-//
30
-//    void endGame();
31
-//
32
-//    void declareWinner();
33
-//
34
-//    void bet(int currentBet) {
35
-//
36
-//    }
37
-//    void winBet() {
38
-//
39
-//    }
40
-//    void loseBet(Player player) {
5
+
6
+    int playerHand;
7
+    int dealerHand;
8
+    int currentBet;
9
+    Player player;
10
+    CardDeck deck;
11
+
12
+    public CardGame(Player player) {
13
+
14
+        this.player = player;
15
+        this.deck = new CardDeck();
41 16
 
42 17
     }
43 18
 
44 19
 
20
+    public abstract int drawCard();
21
+
22
+    public abstract void stand();
23
+
24
+    public abstract void startGame();
25
+
26
+    public abstract void endGame();
27
+
28
+    public abstract void declareWinner();
29
+
30
+    public abstract void winBet();
31
+    
32
+    public abstract void loseBet(Player player);
33
+
34
+
35
+
36
+}
37
+
38
+
45 39
 

+ 6
- 0
src/main/java/io/zipcoder/casino/Console.java Zobrazit soubor

@@ -19,6 +19,12 @@ public class Console {
19 19
         return scan.nextLine().toLowerCase();
20 20
     }
21 21
 
22
+    public static int askForInteger(String thingToAsk) {
23
+        System.out.println(thingToAsk);
24
+        Scanner scan = new Scanner(System.in);
25
+        return Integer.valueOf(scan.nextLine());
26
+    }
27
+
22 28
     public static String output(String output) {
23 29
         System.out.println(output);
24 30
         return output;

+ 26
- 0
src/main/java/io/zipcoder/casino/DiceGame.java Zobrazit soubor

@@ -0,0 +1,26 @@
1
+package io.zipcoder.casino;
2
+
3
+public abstract class DiceGame implements Gamble, Game{
4
+
5
+//    Player player;
6
+//    Dice dice;
7
+//
8
+//    public DiceGame(Player player, int numberOfDice) {
9
+//
10
+//        this.player = player;
11
+//        this.dice = new Dice(numberOfDice);
12
+//    }
13
+
14
+
15
+    public abstract void startGame();
16
+
17
+    public abstract void endGame();
18
+
19
+    public abstract int rollDice();
20
+
21
+    public abstract void winBet();
22
+
23
+    public abstract void loseBet();
24
+
25
+    public abstract void declareWinner();
26
+}

+ 109
- 0
src/main/java/io/zipcoder/casino/HighLow.java Zobrazit soubor

@@ -0,0 +1,109 @@
1
+package io.zipcoder.casino;
2
+
3
+public class HighLow extends DiceGame{
4
+    private Player player;
5
+    private boolean isPlaying = true;
6
+    private int rolledDiceResult;
7
+    private int totalBet;
8
+    private String betCondition;
9
+    private int winnings;
10
+
11
+    public HighLow(Player player) {
12
+        this.player = player;
13
+    }
14
+
15
+    private int askForWager() {
16
+        int wager = 0;
17
+        boolean flag = true;
18
+        Console.output("Current bankroll: " + this.player.getBankroll());
19
+        while (flag) {
20
+            try {
21
+                wager = Console.askForInteger("How much would you like to bet?");
22
+                if (wager <= 0 || wager > this.player.getBankroll()) {
23
+                    Console.output("Wrong input! Try again!");
24
+                } else {
25
+                    flag = false;
26
+                }
27
+            } catch(NumberFormatException e) {
28
+                Console.output("Wrong input! Try again!");
29
+            }
30
+        }
31
+        this.player.subtractFromBankroll(wager);
32
+        return wager;
33
+    }
34
+
35
+    public String makeBet() {
36
+        betCondition = Console.askForInput("What are you betting on?  (H / L / 7)");
37
+        if (betCondition.toLowerCase().equals("h") ||
38
+            betCondition.toLowerCase().equals("l") ||
39
+            betCondition.toLowerCase().equals("7")) {
40
+                return betCondition;
41
+        }
42
+        Console.output("Wrong input. Please try again");
43
+        return makeBet();
44
+    }
45
+
46
+    public int rollDice() {
47
+        Dice dice = new Dice(2);
48
+        rolledDiceResult = dice.getSum();
49
+        Console.output("You rolled " + rolledDiceResult);
50
+        return rolledDiceResult;
51
+    }
52
+
53
+    public void declareWinner() {
54
+        if ((betCondition.toUpperCase().equals("H") && rolledDiceResult >  7) ||
55
+                (betCondition.toUpperCase().equals("L") && rolledDiceResult <  7) ||
56
+                (betCondition.toUpperCase().equals("7") && rolledDiceResult == 7)) {
57
+            winnings = rolledDiceResult == 7 ? this.totalBet * 4 : this.totalBet * 2;
58
+            winBet();
59
+        } else {
60
+            loseBet();
61
+        }
62
+    }
63
+
64
+    public boolean askToContinue() {
65
+        if (this.player.getBankroll() == 0) {
66
+            Console.output("You're bankrupt! Please come back after pay day!");
67
+            return false;
68
+        }
69
+        String input = Console.askForInput("Would you like to continue?  (Y / N)");
70
+        if (input.toLowerCase().equals("y")) {
71
+            return true;
72
+        } else if (input.toLowerCase().equals("n")) {
73
+            return false;
74
+        }
75
+        Console.output("Wrong input. Please try again");
76
+        return askToContinue();
77
+    }
78
+
79
+    public void winBet() {
80
+        player.addToBankroll(winnings);
81
+        Console.output("You won " + winnings);
82
+    }
83
+
84
+    public void loseBet() {
85
+        Console.output("You lost :(");
86
+    }
87
+
88
+    public void startGame() {
89
+        Console.output("You're playing High-Low dice game");
90
+        while (isPlaying) {
91
+            totalBet         = askForWager();
92
+            betCondition     = makeBet();
93
+            rolledDiceResult = rollDice();
94
+            declareWinner();
95
+            isPlaying        = askToContinue();
96
+        }
97
+       // endGame();
98
+    }
99
+
100
+    public void endGame() {
101
+        //???
102
+    }
103
+
104
+    public static void main (String[] args) {
105
+        Player player = new Player("Francis");
106
+        DiceGame app = new HighLow(player);
107
+        app.startGame();
108
+    }
109
+}

+ 43
- 0
src/test/java/io/zipcoder/casino/DiceTest.java Zobrazit soubor

@@ -1,3 +1,4 @@
1
+<<<<<<< HEAD
1 2
 //package io.zipcoder.casino;
2 3
 //
3 4
 //import org.junit.Assert;
@@ -39,3 +40,45 @@
39 40
 //        Assert.assertEquals(expected, actual, 3);
40 41
 //    }
41 42
 //}
43
+=======
44
+package io.zipcoder.casino;
45
+
46
+import org.junit.Assert;
47
+import org.junit.Before;
48
+import org.junit.Test;
49
+
50
+public class DiceTest {
51
+
52
+    @Test
53
+    public void getSumTest1(){
54
+        Dice dice = new Dice(2);
55
+        int expected = 6;
56
+        int actual = dice.getSum();
57
+        Assert.assertEquals(expected, actual, 6);
58
+    }
59
+
60
+    @Test
61
+    public void getSumTest2(){
62
+        Dice dice = new Dice(5);
63
+        int expected = 13;
64
+        int actual = dice.getSum();
65
+        Assert.assertEquals(expected, actual, 12);
66
+    }
67
+
68
+    @Test
69
+    public void getEachTest1(){
70
+        Dice dice = new Dice(2);
71
+        int expected = 3;
72
+        int actual = dice.getEach()[1];
73
+        Assert.assertEquals(expected, actual, 3);
74
+    }
75
+
76
+    @Test
77
+    public void getEachTest2(){
78
+        Dice dice = new Dice(6);
79
+        int expected = 3;
80
+        int actual = dice.getEach()[3];
81
+        Assert.assertEquals(expected, actual, 3);
82
+    }
83
+}
84
+>>>>>>> origin/dev

+ 19
- 0
src/test/java/io/zipcoder/casino/HighLowTest.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class HighLowTest {
7
+
8
+    Player player = new Player("Eug");
9
+    HighLow game = new HighLow(player);
10
+
11
+    @Test
12
+    public void rollDice1(){
13
+        int expected = 6;
14
+        int actual = game.rollDice();
15
+        Assert.assertEquals(expected, actual, 6);
16
+    }
17
+
18
+
19
+}