Lauren Green před 6 roky
rodič
revize
3b592cab61

+ 16
- 11
src/main/java/io/zipcoder/casino/SlotMachine.java Zobrazit soubor

41
         }
41
         }
42
         Printer.printMessage("Your slot is in progress" + "\n");
42
         Printer.printMessage("Your slot is in progress" + "\n");
43
 
43
 
44
-        try {
45
-            Thread.sleep(3000);
46
-        } catch (InterruptedException e) {
47
-            e.printStackTrace();
48
-        }
49
-
50
-        generateWords();
51
-
44
+        startRound();
52
     }
45
     }
53
 
46
 
54
     public void generateWords() {
47
     public void generateWords() {
94
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
87
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
95
 
88
 
96
                 outputword= outputword + "\n"+" You have won $0";
89
                 outputword= outputword + "\n"+" You have won $0";
97
-                payoutAmt=0;
90
+                setPayoutAmt(0);
98
             }
91
             }
99
             else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
92
             else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
100
 
93
 
101
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
94
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
102
-                payoutAmt=betAmount*2;
95
+                setPayoutAmt(betAmount*2);
103
             }
96
             }
104
 
97
 
105
 
98
 
106
             else if(word1.equals(word2) && word1.equals(word3)) {
99
             else if(word1.equals(word2) && word1.equals(word3)) {
107
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
100
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
108
-                payoutAmt=betAmount*3;
101
+                setPayoutAmt(betAmount*3);
109
             }
102
             }
110
 
103
 
111
             Printer.printMessage(( outputword + "\n" ));
104
             Printer.printMessage(( outputword + "\n" ));
119
 
112
 
120
     @Override
113
     @Override
121
     public void startRound() {
114
     public void startRound() {
115
+        try {
116
+            Thread.sleep(3000);
117
+        } catch (InterruptedException e) {
118
+            e.printStackTrace();
119
+        }
122
 
120
 
121
+        generateWords();
123
     }
122
     }
123
+
124
     public int getPayoutAmt() {
124
     public int getPayoutAmt() {
125
         return payoutAmt;
125
         return payoutAmt;
126
     }
126
     }
127
+
128
+    public void setPayoutAmt(int payoutAmt) {
129
+        this.payoutAmt = payoutAmt;
130
+    }
131
+
127
     public void setWord1(String word1) {
132
     public void setWord1(String word1) {
128
         this.word1 = word1;
133
         this.word1 = word1;
129
     }
134
     }

+ 18
- 0
src/test/java/io/zipcoder/casino/SlotTest.java Zobrazit soubor

98
 
98
 
99
 
99
 
100
     }
100
     }
101
+
102
+    @Test
103
+    public void testPayout() {
104
+        //Given
105
+        SlotMachine game = new SlotMachine(100, player);
106
+        int expected = 500;
107
+
108
+        //When
109
+        game.bet(100);
110
+        game.setPayoutAmt(200);
111
+        game.payout();
112
+        int actual = game.getPlayer().getCurrentBalance();
113
+
114
+        //Then
115
+        Assert.assertEquals(expected, actual);
116
+
117
+
118
+    }
101
 }
119
 }