用Java语言,制作斗地主的制牌,洗牌 发牌
时间: 2024-04-17 10:29:19 浏览: 104
FAPAI.rar_发牌_斗地主
好的,我可以帮你编写一个用Java语言制作斗地主的制牌、洗牌和发牌的程序。以下是代码示例:
```java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DouDiZhu {
public static void main(String[] args) {
List<String> poker = createPoker();
System.out.println("初始牌:" + poker);
shufflePoker(poker);
System.out.println("洗牌后:" + poker);
List<String> player1 = new ArrayList<>();
List<String> player2 = new ArrayList<>();
List<String> player3 = new ArrayList<>();
List<String> bottomCards = new ArrayList<>();
dealPoker(poker, player1, player2, player3, bottomCards);
System.out.println("玩家1的牌:" + player1);
System.out.println("玩家2的牌:" + player2);
System.out.println("玩家3的牌:" + player3);
System.out.println("底牌:" + bottomCards);
}
// 创建一副扑克牌
public static List<String> createPoker() {
List<String> poker = new ArrayList<>();
String[] colors = {"♠", "♥", "♣", "♦"};
String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
for (String color : colors) {
for (String number : numbers) {
poker.add(color + number);
}
}
poker.add("小王");
poker.add("大王");
return poker;
}
// 洗牌
public static void shufflePoker(List<String> poker) {
Collections.shuffle(poker);
}
// 发牌
public static void dealPoker(List<String> poker, List<String> player1, List<String> player2,
List<String> player3, List<String> bottomCards) {
for (int i = 0; i < poker.size(); i++) {
if (i >= 51) {
bottomCards.add(poker.get(i));
} else if (i % 3 == 0) {
player1.add(poker.get(i));
} else if (i % 3 == 1) {
player2.add(poker.get(i));
} else if (i % 3 == 2) {
player3.add(poker.get(i));
}
}
}
}
```
这段代码创建了一副扑克牌,然后使用 `Collections.shuffle()` 方法对牌进行洗牌,最后将洗好的牌发给三个玩家和底牌。你可以根据需要进行调整和扩展。希望能对你有所帮助!
阅读全文