我正在尝试找到一种将牌“发”到 4 只不同手牌的好方法。
System.out.println("Deal to 4 Hands: ");
Hand hand1 = new Hand();
Hand hand2 = new Hand();
Hand hand3 = new Hand();
Hand hand4 = new Hand();
hand1.addSingleCard(Deck.deal());
hand2.addSingleCard(Deck.deal());
hand3.addSingleCard(Deck.deal());
hand4.addSingleCard(Deck.deal());
hand1.addSingleCard(Deck.deal());
hand2.addSingleCard(Deck.deal());
hand3.addSingleCard(Deck.deal());
hand4.addSingleCard(Deck.deal());
System.out.println("Cards left in deck: " + Deck.size());
System.out.println("Player 1's Hand: \n" + hand1.getHand());
System.out.println("Player 2's Hand: \n" + hand2.getHand());
System.out.println("Player 3's Hand: \n" + hand3.getHand());
System.out.println("Player 4's Hand: \n" + hand4.getHand());
有没有更简单的方法来对付双手?例如使用 For-Each 循环?
我试过这个:但它不起作用。我还没有真正使用过这种类型的循环非常必须......
for(Hand card : hand1){
System.out.println("Player 1's Hand: \n" + hand1);
}
顺便说一句,这会将 2 张牌发给 4 个不同的手,然后打印每手。