Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoManeein committed Sep 19, 2022
0 parents commit b5f81c0
Show file tree
Hide file tree
Showing 14 changed files with 3,808 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Project exclude paths
/out/
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Poker.iml
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>
52 changes: 52 additions & 0 deletions src/Poker/Card.java
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
}
104 changes: 104 additions & 0 deletions src/Poker/Deck.java
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;
}
}
8 changes: 8 additions & 0 deletions src/Poker/InvalidFormatException.java
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);
}
}
Loading

0 comments on commit b5f81c0

Please sign in to comment.