我可以在 passCard() 中找到我想要的卡片,但是我很难将那张卡片移到手上。
public class CardContainer
{
protected Card[] cards;
这是我试图将我找到的卡片传递到手中的地方。我能够找到卡,但在那之后被卡住了。
public boolean passCard(CardContainer cc, Card c)
{
for(int i = 0; i < cards.length; i++)
{
if(cards[i].equals(c))
{
//this is where im trying to make magic happen
return true;
}
}
return false;
}
}
public class Hand extends CardContainer {
private String playerName;
public Hand(String name, int numCards)
{
playerName = name;
cards = new Card[numCards];
// manually entered a card to test if it works
cards[1] = new Card(1,'s');
}
}
public class TestDemo {
public static void main(String[] args) {
Hand h = new Hand("name", 10);
System.out.println(deck.passCard(h, new Card(2,'s')));
// prints manually entered card in hand class
h.printCards();
}
相关分类