commit e8c3ed199ed08554e4455c327a0d355693d3c461
parent c62d326d517548bb070816026d67790d9dcdd6a4
Author: Michael Neuper <michaelneuper@icloud.com>
Date: Thu, 27 Apr 2023 22:43:14 +0200
Merge pull request #19 from michaelneuper/format
Format and refactor
Diffstat:
12 files changed, 93 insertions(+), 76 deletions(-)
diff --git a/src/controller/Controller.java b/src/controller/Controller.java
@@ -7,9 +7,11 @@ import model.Player;
import model.Statistics;
/**
- * Handles most of the game logic
+
+ * Handles most of the game logic.
*
- * @author Michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Controller {
@@ -21,7 +23,7 @@ public class Controller {
private Statistics stats = new Statistics();
/**
- * Controller Constructor: Initializes score to 0
+ * Controller Constructor: Initializes score to 0.
*/
public Controller() {
// create new dealer and player
@@ -61,7 +63,7 @@ public class Controller {
}
/**
- * Handles logic for each round
+ * Handles logic for each round.
*
*/
public void startRound() {
@@ -156,7 +158,7 @@ public class Controller {
}
/**
- * Hits the player with a card
+ * Hits the player with a card.
*/
public void hitPlayer() {
player.hit(deck, discarded);
diff --git a/src/controller/Hand.java b/src/controller/Hand.java
@@ -6,25 +6,26 @@ 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.
- *
- * @author Michael
+ * Contains methods to calculate the value of a hand, take cards from a deck and
+ * discard the hand to a deck.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Hand {
private ArrayList<Card> hand;
/**
- * Hand Constructor:
- * Creates empty hand
+ * Hand Constructor: Creates empty hand.
*/
public Hand() {
hand = new ArrayList<Card>();
}
/**
- * Adds a card from the deck to the hand
- *
+ * Adds a card from the deck to the hand.
+ *
* @param deck deck to take card from
*/
public void takeCardFromDeck(Deck deck) {
@@ -32,7 +33,7 @@ public class Hand {
}
/**
- * Method to calculate the value of a hand
+ * Method to calculate the value of a hand.
*
* @return value value of the hand
*/
@@ -67,8 +68,8 @@ public class Hand {
}
/**
- * Discards hand to deck
- *
+ * Discards hand to deck.
+ *
* @param discardDeck
*/
public void discardHandToDeck(Deck discardDeck) {
diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java
@@ -6,8 +6,10 @@ import java.util.regex.Pattern;
import javax.swing.JOptionPane;
/**
+ * Controller for handling user login.
*
- * @author Michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class LoginController {
@@ -71,7 +73,7 @@ public class LoginController {
*
* @param mobileNumber the mobile number to check
* @return true if the mobile number is a valid South African mobile number,
- * false otherwise
+ * false otherwise
*/
private boolean isValidSouthAfricanMobileNumber(String mobileNumber) {
// Remove any non-digit characters from the mobile number
@@ -106,7 +108,7 @@ public class LoginController {
*
* @param date the date to be checked
* @return true if the date is valid and the person is at least 18 years
- * old, false otherwise
+ * old, false otherwise
*/
private static boolean isValidDateAndAdult(Date date) {
// Check if the date is null
@@ -143,8 +145,8 @@ public class LoginController {
/**
* Checks the following conditions to determine whether a password is valid:
- * - is at least 10 characters in length - has at least 1 special character
- * - has at least 1 number - has at least 1 uppercase and lowercase letter
+ * - is at least 10 characters in length - has at least 1 special character.
+ * - has at least 1 number - has at least 1 uppercase and lowercase letter.
*
* @param password to be validated
* @return true if password is valid, false otherwise
diff --git a/src/model/Card.java b/src/model/Card.java
@@ -1,9 +1,10 @@
package model;
/**
- * Represents a card and handles card operations
- *
- * @author Michael
+ * Represents a card and handles card operations.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Card {
@@ -59,9 +60,8 @@ public class Card {
private Rank rank;
/**
- * Card Constructor:
- * Creates a card given a suit and rank
- *
+ * Card Constructor: Creates a card given a suit and rank.
+ *
* @param suit Card suit
* @param rank Card rank
*/
@@ -71,9 +71,8 @@ public class Card {
}
/**
- * Card Constructor:
- * Creates a new card as a copy of another card
- *
+ * Card Constructor: Creates a new card as a copy of another card.
+ *
* @param card card to be added
*/
public Card(Card card) {
diff --git a/src/model/Dealer.java b/src/model/Dealer.java
@@ -1,14 +1,16 @@
package model;
/**
- * Handles dealer specific operations, such as drawing cards to 16 and standing on 17 or above.
- *
- * @author Michael
+ * Handles dealer specific operations, such as drawing cards to 16 and standing
+ * on 17 or above.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Dealer extends Person {
/**
- * Creates a new dealer
+ * Creates a new dealer.
*/
public Dealer() {
super.setName("Dealer");
@@ -17,7 +19,7 @@ public class Dealer extends Person {
public String printFirstHand() {
return "" + super.getHand().getCard(0);
}
-
+
public String printFirstCardValue() {
return "" + super.getHand().getCard(0).getValue();
}
diff --git a/src/model/Deck.java b/src/model/Deck.java
@@ -7,9 +7,10 @@ import model.Card.Rank;
import model.Card.Suit;
/**
- * Holds multiple cards and performs operations such as shuffling the deck
- *
- * @author Michael
+ * Holds multiple cards and performs operations such as shuffling the deck.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Deck {
@@ -23,7 +24,7 @@ public class Deck {
}
/**
- * Populates 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() {
@@ -36,7 +37,7 @@ public class Deck {
}
/**
- * Shuffles deck
+ * Shuffles deck.
*/
public void shuffle() {
@@ -56,8 +57,8 @@ public class Deck {
}
/**
- * Method to add a card to the deck
- *
+ * Method to add a card to the deck.
+ *
* @param inCard card the be added
*/
public void addCard(Card inCard) {
@@ -65,20 +66,20 @@ public class Deck {
}
/**
- * Takes copy of first card from deck and removes card from deck
- *
+ * Takes copy of first card from deck and removes card from deck.
+ *
* @return cardToTake card that was removed
*/
public Card takeCard() { // TODO: change take to draw
Card cardToTake = new Card(deck.get(0));
deck.remove(0);
-
+
return cardToTake;
}
/**
- * Makes 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)
*/
@@ -87,15 +88,15 @@ public class Deck {
}
/**
- * Mehtod to empty the deck
+ * Mehtod to empty the deck.
*/
public void emptyDeck() {
deck.clear();
}
/**
- * Adds arraylist of cards to deck
- *
+ * Adds arraylist of cards to deck.
+ *
* @param cards arraylist of cards to be added to deck
*/
public void addCards(ArrayList<Card> cards) {
@@ -103,7 +104,7 @@ public class Deck {
}
/**
- * Returns arraylist containing all the cards in the deck
+ * Returns arraylist containing all the cards in the deck.
*
* @return deck arraylist with the cards
*/
@@ -125,7 +126,7 @@ public class Deck {
}
/**
- * @return deck.size() number of cards left in the deck
+ * @return deck.size() number of cards left in the deck.
*/
public int cardsLeft() {
return deck.size();
diff --git a/src/model/Person.java b/src/model/Person.java
@@ -3,9 +3,10 @@ package model;
import controller.Hand;
/**
- * Parent class of the Player and Dealer Objects
- *
- * @author Michael
+ * Parent class of the Player and Dealer Objects.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public abstract class Person {
@@ -13,7 +14,7 @@ public abstract class Person {
private String name;
/**
- * Creates a person
+ * Creates a person.
*/
public Person() {
this.hand = new Hand();
@@ -37,26 +38,25 @@ public abstract class Person {
}
/**
- * Checks 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)
*/
public boolean hasBlackjack() {
return this.getHand().calculateValue() == 21;
}
-
+
/**
- * Prints a formatted version of the person's hand
+ * Prints a formatted version of the person's hand.
*/
- // TODO: remove print statement
public String printHand() {
return this.hand + "[" + this.hand.calculateValue() + "]";
}
-
+
/**
- * Checks if deck has cards and reloads 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
*/
diff --git a/src/model/Player.java b/src/model/Player.java
@@ -8,7 +8,10 @@ import java.io.PrintWriter;
import java.util.Scanner;
/**
- * Represents a player in a Blackjack game
+ * Represents a player in a Blackjack game.
+ *
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Player extends Person {
@@ -17,14 +20,14 @@ public class Player extends Person {
private Scanner input = new Scanner(System.in);
/**
- * Creates a new player with a default name of "Player"
+ * Creates a new player with a default name of "Player".
*/
public Player() {
super.setName("Player");
}
/**
- * Gets the player's current balance from a file
+ * Gets the player's current balance from a file.
*
* @return balance the player's current balance
*/
@@ -41,7 +44,7 @@ public class Player extends Person {
}
/**
- * Sets the player's balance and stores it in a file
+ * Sets the player's balance and stores it in a file.
*
* @param balance the new balance to set
*/
diff --git a/src/model/Statistics.java b/src/model/Statistics.java
@@ -16,7 +16,8 @@ import com.opencsv.exceptions.CsvValidationException;
*
* The file is named 'statistics.csv' and is stored in the 'db/' directory.
*
- * @author michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class Statistics {
diff --git a/src/view/LoginGUI.java b/src/view/LoginGUI.java
@@ -4,8 +4,10 @@ import controller.LoginController;
import java.util.Date;
/**
+ * GUI for login screen.
*
- * @author Michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class LoginGUI extends javax.swing.JFrame {
diff --git a/src/view/MainGUI.java b/src/view/MainGUI.java
@@ -7,11 +7,13 @@ import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
+ * Main GUI.
*
- * @author Michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class MainGUI extends javax.swing.JFrame {
-
+
Controller game = new Controller();
/**
@@ -339,12 +341,12 @@ public class MainGUI extends javax.swing.JFrame {
new MainGUI().setVisible(true);
});
}
-
+
public void printDealerHand() {
jLabelDisplayDealerHand.setText(game.displayDealerHand());
jLabelDealerHandValue.setText(game.displayDealerHandValue());
}
-
+
public void printPlayerHand() {
jLabelDisplayPlayerHand.setText(game.displayPlayerHand());
jLabelPlayerHandValue.setText(game.displayPlayerHandValue());
diff --git a/src/view/StatisticsGUI.java b/src/view/StatisticsGUI.java
@@ -1,4 +1,5 @@
package view;
+
import com.opencsv.exceptions.CsvValidationException;
import java.io.IOException;
import java.util.logging.Level;
@@ -6,14 +7,15 @@ import java.util.logging.Logger;
import model.Statistics;
/**
+ * GUI that displays the player's wins, losses and pushes.
*
- * @author michael
+ * @author Michael Neuper
+ * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a>
*/
public class StatisticsGUI extends javax.swing.JFrame {
-
+
Statistics stats;
-
/**
* Creates new form StatisticsGUI
*/