java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) {
int numPlayers = 3; // 固定为3名玩家
int cardsPerPlayer = 17; // 每位玩家获得17张牌
int bottomCards = 3; // 底牌数量
Deck deck = new Deck();
List<List<Card>> playersHands = new ArrayList<>();
// 发给每位玩家17张牌
for (int i = 0; i < numPlayers; i++) {
List<Card> hand = deck.deal(cardsPerPlayer);
playersHands.add(hand);
System.out.println("玩家" + (i + 1) + "的手牌: " + hand);
}
// 底牌
List<Card> bottomCardsList = deck.deal(bottomCards);
System.out.println("底牌: " + bottomCardsList);
}
}
class Card {
private String suit; // 花色
private String rank; // 点数
public Card(String suit, String rank) {
this.suit = suit;
this.rank = rank;
}
@Override
public String toString() {
return suit + rank;
}
}
class Deck {
private List<Card> cards;
public Deck() {
this.cards = new ArrayList<>();
String[] suits = {"♥", "♠", "♦", "♣"};
String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
// 添加普通牌
for (String suit : suits) {
for (String rank : ranks) {
cards.add(new Card(suit, rank));
}
}
// 添加大小王
cards.add(new Card("大", "王")); // 大王
cards.add(new Card("小", "王")); // 小王
Collections.shuffle(cards); // 洗牌
}
public List<Card> deal(int numCards) {
List<Card> hand = new ArrayList<>();
for (int i = 0; i < numCards && !cards.isEmpty(); i++) {
hand.add(cards.remove(0)); // 从顶部发牌
}
return hand;
}
}
效果展示: