I'm writing a program creating a card game of war. I (think) that I have the majority of it done, but I cannot seem to figure out how to split a deck into two separate hands in a Hand class. My code is in components, I have a Deck, Card, Game, War (main) classes. I have the Game set up to use a Hand class with a player A hand and a player B hand, but I'm having a hard time wrapping my head around creating this class with the two hands. Here is my Card and Deck classes (so far). Could anyone point me in the right direction? I can post my other two classes if needed, but I don't want to scare anyone away with how much code I post.
public class Card
{
private int rank;
private int suit;
public Card(int rank, int suit)
{
this.rank = rank;
this.suit = suit;
}
public int getRank()
{
return rank;
}
public int getSuit()
{
return suit;
}
public String toString()
{
String printed;
switch (rank){
case 11:
printed = "Jack ";
break;
case 12:
printed = "Queen ";
break;
case 13:
printed = "King ";
break;
case 14:
printed = "Ace ";
break;
default:
printed = rank + " ";
break;
}
printed = printed + "of";
switch (suit)
{
case 1:
printed = printed + " Diamonds";
break;
case 2:
printed = printed + " Hearts";
break;
case 3:
printed = printed + " Spades";
break;
case 4:
printed = printed + " Clubs";
break;
}
return printed;
}
public static int compareRank(int rank1, int rank2)
{
int num = 0;
if (rank1 > rank2)
num = 1;
else
if (rank1 < rank2)
num = -1;
else
num = 2;
return num;
}
}
import java.util.*;
public class Deck{
List<Card> deck = new ArrayList<Card>();
public Deck()
{
int x, y;
for (x = 2; x <= 14; x++)
{
for (y = 1; y <= 4; y++)
{
deck.add( new Card(x, y) );
}
}
Collections.shuffle(deck);
Collections.shuffle(deck);
Collections.shuffle(deck);
Collections.shuffle(deck);
Collections.shuffle(deck);
Collections.shuffle(deck);
Collections.shuffle(deck);
System.out.println(deck);
}
public List<Card> splitDeck(int handNum)
{
List<Card> tempHand = new ArrayList<Card>();
if (handNum == 1)
tempHand = deck.subList(0, 26);
if (handNum == 2)
tempHand = deck.subList(26, 52);
return tempHand;
}
}