librejack

Blackjack clone written in java
git clone https://github.com/michaelneuper/librejack.git
README | Files | Log | Refs | LICENSE

commit a42d3c333beeff9777039df7e0778169ec30c0a3
parent ee575e0f7d77e0048b4092f91197f83566365146
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Fri,  7 Oct 2022 18:03:49 +0200

Update Deck.java

Diffstat:
Msrc/model/Deck.java | 204++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 102 insertions(+), 102 deletions(-)

diff --git a/src/model/Deck.java b/src/model/Deck.java @@ -12,106 +12,106 @@ import model.Card.Suit; */ public class Deck { - private ArrayList<Card> deck; - - /** - * Deck constructor - */ - public Deck() { - this.deck = new ArrayList<Card>(); - } - - /** - * Method that populates deck with 52 cards - * by looping over each rank and value - */ - public void populate() { - for(Suit cardSuit : Suit.values()) { - for (Rank cardRank : Rank.values()) { - // adds a new card to the deck - this.deck.add(new Card(cardSuit, cardRank)); - } - } - } - - /** - * Method that shuffles the deck - */ - public void shuffle() { - ArrayList<Card> shufDeck = new ArrayList<Card>(); // temporary deck for storing cards in random order - - Random random = new Random(); - int randomCardIndex = 0; - int originalSize = this.deck.size(); - for(int i = 0; i < originalSize; i++) { - // Generate random index - /* - Formula for generating random number: - = random.nextInt((max - min) + 1) + min - = random.nextInt(((deckSize - 1) - 0) + 1) + 0 - */ - randomCardIndex = random.nextInt(this.deck.size()); - shufDeck.add(this.deck.get(randomCardIndex)); // add card to random index of temporary deck - this.deck.remove(randomCardIndex); // remove card from original deck - } - - this.deck = shufDeck; - } - - /** - * Method to draw card from one deck to another - * @param comingFromDeck deck the card comes from - */ - public void draw(Deck comingFromDeck) { - this.deck.add(comingFromDeck.getCard(0)); - comingFromDeck.removeCard(0); - } - - /** - * Method to remove a card from the deck - * @param i index of card to be removed - */ - public void removeCard(int i) { - this.deck.remove(i); - } - - /** - * Method to return the value of a card at a paticular index - * @param i index of card to be returned - * @return card at index i - */ - public Card getCard(int i) { - return this.deck.get(i); - } - - /** - * Method to add a card to a hand - * @param addCard - */ - public void addCard(Card addCard) { - this.deck.add(addCard); - } - - /** - * Method to take a copy of the first card from the deck, - * remove the card from the deck - * and return the card - * @return card - */ - public Card takeCard() { - Card cardToTake = new Card(deck.get(0)); - deck.remove(0); - return cardToTake; - } - - @Override - public String toString() { - String output = ""; - byte i = 0; - for (Card aCard : this.deck) { - output += "\n" + i + "-" + aCard.toString(); - ++i; - } - return output; - } +// private ArrayList<Card> deck; +// +// /** +// * Deck constructor +// */ +// public Deck() { +// this.deck = new ArrayList<Card>(); +// } +// +// /** +// * Method that populates deck with 52 cards +// * by looping over each rank and value +// */ +// public void populate() { +// for(Suit cardSuit : Suit.values()) { +// for (Rank cardRank : Rank.values()) { +// // adds a new card to the deck +//// this.deck.add(new Card(cardSuit, cardRank)); +// } +// } +// } +// +// /** +// * Method that shuffles the deck +// */ +// public void shuffle() { +// ArrayList<Card> shufDeck = new ArrayList<Card>(); // temporary deck for storing cards in random order +// +// Random random = new Random(); +// int randomCardIndex = 0; +// int originalSize = this.deck.size(); +// for(int i = 0; i < originalSize; i++) { +// // Generate random index +// /* +// Formula for generating random number: +// = random.nextInt((max - min) + 1) + min +// = random.nextInt(((deckSize - 1) - 0) + 1) + 0 +// */ +// randomCardIndex = random.nextInt(this.deck.size()); +// shufDeck.add(this.deck.get(randomCardIndex)); // add card to random index of temporary deck +// this.deck.remove(randomCardIndex); // remove card from original deck +// } +// +// this.deck = shufDeck; +// } +// +// /** +// * Method to draw card from one deck to another +// * @param comingFromDeck deck the card comes from +// */ +// public void draw(Deck comingFromDeck) { +// this.deck.add(comingFromDeck.getCard(0)); +// comingFromDeck.removeCard(0); +// } +// +// /** +// * Method to remove a card from the deck +// * @param i index of card to be removed +// */ +// public void removeCard(int i) { +// this.deck.remove(i); +// } +// +// /** +// * Method to return the value of a card at a paticular index +// * @param i index of card to be returned +// * @return card at index i +// */ +// public Card getCard(int i) { +// return this.deck.get(i); +// } +// +// /** +// * Method to add a card to a hand +// * @param addCard +// */ +// public void addCard(Card addCard) { +// this.deck.add(addCard); +// } +// +// /** +// * Method to take a copy of the first card from the deck, +// * remove the card from the deck +// * and return the card +// * @return card +// */ +// public Card takeCard() { +// Card cardToTake = new Card(deck.get(0)); +// deck.remove(0); +// return cardToTake; +// } +// +// @Override +// public String toString() { +// String output = ""; +// byte i = 0; +// for (Card aCard : this.deck) { +// output += "\n" + i + "-" + aCard.toString(); +// ++i; +// } +// return output; +// } } \ No newline at end of file