java斗地主单机版
时间: 2023-12-31 08:24:18 浏览: 36
以下是一个简单的Java斗地主单机版的示例:
```java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LandlordGame {
public static void main(String[] args) {
// 创建一副扑克牌
List<String> poker = createPoker();
// 洗牌
Collections.shuffle(poker);
// 发牌
List<String> player1 = new ArrayList<>();
List<String> player2 = new ArrayList<>();
List<String> player3 = new ArrayList<>();
List<String> bottom = new ArrayList<>();
for (int i = 0; i < poker.size(); i++) {
String card = poker.get(i);
if (i >= 51) {
bottom.add(card);
} else if (i % 3 == 0) {
player1.add(card);
} else if (i % 3 == 1) {
player2.add(card);
} else {
player3.add(card);
}
}
// 查看玩家手牌和底牌
System.out.println("玩家1的手牌:" + player1);
System.out.println("玩家2的手牌:" + player2);
System.out.println("玩家3的手牌:" + player3);
System.out.println("底牌:" + bottom);
}
// 创建一副扑克牌
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;
}
}
```