-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Project exclude paths | ||
/out/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package Poker; | ||
|
||
/** | ||
* this class represents a card object. Each {@code Poker.Card} has a {@code value} value which goes from 2 to A. | ||
* Each {@code Poker.Card} has a {@code suit} value which is either "clubs", "diamonds", "hearts", or "spades". | ||
*/ | ||
public class Card | ||
{ | ||
/** | ||
* a value of a playing card that can range from 2, 3, 4, ... Q, K, A. | ||
*/ | ||
private String value; | ||
/** | ||
* a suit of a playing card that can be either "clubs", "diamonds", "hearts", or "spades". | ||
*/ | ||
private String suit; | ||
|
||
/** | ||
* constructs a {@code Poker.Card} object with the given {@code value} and {@code suit} | ||
* @param value the given value of the card | ||
* @param suit the given suit of the card | ||
*/ | ||
public Card(String value, String suit) { | ||
this.value = value; | ||
this.suit = suit; | ||
} | ||
|
||
/** | ||
* returns the value of the {@code Poker.Card} | ||
* @return the value | ||
*/ | ||
public String getValue() { | ||
return value; | ||
} // getValue | ||
|
||
/** | ||
* returns the suit of the {@code Poker.Card} | ||
* @return the suit | ||
*/ | ||
public String getSuit() { | ||
return suit; | ||
} // getSuit | ||
|
||
/** | ||
* returns the value and suit in a readable way to the user | ||
* @return in a String the value and suit of the card | ||
*/ | ||
@Override | ||
public String toString() { | ||
return value + " of " + suit; | ||
} // toString | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package Poker; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* This class represents a deck of playing cards with 52 unique {@code Poker.Card} objects. | ||
* This {@code Poker.Deck} can reset the deck, shuffle, and draw a card via {@link #newDeck()}, {@link #shuffleDeck()}, | ||
* and {@link #drawCard()} methods respectively. | ||
*/ | ||
public class Deck | ||
{ | ||
/** | ||
* List of {@code Poker.Card} objects. | ||
*/ | ||
private ArrayList<Card> cards = new ArrayList<>(); | ||
/** | ||
* The board in a poker game in which players try to match cards to. | ||
* Array of 5 {@code Poker.Card} objects that gets added throughout the poker game. | ||
*/ | ||
private Card [] board = new Card[5]; | ||
static Random rand = new Random(); | ||
|
||
/** | ||
* This constructor calls the method {@link #newDeck()} and creates a new deck. | ||
*/ | ||
Deck() | ||
{ | ||
newDeck(); | ||
} | ||
|
||
/** | ||
* returns the values of the {@code board} | ||
* @return the {@code board} | ||
*/ | ||
public Card[] getBoard() { | ||
return board; | ||
} | ||
|
||
public void setBoard(Card[] board) { | ||
this.board = board; | ||
} | ||
|
||
/** | ||
* Resets the deck to a new deck of 52 {@code cards} un-shuffled | ||
* also resets the {@code board} of the deck object | ||
*/ | ||
public void newDeck() | ||
{ | ||
String [] suits = {"Clubs", "Diamonds", "Hearts", "Spades"}; | ||
String [] values = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"}; | ||
|
||
if (cards.size() > 0) { | ||
cards.subList(0, cards.size()).clear(); | ||
} | ||
for (int i = 0; i < 4; i++) | ||
{ | ||
for (int j = 0; j < 13; j++) | ||
{ | ||
cards.add(new Card(values[j], suits[i])); | ||
} | ||
} | ||
Arrays.fill(board, null); | ||
} | ||
|
||
/** | ||
* This method will shuffle {@code cards} into a random order | ||
*/ | ||
public void shuffleDeck() | ||
{ | ||
//putting cards from deck into a tracker array in a random order | ||
int pos; | ||
ArrayList<Card> randomDeck = new ArrayList<>(); | ||
int [] tracker = new int[52]; | ||
for (int i = 0; i<52; i++) | ||
{ | ||
boolean randomCardAdded = false; | ||
do { | ||
pos = rand.nextInt(52); | ||
if (tracker[pos] == 0) | ||
{ | ||
randomDeck.add(cards.get(pos)); | ||
tracker[pos] = 1; | ||
randomCardAdded = true; | ||
} | ||
} while (!randomCardAdded); | ||
} | ||
//saving tracker array into deck array | ||
for (int j = 0; j<52; j++) | ||
{ | ||
cards.set(j, randomDeck.get(j)); | ||
} | ||
} | ||
|
||
/** | ||
* This method will return a single card from {@code cards} and remove it from {@code cards}. | ||
* @return the Poker.Card object in the last index of {@code cards} | ||
*/ | ||
public Card drawCard() | ||
{ | ||
Card topCard = cards.get(cards.size()-1); | ||
cards.remove(cards.size()-1); | ||
return topCard; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Poker; | ||
|
||
public class InvalidFormatException extends Exception | ||
{ | ||
public InvalidFormatException(String message) { | ||
super(message); | ||
} | ||
} |