librejack

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

commit 009dfa1e43385f85b41417ff08ad81af1c500d22
parent d617630d679c3c1f4bc6fe45b975e428e1044cda
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date:   Sat,  8 Oct 2022 15:20:45 +0200

remove legacy code

Diffstat:
Msrc/controller/Controller.java | 2+-
Msrc/controller/Hand.java | 17++++++++---------
Msrc/model/Dealer.java | 4+---
Msrc/model/Deck.java | 60++++++++++++++----------------------------------------------
Msrc/model/Person.java | 6+++---
Msrc/model/Player.java | 14+-------------
6 files changed, 28 insertions(+), 75 deletions(-)

diff --git a/src/controller/Controller.java b/src/controller/Controller.java @@ -116,7 +116,7 @@ public class Controller { startRound(); } - private void checkWhoWins() { + private void checkWhoWins() { // TODO: return string // check whether player busted if(player.getHand().calculateValue() > 21) { diff --git a/src/controller/Hand.java b/src/controller/Hand.java @@ -6,9 +6,7 @@ import model.Card; import model.Deck; /** - * Contains methods to calculate the value of a hand, - * take cards from a deck and - * discard the hand to a deck. + * Contains methods to calculate the value of a hand, take cards from a deck and discard the hand to a deck. * * @author Michael */ @@ -51,25 +49,26 @@ public class Hand { ++aceCount; } } - + // for the scenario where we have multiple aces // go back and set each ace to 1 until get back under 21, if possible - if(value > 21 && aceCount > 0) { - while(aceCount > 0 && value > 21) { - -- aceCount; + if (value > 21 && aceCount > 0) { + while (aceCount > 0 && value > 21) { + --aceCount; value -= 10; } } return value; } - + public Card getCard(int i) { return hand.get(i); } - + /** * Discards hand to deck + * * @param discardDeck */ public void discardHandToDeck(Deck discardDeck) { diff --git a/src/model/Dealer.java b/src/model/Dealer.java @@ -1,9 +1,7 @@ package model; /** - * Handles dealer specific operations, - * such as drawing cards to 16 and standing - * on 17 or above. + * Handles dealer specific operations, such as drawing cards to 16 and standing on 17 or above. * * @author Michael */ diff --git a/src/model/Deck.java b/src/model/Deck.java @@ -7,8 +7,7 @@ import model.Card.Rank; import model.Card.Suit; /** - * Holds multiple cards and - * performs operations such as shuffling the deck + * Holds multiple cards and performs operations such as shuffling the deck * * @author Michael */ @@ -24,8 +23,7 @@ public class Deck { } /** - * Method that populates an empty deck with 52 cards - * by looping over each rank and value + * Populates empty deck with 52 cards by looping over each rank and value */ public void populate() { @@ -38,7 +36,7 @@ public class Deck { } /** - * Method that shuffles the deck + * Shuffles deck */ public void shuffle() { @@ -57,32 +55,6 @@ public class 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 the deck * @@ -93,20 +65,18 @@ public class Deck { } /** - * Method to take a copy of the first card from the deck, - * remove the card from the deck - * and return the card + * Takes copy of first card from deck and removes card from deck * - * @return cardToTake card to take + * @return cardToTake card that was removed */ - public Card takeCard() { + public Card takeCard() { // TODO: change take to draw Card cardToTake = new Card(deck.get(0)); deck.remove(0); return cardToTake; } /** - * Method to make sure the deck we're hitting from has cards in it + * Makes sure the deck we're hitting from has cards in it * * @return true (if the deck has cards in) * @return false (if the deck is empty) @@ -123,28 +93,28 @@ public class Deck { } /** - * Adds an arraylist of cards to the deck + * Adds arraylist of cards to deck * * @param cards arraylist of cards to be added to deck */ public void addCards(ArrayList<Card> cards) { deck.addAll(cards); } - + /** - * returns the arraylist containing all the cards in the deck + * Returns arraylist containing all the cards in the deck * - * @return deck arraylist to be returned + * @return deck arraylist with the cards */ public ArrayList<Card> getCards() { return deck; } /** - * Take all the cards from a discarded deck and place them in this deck, shuffled + * Take all cards from discarded deck and place them in this deck, shuffled. * Clear the old deck * - * @param discard deck cards are coming from + * @param discard the deck cards are coming from */ public void reloadDeckFromDiscard(Deck discard) { this.addCards(discard.getCards()); @@ -152,10 +122,8 @@ public class Deck { discard.emptyDeck(); System.out.println("Ran out of cards, creating new deck from discard pile & shuffling deck"); } - + /** - * Returns number of cards left in a deck - * * @return deck.size() number of cards left in the deck */ public int cardsLeft() { diff --git a/src/model/Person.java b/src/model/Person.java @@ -37,7 +37,7 @@ public abstract class Person { } /** - * Method to check if a person has blackjack + * Checks if a person has blackjack * * @return true (if player has a blackjack) * @return false (if player does not have a blackjack) @@ -54,14 +54,14 @@ public abstract class Person { } /** - * Checks if the deck has cards and reloads the deck if it ran out + * Checks if deck has cards and reloads deck if it ran out * * @param deck deck to draw from * @param discard deck to discard to */ public void hit(Deck deck, Deck discard) { - //If there's no cards left in the deck + // if there's no cards left in the deck if (!deck.hasCards()) { deck.reloadDeckFromDiscard(discard); } diff --git a/src/model/Player.java b/src/model/Player.java @@ -86,15 +86,4 @@ public class Player extends Person { } } - // Deck playerDeck = new Deck(); // empty deck for the player - // // private double balance; - // // try { - // // Scanner scFile = new Scanner(new File("db/balance.txt")); - // // balance = scFile.nextDouble(); - // // } catch (FileNotFoundException e) { - // // System.out.println(e); - // // } - // double balance = 100.00d; - - // Scanner betAmount = new Scanner(System.in); -} -\ No newline at end of file +}