Bläddra i källkod

Added Solitare Foundation and SLOTS

Nathan Hall 6 år sedan
förälder
incheckning
0951c9e7db

+ 72
- 3
src/main/java/io/zipcoder/casino/CardGame/Solitaire/Foundation.java Visa fil

@@ -1,15 +1,84 @@
1 1
 package io.zipcoder.casino.CardGame.Solitaire;
2 2
 
3 3
 import io.zipcoder.casino.CardGame.Card;
4
+import io.zipcoder.casino.CardGame.Deck;
5
+import io.zipcoder.casino.CardGame.Face;
6
+import io.zipcoder.casino.CardGame.Suit;
4 7
 
5 8
 import java.util.Stack;
6 9
 
7 10
 public class Foundation {
8 11
 
9
-    private Stack stack;
12
+    public Stack<Card> tempStack = new Stack<>();
13
+    public Stack<Card> clubStack = new Stack<>();
14
+    public Stack<Card> diamondStack = new Stack<>();
15
+    public Stack<Card> heartStack = new Stack<>();
16
+    public Stack<Card> spadeStack = new Stack<>();
17
+
18
+
19
+    public Foundation() {
20
+
21
+        this.tempStack = new Stack<>();
22
+    }
23
+
24
+    Tableau tab = new Tableau();
25
+    Deck deck = new Deck();
26
+    Card card;
27
+
28
+
29
+    public void whichSuit(Stack<Card> tempStackCard) {
30
+
31
+        if (tempStackCard.peek().getSuit() == Suit.CLUBS) {
32
+            //Checks if the Clubs Foundation is Empty
33
+            if (clubStack.empty() && tempStackCard.peek().getFace() == Face.ACE) {
34
+                clubStack.push(tempStackCard.peek());
35
+            }
36
+            //Checks if the Temp Card is 1 more than what
37
+            // is on the Foundation
38
+
39
+            if (tempStackCard.peek().getFace().getPrimaryValue() == clubStack.peek().getFace().getPrimaryValue() + 1) {
40
+                clubStack.push(tempStackCard.peek());
41
+
42
+            }
43
+        }
44
+
45
+        if (tempStackCard.peek().getSuit() == Suit.DIAMONDS) {
46
+
47
+            //Checks if the Diamonds Foundation is Empty
48
+            if (diamondStack.empty() && tempStackCard.peek().getFace() == Face.ACE) {
49
+                diamondStack.push(tempStackCard.peek());
50
+            }
51
+            //Checks if the Temp Card is 1 more than what
52
+            // is on the Foundation
53
+            if (tempStackCard.peek().getFace().getPrimaryValue() == diamondStack.peek().getFace().getPrimaryValue() + 1) {
54
+                diamondStack.push(tempStackCard.peek());
55
+            }
56
+        }
57
+
58
+        if (tempStackCard.peek().getSuit() == Suit.HEARTS) {
59
+
60
+            //Checks if the Heart Foundation is Empty
61
+            if (heartStack.empty() && tempStackCard.peek().getFace() == Face.ACE) {
62
+                heartStack.push(tempStackCard.peek());
63
+            }
64
+            //Checks if the Temp Card is 1 more than what
65
+            // is on the Foundation
66
+            if (tempStackCard.peek().getFace().getPrimaryValue() == heartStack.peek().getFace().getPrimaryValue() + 1) {
67
+                heartStack.push(tempStackCard.peek());
68
+            }
69
+        }
70
+
71
+        if (tempStackCard.peek().getSuit() == Suit.SPADES) {
72
+
73
+
74
+            if (spadeStack.empty() && tempStackCard.peek().getFace() == Face.ACE) {
75
+                spadeStack.push(tempStackCard.peek());
76
+            }
77
+            if (tempStackCard.peek().getFace().getPrimaryValue() == spadeStack.peek().getFace().getPrimaryValue() + 1) {
78
+                spadeStack.push(tempStackCard.peek());
79
+            }
80
+        }
10 81
 
11
-    public Foundation(){
12
-        this.stack = new Stack<Card>();
13 82
     }
14 83
 
15 84
 

+ 88
- 0
src/main/java/io/zipcoder/casino/Slots.java Visa fil

@@ -0,0 +1,88 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Slots {
4
+
5
+    String[] reels = new String[5];
6
+    String[] names = {"♡","♢", "♤",
7
+            "♧", "♬", "WIN", "♡","♢", "♤",
8
+            "♧", "♬", "Kris", "Nhu", "Froilan",
9
+            "Dolio",
10
+            "Leon", "Wilhem", "WOW", "ZCW" };
11
+
12
+    public Slots() {
13
+        int bet;
14
+
15
+    }
16
+
17
+    public void FillReels(int bet){
18
+        int win = 0;
19
+        int zcw = 0;
20
+        int getAll = 0;
21
+        int payOut = 0;
22
+        printScreen1();
23
+        System.out.print("///\t\t\t|");
24
+        for(int i = 0; i < reels.length; i++){
25
+            reels[i] = names[(int)(Math.random() * 19)];
26
+            if (reels[i] == "WIN"){
27
+                win++;
28
+            }
29
+            if (reels[i] == "ZCW"){
30
+                zcw++;
31
+            }
32
+
33
+            System.out.printf("| %8s |", reels[i]);
34
+            if (i == reels.length - 1){
35
+                System.out.println("|\t\t|\t\t///\t | |");
36
+            }
37
+        }
38
+
39
+            printScreen2();
40
+
41
+
42
+        payOut = amountWon(bet, win, zcw);
43
+
44
+        System.out.println("\t\t\t\t\t\t\t\t\tYour bet: " + bet + "CHIPS");
45
+        if (payOut > 0) {
46
+            System.out.println("\t\t\t\t\t\t\t\t\tYOU WON: " + bet + "CHIPS");
47
+        }
48
+
49
+
50
+
51
+    }
52
+
53
+    private int amountWon(int bet, int win, int zcw) {
54
+        int payOut = 0;
55
+        int winTotal = bet * win;
56
+        int zcwTotal = (bet * 2) * zcw;
57
+        payOut = winTotal + payOut;
58
+        return payOut;
59
+    }
60
+
61
+    private void printScreen1() {
62
+        System.out.println(" ////////////////////////////////////////////////////////////////////////////////////////");
63
+        System.out.println("///																				        ///");
64
+        System.out.println("///								    THE THUNDER DOME							        ///");
65
+        System.out.println("///																				        ///");
66
+        System.out.println("///		    _____________________________________________________________________       ///  ___");
67
+        System.out.println("///		    |																	|	    /// (   )");
68
+        System.out.println("///		    |																	|	    ///	 | |");
69
+        System.out.println("///		    |																	|	    ///	 | |");
70
+
71
+    }
72
+
73
+    private void printScreen2() {
74
+        System.out.println("///		    |																	|	    ///__| |");
75
+        System.out.println("///		    |																	|	    ///____|");
76
+        System.out.println("///		    |___________________________________________________________________|	    ///");
77
+        System.out.println("///																	                    ///");																			///
78
+        System.out.println("///																                        ///");																			///
79
+        System.out.println(" /////    	 															            /////");																			///
80
+        System.out.println("  //////////////////////////////////////////////////////////////////////////////////////");
81
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
82
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
83
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
84
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
85
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
86
+        System.out.println("  /////////////////////////////////////////////////////////////////////////////////////");
87
+    }
88
+}

+ 204
- 0
src/test/java/io/zipcoder/casino/CardGame/Solitaire/FoundationTest.java Visa fil

@@ -0,0 +1,204 @@
1
+package io.zipcoder.casino.CardGame.Solitaire;
2
+
3
+import io.zipcoder.casino.CardGame.Card;
4
+import io.zipcoder.casino.CardGame.Deck;
5
+import io.zipcoder.casino.CardGame.Face;
6
+import io.zipcoder.casino.CardGame.Suit;
7
+import org.junit.Assert;
8
+import org.junit.Test;
9
+
10
+public class FoundationTest {
11
+
12
+
13
+
14
+    Foundation foundation = new Foundation();
15
+    Deck deck = new Deck();
16
+    Card card  = new Card(Suit.CLUBS, Face.QUEEN);
17
+
18
+    @Test
19
+    public void addKingToQueenOnClubStackTest() {
20
+        //GIVEN
21
+
22
+
23
+        Card chosen = deck.deckOfCards.pop();
24
+        foundation.tempStack.push(chosen);
25
+        foundation.clubStack.push(card);
26
+        foundation.whichSuit(foundation.tempStack);
27
+        //WHEN
28
+
29
+        Card expected = new Card(Suit.CLUBS, Face.KING);
30
+        Card actual = foundation.clubStack.peek();
31
+
32
+
33
+        //THEN
34
+        Assert.assertEquals(expected, actual);
35
+
36
+    }
37
+
38
+    @Test
39
+    public void addKingToQueenOfDiamondsStackTest() {
40
+        //GIVEN
41
+
42
+
43
+        Card tempCard  = new Card(Suit.DIAMONDS, Face.KING);
44
+        Card cardOnFoundation  = new Card(Suit.DIAMONDS,
45
+                Face.QUEEN);
46
+
47
+
48
+        foundation.tempStack.push(tempCard);
49
+        foundation.diamondStack.push(cardOnFoundation);
50
+        foundation.whichSuit(foundation.tempStack);
51
+        //WHEN
52
+
53
+        Card expected = new Card(Suit.DIAMONDS, Face.KING);
54
+        Card actual = foundation.diamondStack.peek();
55
+
56
+
57
+        //THEN
58
+        Assert.assertEquals(expected, actual);
59
+
60
+    }
61
+
62
+    @Test
63
+    public void addKingToQueenInHeartStackTest() {
64
+        Card tempCard  = new Card(Suit.HEARTS, Face.KING);
65
+        Card cardOnFoundation  = new Card(Suit.HEARTS,
66
+                Face.QUEEN);
67
+
68
+
69
+        foundation.tempStack.push(tempCard);
70
+        foundation.heartStack.push(cardOnFoundation);
71
+        foundation.whichSuit(foundation.tempStack);
72
+        //WHEN
73
+
74
+        Card expected = new Card(Suit.HEARTS, Face.KING);
75
+        Card actual = foundation.heartStack.peek();
76
+
77
+
78
+        //THEN
79
+        Assert.assertEquals(expected, actual);
80
+    }
81
+
82
+    @Test
83
+    public void addKingToQueenInSpadeStackTest() {
84
+        Card tempCard  = new Card(Suit.SPADES, Face.KING);
85
+        Card cardOnFoundation  = new Card(Suit.SPADES,
86
+                Face.QUEEN);
87
+
88
+
89
+        foundation.tempStack.push(tempCard);
90
+        foundation.spadeStack.push(cardOnFoundation);
91
+        foundation.whichSuit(foundation.tempStack);
92
+        //WHEN
93
+
94
+        Card expected = new Card(Suit.SPADES, Face.KING);
95
+        Card actual = foundation.spadeStack.peek();
96
+
97
+
98
+        //THEN
99
+        Assert.assertEquals(expected, actual);
100
+    }
101
+
102
+    @Test
103
+    public void addTenToQueenInSpadeStackTest() {
104
+        Card tempCard  = new Card(Suit.SPADES, Face.KING);
105
+        Card cardOnFoundation  = new Card(Suit.SPADES,
106
+                Face.TEN);
107
+
108
+
109
+        foundation.tempStack.push(tempCard);
110
+        foundation.spadeStack.push(cardOnFoundation);
111
+        foundation.whichSuit(foundation.tempStack);
112
+        //WHEN
113
+
114
+        Card expected = new Card(Suit.SPADES, Face.KING);
115
+        Card actual = foundation.spadeStack.peek();
116
+
117
+
118
+        //THEN
119
+        Assert.assertNotEquals(expected, actual);
120
+    }
121
+
122
+    @Test
123
+    public void addAceToEmptyStackInClubStackTest() {
124
+        Card tempCard  = new Card(Suit.CLUBS, Face.ACE);
125
+
126
+        Foundation foundation1 = new Foundation();
127
+
128
+
129
+        foundation1.tempStack.push(tempCard);
130
+
131
+        foundation1.whichSuit(foundation1.tempStack);
132
+        //WHEN
133
+
134
+        Card expected = new Card(Suit.CLUBS, Face.ACE);
135
+        Card actual = foundation1.clubStack.peek();
136
+
137
+
138
+        //THEN
139
+        Assert.assertEquals(expected, actual);
140
+    }
141
+
142
+    @Test
143
+    public void addAceToEmptyStackInDiamondStackTest() {
144
+        Card tempCard  = new Card(Suit.DIAMONDS, Face.ACE);
145
+
146
+        Foundation foundation1 = new Foundation();
147
+
148
+
149
+        foundation1.tempStack.push(tempCard);
150
+
151
+        foundation1.whichSuit(foundation1.tempStack);
152
+        //WHEN
153
+
154
+        Card expected = new Card(Suit.DIAMONDS, Face.ACE);
155
+        Card actual = foundation1.diamondStack.peek();
156
+
157
+
158
+        //THEN
159
+        Assert.assertEquals(expected, actual);
160
+    }
161
+
162
+    @Test
163
+    public void addAceToEmptyStackInHeartStackTest() {
164
+        Card tempCard  = new Card(Suit.HEARTS, Face.ACE);
165
+
166
+        Foundation foundation1 = new Foundation();
167
+
168
+
169
+        foundation1.tempStack.push(tempCard);
170
+
171
+        foundation1.whichSuit(foundation1.tempStack);
172
+        //WHEN
173
+
174
+        Card expected = new Card(Suit.HEARTS, Face.ACE);
175
+        Card actual = foundation1.heartStack.peek();
176
+
177
+
178
+        //THEN
179
+        Assert.assertEquals(expected, actual);
180
+    }
181
+
182
+
183
+
184
+    @Test
185
+    public void addAceToEmptyStackInSpadeStackTest() {
186
+        Card tempCard  = new Card(Suit.SPADES, Face.ACE);
187
+
188
+        Foundation foundation1 = new Foundation();
189
+
190
+
191
+        foundation1.tempStack.push(tempCard);
192
+
193
+        foundation1.whichSuit(foundation1.tempStack);
194
+        //WHEN
195
+
196
+        Card expected = new Card(Suit.SPADES, Face.ACE);
197
+        Card actual = foundation1.spadeStack.peek();
198
+
199
+
200
+        //THEN
201
+        Assert.assertEquals(expected, actual);
202
+    }
203
+
204
+}

+ 28
- 0
src/test/java/io/zipcoder/casino/SlotsTest.java Visa fil

@@ -0,0 +1,28 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class SlotsTest {
8
+
9
+    String[] reels = new String[5];
10
+    String[] names = {"Christian","Demetrius", "Jen",
11
+            "Kate", "Nate", "WIN", "Christian","Demetrius",
12
+            "Jen",
13
+            "Kate", "Nate" };
14
+
15
+
16
+    @Test
17
+    public void randomlyFillReels(){
18
+        Slots slot = new Slots();
19
+
20
+        slot.FillReels(5);
21
+
22
+
23
+    }
24
+
25
+
26
+
27
+
28
+}