Sfoglia il codice sorgente

Merge branch 'working' of https://git.zipcode.rocks/jonathan-hinds/ZCW-OOP-Casino into working

Jonathan Hinds 6 anni fa
parent
commit
92ad58c0d6

+ 0
- 1
.gitignore Vedi File

10
 .loadpath
10
 .loadpath
11
 .recommenders
11
 .recommenders
12
 .DS_Store
12
 .DS_Store
13
- f4be1dfe4483806d9dd9cf3b6546e184f84a5f1a
14
 
13
 
15
 # External tool builders
14
 # External tool builders
16
 .externalToolBuilders/
15
 .externalToolBuilders/

+ 0
- 1
src/main/java/io/zipcoder/casino/Casino.java Vedi File

2
 
2
 
3
 
3
 
4
 import java.util.ArrayList;
4
 import java.util.ArrayList;
5
-import java.util.InputMismatchException;
6
 
5
 
7
 public class Casino {
6
 public class Casino {
8
     public boolean running = true;
7
     public boolean running = true;

+ 13
- 1
src/main/java/io/zipcoder/casino/SlotMachine.java Vedi File

3
 import java.util.Random;
3
 import java.util.Random;
4
 
4
 
5
 public class SlotMachine implements Game, Gamble {
5
 public class SlotMachine implements Game, Gamble {
6
-    private int betAmount;
6
+    protected int betAmount;
7
     private int payoutAmt=0;
7
     private int payoutAmt=0;
8
     String word="";
8
     String word="";
9
     String outputword="";
9
     String outputword="";
22
 
22
 
23
     @Override
23
     @Override
24
     public void bet(int betAmount) {
24
     public void bet(int betAmount) {
25
+
26
+        this.betAmount= betAmount;
25
         player.changeBalance(-betAmount);
27
         player.changeBalance(-betAmount);
28
+
26
     }
29
     }
27
 
30
 
28
     public void payout(){
31
     public void payout(){
47
     public void generateWords() {
50
     public void generateWords() {
48
         Random rand = new Random();
51
         Random rand = new Random();
49
 
52
 
53
+        generateWords(rand);
54
+
55
+    }
56
+
57
+    protected void generateWords(Random rand) {
50
         for (int i = 1; i <= 3; i++) {
58
         for (int i = 1; i <= 3; i++) {
51
             int randnum = rand.nextInt(6);
59
             int randnum = rand.nextInt(6);
52
 
60
 
79
                 word3 = word;
87
                 word3 = word;
80
             }
88
             }
81
         }
89
         }
90
+
82
         outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
91
         outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
92
+
83
     }
93
     }
84
 
94
 
85
     public void slotResult()
95
     public void slotResult()
122
     }
132
     }
123
 
133
 
124
     public int getPayoutAmt() {
134
     public int getPayoutAmt() {
135
+
125
         return payoutAmt;
136
         return payoutAmt;
126
     }
137
     }
127
 
138
 
130
     }
141
     }
131
 
142
 
132
     public void setWord1(String word1) {
143
     public void setWord1(String word1) {
144
+
133
         this.word1 = word1;
145
         this.word1 = word1;
134
     }
146
     }
135
 
147
 

+ 35
- 6
src/test/java/io/zipcoder/casino/SlotTest.java Vedi File

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 
3
 
4
+import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 import org.junit.Assert;
6
 import org.junit.Assert;
7
+import java.util.Random;
6
 
8
 
7
-import java.io.ByteArrayInputStream;
8
-import java.util.NoSuchElementException;
9
-import java.util.Scanner;
10
 
9
 
11
 
10
 
12
 public class SlotTest {
11
 public class SlotTest {
12
+    private int betAmount = 10;
13
+    private SlotMachine slotmachine = new SlotMachine(betAmount);
13
 
14
 
14
     Player player = new Player("Bob", 400);
15
     Player player = new Player("Bob", 400);
15
 
16
 
16
     @Test
17
     @Test
17
     public void testSlotResult1(){
18
     public void testSlotResult1(){
18
-        int betAmount=10;
19
         String word1="MOUSE";
19
         String word1="MOUSE";
20
         String word2="MOUSE";
20
         String word2="MOUSE";
21
         String word3="MOUSE";
21
         String word3="MOUSE";
33
 
33
 
34
     @Test
34
     @Test
35
     public void testSlotResult2(){
35
     public void testSlotResult2(){
36
-        int betAmount=10;
37
         String word1="MOUSE";
36
         String word1="MOUSE";
38
         String word2="MOUSE";
37
         String word2="MOUSE";
39
         String word3="CAT";
38
         String word3="CAT";
41
 
40
 
42
         //given
41
         //given
43
         SlotMachine slotmachine = new SlotMachine(betAmount, player);
42
         SlotMachine slotmachine = new SlotMachine(betAmount, player);
44
-
45
         slotmachine.setWord1(word1);
43
         slotmachine.setWord1(word1);
46
         slotmachine.setWord2(word2);
44
         slotmachine.setWord2(word2);
47
         slotmachine.setWord3(word3);
45
         slotmachine.setWord3(word3);
120
 
118
 
121
 
119
 
122
     }
120
     }
121
+
122
+    @Test
123
+    public void testSetBetAmount(){
124
+        int betAmount=10;
125
+        SlotMachine slotmachine = new SlotMachine(betAmount);
126
+
127
+        int newBet = 40;
128
+
129
+        slotmachine.bet(newBet);
130
+
131
+        int actual = slotmachine.betAmount;
132
+
133
+        Assert.assertEquals(newBet, actual);
134
+
135
+    }
136
+
137
+    @Test
138
+    public void testGenerateWords2(){
139
+        Random random = new Random(1);
140
+
141
+
142
+        String expectedWord1 = "SQUIRREL";
143
+        String expectedWord2 = "FISH";
144
+        String expectedWord3 = "CAT";
145
+
146
+        slotmachine.generateWords(random);
147
+
148
+        Assert.assertEquals(expectedWord1, slotmachine.word1);
149
+
150
+    }
151
+
123
 }
152
 }

+ 26
- 70
src/test/java/io/zipcoder/casino/StudTest.java Vedi File

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Before;
4
 import org.junit.Before;
5
 import org.junit.Test;
5
 import org.junit.Test;
6
-
7
-import java.io.ByteArrayInputStream;
8
 import java.util.ArrayList;
6
 import java.util.ArrayList;
9
-import java.util.NoSuchElementException;
10
-import java.util.Scanner;
11
 
7
 
12
 public class StudTest {
8
 public class StudTest {
13
 
9
 
243
         Assert.assertEquals(expected, actual);
239
         Assert.assertEquals(expected, actual);
244
     }
240
     }
245
 
241
 
242
+<<<<<<< HEAD
243
+=======
246
     @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
244
     @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
247
     public void payAnteTest(){
245
     public void payAnteTest(){
248
        stud.payAnte(stud.getPlayers());
246
        stud.payAnte(stud.getPlayers());
251
        Assert.assertEquals(expect, actual);
249
        Assert.assertEquals(expect, actual);
252
     }
250
     }
253
 
251
 
252
+>>>>>>> abcff63819ca0f646e4e501b1afae90ab549a292
254
     @Test
253
     @Test
255
     public void playCardTest(){
254
     public void playCardTest(){
256
         stud.playCard(cardPlayer1.getPlayer(), cardPlayer1.getHand().get(0));
255
         stud.playCard(cardPlayer1.getPlayer(), cardPlayer1.getHand().get(0));
272
 
271
 
273
         Assert.assertEquals(expected, actual);
272
         Assert.assertEquals(expected, actual);
274
     }
273
     }
274
+<<<<<<< HEAD
275
+=======
275
 
276
 
276
     @Test
277
     @Test
277
     public void testStartRound(){
278
     public void testStartRound(){
292
 }
293
 }
293
 /*
294
 /*
294
     CODE FOR TRASH PANDAS
295
     CODE FOR TRASH PANDAS
296
+>>>>>>> abcff63819ca0f646e4e501b1afae90ab549a292
295
 
297
 
296
     @Test
298
     @Test
297
-    public void flipCardTest(){
298
-        stud.deal();
299
+    public void tableTest(){
300
+        stud.changeTablePot(10);
299
         //WHEN @Before
301
         //WHEN @Before
300
-        boolean expected = false;
302
+        int expected = 10;
301
         //THEN
303
         //THEN
302
-        boolean actual = stud.flipCard();
304
+        int actual = stud.getTablePot();
303
 
305
 
304
         Assert.assertEquals(expected, actual);
306
         Assert.assertEquals(expected, actual);
305
     }
307
     }
306
 
308
 
307
-    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
308
-        int max = 0;
309
-        CardPlayer winner = null;
310
-
311
-        for(int i = 0; i < players.size(); i ++){
312
-            CardPlayer player = players.get(i);
313
-            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
314
-            if(playerHandValue > max){
315
-                max = playerHandValue;
316
-                winner = player;
317
-            }
318
-        }
319
-        System.out.println("The winner is " + winner.getPlayer().getName());
320
-        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
321
-                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
322
-        return winner;
323
-    }
324
-
325
-        public CardPlayer determineWinner(){
326
-        int max = 0;
327
-        CardPlayer winner = null;
328
-
329
-        for(int i = 0; i < getPlayers().size(); i ++){
330
-            CardPlayer player = getPlayers().get(i);
331
-            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
332
-            if(playerHandValue > max){
333
-                max = playerHandValue;
334
-                winner = player;
335
-            }
336
-        }
337
-        System.out.println("The winner is " + winner.getPlayer().getName());
338
-        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
339
-                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
340
-        return winner;
341
-    }
342
-
343
-        public void startRound() {
344
-        System.out.println("Welcome to Three Card Stud! Cards are dealt!");
345
-        flipCard();
346
-        gameRound();
347
-        flipCard();
348
-        gameRound2();
349
-        flipCard();
350
-        lastGameRound();
351
-        determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
352
-    }
309
+    @Test
310
+    public void setHandSizeTest(){
311
+        stud.setHandSize(5);
312
+        //WHEN @Before
313
+        int expected = 5;
314
+        //THEN
315
+        int actual = stud.getHandSize();
353
 
316
 
354
-    /*
355
-    public void payAnte() {
356
-        for(int i = 0; i < super.getPlayers().size(); i ++)
357
-        {
358
-            CardPlayer player = super.getPlayers().get(i);
359
-            player.getPlayer().changeBalance(-super.getAnte());
360
-        }
317
+        Assert.assertEquals(expected, actual);
361
     }
318
     }
362
 
319
 
363
-     * PreCondition: Betting rounds already played
364
-     * Plays through round that include flipping last card face up
365
-     * PostCondtion: tablePot is now at max value
366
-     * DetermineWinner() expected to be called after this method
320
+    @Test
321
+    public void setPlayersTurnTest(){
322
+        stud.setPlayersTurn(cardPlayer1);
323
+        //WHEN @Before
324
+        CardPlayer expected = cardPlayer1;
325
+        //THEN
326
+        CardPlayer actual = stud.getPlayersTurn();
367
 
327
 
368
-public void lastGameRound(){
369
-    for (int j = 0; j < getPlayers().size(); j++) {
370
-        CardPlayer player = super.getPlayers().get(j);              //GET a player
371
-        playCard(player.getPlayer(), player.getHand().get(2));      //SHOW-PRINT players first CARD
328
+        Assert.assertEquals(expected, actual);
372
     }
329
     }
373
 }
330
 }
374
-*/