-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSC_fiveCardPoker.java
More file actions
276 lines (246 loc) · 9.89 KB
/
BSC_fiveCardPoker.java
File metadata and controls
276 lines (246 loc) · 9.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//Creator: BillySampleCode
//Project Name: BSC_fiveCardPoker
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.InputMismatchException;
public class BSC_fiveCardPoker {
//CF&IF
final static public String cardRankOptions[] = {"2","3","4","5","6","7",
"8","9","10","Jack", "Queen", "King", "Ace"};
final static public String cardSuitOptions[] = {"Clubs","Diamonds",
"Hearts","Spades"};
String cardRank;
String cardSuit;
int cardCount;
String cardName;
//Restrict ArrayList to ClassType.
static ArrayList<BSC_fiveCardPoker> deckRandomArrayList =
new ArrayList<>();
int deckLength = deckRandomArrayList.size();
static boolean deckStatus = false; //To check if deck is full or not.
static int cardCounter1 = 1; //To count the Nth random card.
static boolean aCardStatus = false; //To check if card exists in deck.
//CC: PCCDNA
public BSC_fiveCardPoker(){
};
//CC: PCCWA ... Constructor for a card object.
public BSC_fiveCardPoker(String rankInput, String suitInput,
int cardCounter1){
this.cardRank = rankInput;
this.cardSuit = suitInput;
this.cardCount = cardCounter1;
this.cardName = (this.cardRank + " of " + this.cardSuit);
};
//All others.
public static BSC_fiveCardPoker sfmCreateRandomCard(
String inputRank, String inputSuit, int inputCounter){
BSC_fiveCardPoker newCard =
new BSC_fiveCardPoker(
inputRank,
inputSuit,
inputCounter);
return newCard;
};
public static boolean checkDeckArrayListSize(
ArrayList<BSC_fiveCardPoker> inputDeck){
ArrayList<BSC_fiveCardPoker> aDeck = inputDeck;
if (aDeck.size()== 52){
deckStatus = true;
}else if(aDeck.size()!= 52){
deckStatus = false;
}
return deckStatus;
};
public static BSC_fiveCardPoker createRandomCard(){
//Random: random.nextInt(inputIntExclusive)
//...0inclusive to #exclusive.
Random randomVar = new Random();
int newRandom1 = randomVar.nextInt(cardRankOptions.length);
int newRandom2 = randomVar.nextInt(cardSuitOptions.length);
String randomRank = cardRankOptions[newRandom1];
String randomSuit = cardSuitOptions[newRandom2];
//Use sfm here...
BSC_fiveCardPoker cardObject =
sfmCreateRandomCard(randomRank, randomSuit,
cardCounter1);
//cardCounter1 should increase after card creation and SOPCheck.
cardCounter1++;
return cardObject;
};
public static boolean checkForCard(BSC_fiveCardPoker inputCard){
BSC_fiveCardPoker aCard = inputCard;
int cardCounter2 = 0; //Tracks the number of repated cards.
//Will run into problem if ArrayList is empty.
if(deckRandomArrayList.size() == 0){
aCardStatus = false;
}else if(deckRandomArrayList.size() != 0){
for(BSC_fiveCardPoker currentCard : deckRandomArrayList){
if (aCard.cardRank.equals(currentCard.cardRank)
&& aCard.cardSuit.equals(currentCard.cardSuit)){
cardCounter2++; //This counter should never be >1.
}
}
}
if(cardCounter2 > 0){
aCardStatus = true;
}else{
aCardStatus = false;
}
//Count the Nth random card here.
return aCardStatus;
};
//Utilize @Override so values returned in ArrayList are not hashcodes.
@Override
public String toString(){
return this.cardName;
};
//Ask For Scanner Input, to determine number of player hands!
static int handsAtTable = 0;
static boolean handsMaxLimit = true; //anchorStatic.
public static void askForScannerInput(){
int intCheck = 0; //anchorLocal.
boolean inputStatus = false; //anchorLocal.
do{
Scanner scannerVar1 = new Scanner(System.in);
System.out.println("Please input number of players: ");
//Assume string, convert later.
String input1 = scannerVar1.nextLine();
try{
//Parse a String into an Integer Wrapper Value.
handsAtTable = Integer.parseInt(input1);
inputStatus = true;
if (handsAtTable > 4){
System.out.println("Too many, max players 4, "
+ "please re-input!");
inputStatus = false;
}else if(handsAtTable == 0){
System.out.println("Huh, you entered zero players! "
+ "please re-input!");
inputStatus = false;
}else if(handsAtTable == 1){
System.out.println("Thanks, we have " + handsAtTable
+ " player! - Why not invite a friend to join!");
inputStatus = true;
}else{
System.out.println("Thanks, we have " + handsAtTable
+ " players!");
inputStatus = true;
}
}catch(NumberFormatException varException){
System.out.println("You did not enter an integer!");
inputStatus = false;
}
}while(inputStatus == false);
}
//Create sfm for creating an arrayListHand.
public static ArrayList<BSC_fiveCardPoker> sfmCreateHand(){
ArrayList<BSC_fiveCardPoker> aHand = new ArrayList();
return aHand;
};
//Create a 2D ArrayList, an ArrayList filled with ArrayLists!
static ArrayList<ArrayList<BSC_fiveCardPoker>> al2DHandCollector
= new ArrayList();
//Consolidate the number of player hands created.
public static void createHandsAtTableCollector(){
int handCounter = 0; //anchorLocal.
while (handCounter<handsAtTable){
ArrayList<BSC_fiveCardPoker> newHand = sfmCreateHand();
//Add each new hand at the Nth index of the arraylist collector.
al2DHandCollector.add(handCounter,newHand);
handCounter++;
}
};
//Draw card from deck.
public static BSC_fiveCardPoker drawRandomCard(){
Random randomVar = new Random();
int newRandom3 = randomVar.nextInt(deckRandomArrayList.size());
BSC_fiveCardPoker addThisCardToHand =
deckRandomArrayList.get(newRandom3);
return addThisCardToHand;
};
//Remove drawn card from existing deck.
public static void removeDrawnRandomCard(BSC_fiveCardPoker inputCard){
deckRandomArrayList.remove(inputCard);
};
//A single round of drawing cards.
static int cardCounter3 = 0; //anchorStatic for each round of card dealt.
public static void aRoundOfDrawingCards(){
for(ArrayList<BSC_fiveCardPoker>
handArrayList: al2DHandCollector ){
BSC_fiveCardPoker drawnCard = drawRandomCard();
handArrayList.add(cardCounter3, drawnCard);
removeDrawnRandomCard(drawnCard);
}
//Increase counter for next index in each hand.
cardCounter3++;
};
//Set the number of cards per hand.
static int cardsPerHand = 5;
//A multiple round of drawing cards to build a hand.
public static void buildTheHands(){
int nThRound = 0;
while(nThRound < cardsPerHand){
aRoundOfDrawingCards();
nThRound++;
}
};
//SOP Checks.
public static void sopCheck1(){
System.out.println("Hello, world!");
System.out.println("Welcome to BillySampleCode's "
+ "Five Card Poker Game!");
}
public static void sopCheck2(){
System.out.println("Cards are dealt! Number of cards remaining in "
+ "deck: " + deckRandomArrayList.size());
};
public static void sopCheck3(){
int cardCounter4 = 0; //anchorLocal.
for (ArrayList<BSC_fiveCardPoker>
handArrayList: al2DHandCollector){
System.out.println("Player #" + (cardCounter4+1) + "'s cards are:"
+ handArrayList);
cardCounter4++;
}
}
public static void sopCheck4(){
System.out.println("Please compare for strongest hand! ");
System.out.println("Thanks for playing!");
System.out.println("Hope you had plenty of fun!");
}
static boolean psvmVar1;
public static void main (String[] args){
//Building a random deck.
//Check if deck is full.
psvmVar1 = checkDeckArrayListSize(deckRandomArrayList);
//If full, do nothing.
if (psvmVar1 == true){
return;
//If not full, then Loop-While, until deck is full.
}else if (psvmVar1 == false){
labelPoint1:
while(deckRandomArrayList.size()<52){
//Create a random card.
BSC_fiveCardPoker psvmVar2 = createRandomCard();
//Check if random card exists in deck.
boolean psvmVar3 = checkForCard(psvmVar2);
//If in deck, jump back to create random card.
if (psvmVar3 == true){
continue labelPoint1;
}
//If not in deck, then add random card to deck.
deckRandomArrayList.add(psvmVar2);
}
}
//Run the game.
sopCheck1();
askForScannerInput();
createHandsAtTableCollector();
buildTheHands();
sopCheck2();
sopCheck3();
sopCheck4();
};
};//End.