So I have a Hand object that is an array of Card objects. Here's my constructor for the Hand:
public Hand(){
Card[] Hand = new Card[5];
}
And here's my constructor for the Card:
public Card(int value, char suit){
if (value < 0 || value > 13)
{
System.err.println("Twilight Zone Card");
System.exit(1);
}
this.value = value;
if (suit == 'c')
suit = 'C';
if (suit == 'd')
suit = 'D';
if (suit == 'h')
suit = 'H';
if (suit == 's')
suit = 'S';
if (suit == 'C' || suit == 'D' || suit == 'H' || suit == 'S')
{
this.suit = suit;
}
else
{
System.err.println("No such suit.");
System.exit(1);
}
}
The game I have to make is go fish, so sometimes I need to pull the particular card object out of the hand to compare it or print it etc. So once I instantiate a Hand in my main class, it treats it as an object and not an array. So how am I supposed to pull the cards for different locations in the hand? Like I can't do:
Hand Player1 = new Hand();
Hand Player2 = new Hand();
if (Player1[2] == Player2[2])....
So I tried to make a getCard function in the Hand class, but I don't know how to access like, say the second card in the hand, since it won't let me do hand[2] since it doesn't treat it as an array. I'm struggling so hard right now. What should I do?