java四人斗地主洗牌发牌
时间: 2023-12-31 22:24:36 浏览: 51
以下是Java实现四人斗地主洗牌发牌的代码示例:
```java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LandlordGame {
public static void main(String[] args) {
// 初始化54张牌
List<String> poker = new ArrayList<>();
String[] colors = {"♠", "♥", "♣", "♦"};
String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
poker.add("大王");
poker.add("小王");
for (String number : numbers) {
for (String color : colors) {
poker.add(color + number);
}
}
// 洗牌
Collections.shuffle(poker);
// 发牌
List<String> player1 = new ArrayList<>();
List<String> player2 = new ArrayList<>();
List<String> player3 = new ArrayList<>();
List<String> bottomCards = new ArrayList<>();
for (int i = 0; i < poker.size(); i++) {
String card = poker.get(i);
if (i >= 51) {
bottomCards.add(card);
} else if (i % 3 == 0) {
player1.add(card);
} else if (i % 3 == 1) {
player2.add(card);
} else if (i % 3 == 2) {
player3.add(card);
}
}
// 输出结果
System.out.println("玩家1的牌:" + player1);
System.out.println("玩家2的牌:" + player2);
System.out.println("玩家3的牌:" + player3);
System.out.println("底牌:" + bottomCards);
}
}
```