So I'm in the process of creating a simple Contract Bridge in Java. I will be using JavaFX to create the GUI component of the program. For right now I am trying to tackle writing each of the classes needed to run the game.
If you're unfamiliar with bridge the short explanation is as follows: you start with a 52 card deck, shuffled w/ no jokers. There will be four players, two teams, the player who is opposite of you will be you team mate. The deck is dealt and each player gets 13 cards. The turns run to the left. Basically, find the highest value card for a given suit, who ever has the largest value wins the round.
I would like some advice as far as design goes, also feedback on the classes I've created so far. It is my first time creating a game so it feels a bit foreign.
I've identified four classes I will create: Card
, Deck
, Player
, and Game
.
Here is my Card
class:
public class Card {
private Suit suit;
private CardValue cardValue;
public Card (CardValue cardValue, Suit suit)
{
this.cardValue = cardValue;
this.suit = suit;
}
public Suit getSuit()
{
return suit;
}
public void setSuit(Suit suit)
{
this.suit = suit;
}
public CardValue getCardValue()
{
return cardValue;
}
public void setCardValue(CardValue cardValue)
{
this.cardValue = cardValue;
}
public enum Suit {
SPADES,
HEARTS,
DIAMONDS,
CLUBS;
}
public enum CardValue
{
ACE(1),
TWO(2),
THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
JACK(11),
QUEEN(12),
KING(13);
private int cardValue;
private CardValue (int value)
{
this.cardValue = value;
}
public int getCardValue() {
return cardValue;
}
}
//TODO
public String toString() {
switch (suit) {
case 1:
System.out.print
}
}
}
Deck:
public class Deck {
/** deck instance variable */
private Card[] deck;
/** Tracks cards dealt */
private int cardsDealt;
/** Construct a standard 52 card deck. Un-shuffled*/
public Deck() {
this.deck = new Card[52];
}
/** Constructs a standard 52 card deck. Shuffled*/
public Deck(boolean isShuffled){
if(isShuffled == false)
this.deck = new Card[52];
else{
this.deck = new Card[52];
shuffle();
}
}
/** Shuffle deck */
public void shuffle() {
for ( int i = deck.length - 1; i > 0; i-- ) {
int randomize = (int)(Math.random()*( i + 1 ));
Card temp = deck[i];
deck[i] = deck[randomize];
deck[randomize] = temp;
}
cardsDealt = 0;
}
/** Returns cards left in the deck */
public int cardsLeft() {
return deck.length - cardsDealt;
}
/** Deals card */
public Card dealCard() {
if (cardsDealt == deck.length)
throw new IllegalStateException("No cards are left in the deck.");
cardsDealt++;
return deck[cardsDealt - 1];
}
}